1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER
29 #include "GEOM_Displayer.h"
31 #include "GeometryGUI.h"
33 #include "GEOM_TypeFilter.h"
34 #include "GEOM_EdgeFilter.h"
35 #include "GEOM_FaceFilter.h"
36 #include "GEOM_PreviewFilter.h"
37 #include "GEOM_LogicalFilter.h"
38 #include "GEOM_OCCFilter.h"
40 #include "GEOM_Actor.h"
41 #include "GEOM_AssemblyBuilder.h"
42 #include "GEOM_AISShape.hxx"
43 #include "GEOM_AISTrihedron.hxx"
44 #include "GEOM_VTKTrihedron.hxx"
46 #include <SUIT_Desktop.h>
47 #include <SUIT_ViewWindow.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_Tools.h>
50 #include <SUIT_ViewManager.h>
52 #include <SalomeApp_Study.h>
53 #include <SalomeApp_Application.h>
54 #include <LightApp_SelectionMgr.h>
55 #include <SalomeApp_TypeFilter.h>
56 #include <SalomeApp_Tools.h>
58 #include <SALOME_ListIteratorOfListIO.hxx>
61 #include <SOCC_ViewModel.h>
64 #include <SVTK_ViewModel.h>
66 #include <SALOMEDSClient.hxx>
67 #include <SALOMEDSClient_SObject.hxx>
70 #include <AIS_Drawer.hxx>
71 #include <AIS_ListIteratorOfListOfInteractive.hxx>
72 #include <Prs3d_IsoAspect.hxx>
73 #include <Prs3d_PointAspect.hxx>
74 #include <Graphic3d_AspectMarker3d.hxx>
75 #include <StdSelect_TypeOfEdge.hxx>
76 #include <StdSelect_TypeOfFace.hxx>
77 #include <TopoDS_Face.hxx>
78 #include <BRep_Tool.hxx>
79 #include <Geom_Plane.hxx>
80 #include <Geom_Axis2Placement.hxx>
82 #include <TColStd_MapOfInteger.hxx>
83 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
86 #include <vtkActorCollection.h>
87 #include <vtkProperty.h>
93 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
95 #include "GEOMImpl_Types.hxx"
99 //================================================================
100 // Function : getActiveStudy
101 // Purpose : Get active study, returns 0 if no open study frame
102 //================================================================
103 static inline SalomeApp_Study* getActiveStudy()
105 SUIT_Session* session = SUIT_Session::session();
106 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
108 return ( SalomeApp_Study* )app->activeStudy();
112 //================================================================
113 // Function : getTopAbsMode
114 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
115 // one from GEOMImpl_Types.h
116 //================================================================
117 static inline int getTopAbsMode( const int implType )
121 case GEOM_COMPOUND : return TopAbs_COMPOUND;
122 case GEOM_SOLID : return TopAbs_SOLID;
123 case GEOM_SHELL : return TopAbs_SHELL;
124 case GEOM_FACE : return TopAbs_FACE;
125 case GEOM_WIRE : return TopAbs_WIRE;
126 case GEOM_EDGE : return TopAbs_EDGE;
127 case GEOM_POINT : return TopAbs_VERTEX;
132 //================================================================
133 // Function : getFilter
134 // Purpose : Get filter corresponding to the type of object
135 // from GEOMImpl_Types.h
136 //================================================================
137 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
139 SUIT_SelectionFilter* aFilter;
141 int aTopAbsMode = getTopAbsMode( theMode );
142 if ( aTopAbsMode != -1 )
143 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
147 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
148 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
150 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
151 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
152 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
153 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
154 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
155 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
157 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
159 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
160 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
162 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
168 //================================================================
169 // Function : getEntry
171 //================================================================
172 static string getEntry( GEOM::GEOM_Object_ptr object )
174 SUIT_Session* session = SUIT_Session::session();
175 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
178 CORBA::String_var IOR = app->orb()->object_to_string( object );
179 if ( strcmp(IOR.in(), "") != 0 )
181 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
182 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
190 //================================================================
191 // Function : getName
193 //================================================================
194 static string getName( GEOM::GEOM_Object_ptr object )
196 SUIT_Session* session = SUIT_Session::session();
197 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
200 CORBA::String_var IOR = app->orb()->object_to_string( object );
201 if ( strcmp(IOR.in(), "") != 0 )
203 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
204 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
206 _PTR(GenericAttribute) anAttr;
208 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
210 _PTR(AttributeName) aNameAttr( anAttr );
211 return aNameAttr->Value();
219 //=================================================================
221 * GEOM_Displayer::GEOM_Displayer
224 //=================================================================
225 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
228 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
233 SUIT_Session* session = SUIT_Session::session();
234 SUIT_ResourceMgr* resMgr = session->resourceMgr();
236 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
237 myShadingColor = SalomeApp_Tools::color( col );
239 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
242 // This color is used for shape displaying. If it is equal -1 then
243 // default color is used.
249 // This parameter is used for activisation/deactivisation of objects to be displayed
254 //=================================================================
256 * GEOM_Displayer::~GEOM_Displayer
259 //=================================================================
260 GEOM_Displayer::~GEOM_Displayer()
264 //=================================================================
266 * GEOM_Displayer::Display
267 * Display interactive object in the current viewer
269 //=================================================================
270 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
271 const bool updateViewer,
272 SALOME_View* theViewFrame )
274 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
277 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
281 vf->BeforeDisplay( this );
283 vf->AfterDisplay( this );
288 delete prs; // delete presentation because displayer is its owner
293 //=================================================================
295 * GEOM_Displayer::Display
296 * This overloaded Display() method can be useful for operations
297 * not using dialog boxes.
299 //=================================================================
300 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
302 if ( theObj->_is_nil() )
305 string entry = getEntry( theObj );
307 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
312 //=================================================================
314 * GEOM_Displayer::Erase
315 * Erase interactive object in the current viewer
317 //=================================================================
318 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
320 const bool updateViewer,
321 SALOME_View* theViewFrame )
323 if ( theIO.IsNull() )
326 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
329 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
331 vf->Erase( prs, forced );
334 delete prs; // delete presentation because displayer is its owner
339 //=================================================================
341 * GEOM_Displayer::Erase
342 * Erase geometry object in the current viewer
344 //=================================================================
345 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
347 const bool updateViewer )
349 string entry = getEntry( theObj );
352 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
353 forced, updateViewer);
357 //=================================================================
359 * GEOM_Displayer::Redisplay
360 * Redisplay (erase and then display again) interactive object
361 * in the current viewer
363 //=================================================================
364 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
365 const bool updateViewer )
367 // Remove the object permanently (<forced> == true)
368 SUIT_Session* ses = SUIT_Session::session();
369 SUIT_Application* app = ses->activeApplication();
372 SUIT_Desktop* desk = app->desktop();
373 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
374 SUIT_ViewWindow* wnd;
375 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
377 SUIT_ViewManager* vman = wnd->getViewManager();
380 SUIT_ViewModel* vmodel = vman->getViewModel();
383 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
386 if ( view->isVisible( theIO ) || view == GetActiveView() )
388 Erase( theIO, true, false, view );
389 Display( theIO, updateViewer, view );
398 //=================================================================
400 * GEOM_Displayer::Display
401 * Calls Display() method for each object in the given list
403 //=================================================================
404 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
406 SALOME_ListIteratorOfListIO Iter( theIOList );
407 for ( ; Iter.More(); Iter.Next() ) {
408 Display( Iter.Value(), false );
414 //=================================================================
416 * GEOM_Displayer::Erase
417 * Calls Erase() method for each object in the given list
419 //=================================================================
420 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
422 const bool updateViewer )
424 SALOME_ListIteratorOfListIO Iter( theIOList );
425 for ( ; Iter.More(); Iter.Next() )
426 Erase( Iter.Value(), forced, false );
432 //=================================================================
434 * GEOM_Displayer::Redisplay
435 * Calls Redisplay() method for each object in the given list
437 //=================================================================
438 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
440 SALOME_ListIteratorOfListIO Iter( theIOList );
441 for ( ; Iter.More(); Iter.Next() )
442 Redisplay( Iter.Value(), false );
448 //=================================================================
450 * GEOM_Displayer::Update
451 * Update OCC presentaion
452 * [ Reimplemented from SALOME_Displayer ]
454 //=================================================================
455 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
457 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
461 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
463 TopoDS_Face aFace = TopoDS::Face( myShape );
464 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
465 if ( !aPlane.IsNull() )
467 gp_Ax3 aPos = aPlane->Pln().Position();
468 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
470 Handle(GEOM_AISTrihedron) aTrh;
472 if ( occPrs->IsNull() )
474 aTrh = new GEOM_AISTrihedron( aPlc );
477 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
480 aTrh->SetWidth( GetWidth() );
482 if ( !myIO.IsNull() )
485 aTrh->SetOwner( myIO );
488 occPrs->AddObject( aTrh );
492 AIS_ListOfInteractive aList;
493 occPrs->GetObjects( aList );
494 AIS_ListIteratorOfListOfInteractive anIter( aList );
495 for ( ; anIter.More(); anIter.Next() )
497 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
498 if ( !aTrh.IsNull() )
500 aTrh->SetComponent( aPlc );
506 occPrs->SetToActivate( ToActivate() );
511 // if presentation is empty we try to create new one
512 if ( occPrs->IsNull() )
514 if ( !myShape.IsNull() )
516 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
517 // Temporary staff: vertex must be infinite for correct visualization
518 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
520 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
521 AISShape->SetDisplayMode( myDisplayMode );
522 AISShape->SetShadingColor( myShadingColor );
524 // Set color and number for iso lines
525 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
526 QColor col = aResMgr->colorValue( "Geometry", "isos_color", QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
527 Quantity_Color aColor = SalomeApp_Tools::color( col );
528 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
529 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
531 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
532 anAspect->SetNumber( anUIsoNumber );
533 anAspect->SetColor( aColor );
534 AISShape->Attributes()->SetUIsoAspect( anAspect );
536 anAspect = AISShape->Attributes()->VIsoAspect();
537 anAspect->SetNumber( aVIsoNumber );
538 anAspect->SetColor( aColor );
539 AISShape->Attributes()->SetVIsoAspect( anAspect );
543 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
544 if ( myShape.ShapeType() == TopAbs_VERTEX )
546 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
547 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
548 AISShape->Attributes()->SetPointAspect( anAspect );
553 if ( myShape.ShapeType() == TopAbs_VERTEX )
555 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
556 aColor = SalomeApp_Tools::color( col );
558 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
559 anAspect->SetColor( aColor );
560 AISShape->Attributes()->SetPointAspect( anAspect );
565 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
566 aColor = SalomeApp_Tools::color( col );
568 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
569 anAspect->SetColor( aColor );
570 AISShape->Attributes()->SetLineAspect( anAspect );
572 // Set unfree boundaries aspect
573 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
574 anAspect->SetColor( aColor );
575 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
577 // Set free boundaries aspect
578 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
579 aColor = SalomeApp_Tools::color( col );
581 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
582 anAspect->SetColor( aColor );
583 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
586 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
587 aColor = SalomeApp_Tools::color( col );
589 anAspect = AISShape->Attributes()->WireAspect();
590 anAspect->SetColor( aColor );
591 AISShape->Attributes()->SetWireAspect( anAspect );
596 AISShape->SetWidth( GetWidth() );
598 if ( !myIO.IsNull() )
600 AISShape->setIO( myIO );
601 AISShape->SetOwner( myIO );
603 else if ( !myName.empty() )
605 // Workaround to allow selection of temporary objects
606 static int tempId = 0;
608 sprintf( buf, "TEMP_%d", tempId++ );
609 Handle( SALOME_InteractiveObject ) anObj =
610 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
611 AISShape->setIO( anObj );
612 AISShape->SetOwner( anObj );
614 // AISShape->SetName(???); ??? necessary to set name ???
615 occPrs->AddObject( AISShape );
617 // In accordance with ToActivate() value object will be activated/deactivated
618 // when it will be displayed
619 occPrs->SetToActivate( ToActivate() );
622 // if presentation is found -> set again shape for it
625 if ( !myShape.IsNull() )
627 AIS_ListOfInteractive IOList;
628 occPrs->GetObjects( IOList );
629 AIS_ListIteratorOfListOfInteractive Iter( IOList );
630 for ( ; Iter.More(); Iter.Next() )
632 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
633 if ( AISShape.IsNull() )
635 if ( AISShape->Shape() != myShape )
637 AISShape->Set( myShape );
638 AISShape->UpdateSelection();
639 AISShape->SetToUpdate();
641 if ( !myIO.IsNull() )
643 AISShape->setIO( myIO );
644 AISShape->SetOwner( myIO );
652 //=================================================================
654 * GEOM_Displayer::Update
655 * Update VTK presentaion
656 * [ Reimplemented from SALOME_Displayer ]
658 //=================================================================
659 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
661 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
662 if ( !vtkPrs || myShape.IsNull() )
665 vtkActorCollection* theActors = 0;
667 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
669 myToActivate = false;
670 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
674 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
675 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
678 Handle(Geom_Plane) aPlane =
679 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
680 if ( aPlane.IsNull() )
683 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
684 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
686 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
687 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
689 vtkPrs->AddObject( aTrh );
691 theActors = vtkActorCollection::New();
692 theActors->AddItem( aTrh );
695 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
697 theActors->InitTraversal();
699 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
701 vtkProperty* aProp = 0;
703 if ( HasColor() || HasWidth() )
705 aProp = vtkProperty::New();
706 aProp->SetRepresentationToWireframe();
711 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
712 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
717 aProp->SetLineWidth( GetWidth() );
720 while ( anActor != NULL )
722 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
724 GActor->setIO( myIO );
728 GActor->SetProperty( aProp );
729 GActor->SetPreviewProperty( aProp );
731 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
732 if ( aGeomGActor != 0 )
734 aGeomGActor->SetShadingProperty( aProp );
735 aGeomGActor->SetWireframeProperty( aProp );
740 GActor->PickableOn();
742 GActor->PickableOff();
744 vtkPrs->AddObject( GActor );
746 anActor = (vtkActor*)theActors->GetNextActor();
755 //=================================================================
757 * GEOM_Displayer::BuildPrs
758 * Build presentation accordint to the current viewer type
760 //=================================================================
761 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
763 if ( theObj->_is_nil() )
766 myViewFrame = GetActiveView();
767 if ( myViewFrame == 0 )
770 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
775 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
776 myType = theObj->GetType();
778 // Update presentation
784 //=================================================================
786 * GEOM_Displayer::BuildPrs
787 * Build presentation accordint to the current viewer type
789 //=================================================================
790 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
792 myViewFrame = GetActiveView();
793 if ( theShape.IsNull() || myViewFrame == 0 )
796 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
801 setShape( theShape );
809 //=================================================================
811 * GEOM_Displayer::buildPresentation
812 * Builds/finds object's presentation for the current viewer
813 * Calls corresponding Update() method by means of double dispatch
816 //=================================================================
817 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
818 SALOME_View* theViewFrame )
823 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
827 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
830 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
831 theIO->setEntry( entry.latin1() );
832 if ( !theIO.IsNull() )
834 // set interactive object
836 // Find SOBject (because shape should be published previously)
837 SUIT_Session* session = SUIT_Session::session();
838 SUIT_Application* app = session->activeApplication();
841 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
844 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
847 // get CORBA reference to data object
848 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
849 if ( !CORBA::is_nil( object ) )
851 // downcast to GEOM object
852 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
853 if ( !GeomObject->_is_nil() )
856 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
857 myType = GeomObject->GetType();
864 UpdatePrs( prs ); // Update presentation by using of the double dispatch
870 //=================================================================
872 * GEOM_Displayer::internalReset
873 * Resets internal data
876 //=================================================================
877 void GEOM_Displayer::internalReset()
883 //=================================================================
885 * GEOM_Displayer::LocalSelection
886 * Activate selection of CAD shapes with activisation of selection
887 * of their sub-shapes (with opened local context for OCC viewer)
889 //=================================================================
890 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
892 SUIT_Session* session = SUIT_Session::session();
893 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
897 LightApp_SelectionMgr* sm = app->selectionMgr();
899 // remove all filters from selection
902 SALOME_View* vf = GetActiveView();
904 if (!theIO.IsNull() && !vf->isVisible(theIO))
906 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
907 vf->LocalSelection( prs, theMode );
908 delete prs; // delete presentation because displayer is its owner
912 //=================================================================
914 * GEOM_Displayer::globalSelection
915 * Activate selection of CAD shapes without activisation of selection
916 * of their sub-shapes (without opened local context for OCC viewer)
918 //=================================================================
919 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
921 TColStd_MapOfInteger aModes;
922 aModes.Add( theMode );
923 GlobalSelection( aModes, update );
926 //=================================================================
928 * GEOM_Displayer::globalSelection
929 * Activate selection of CAD shapes without activisation of selection
930 * of their sub-shapes (without opened local context for OCC viewer)
932 //=================================================================
933 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
936 SUIT_Session* session = SUIT_Session::session();
937 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
941 SALOME_View* vf = GetActiveView();
945 // Close local context
946 vf->GlobalSelection( update );
948 // Set selection filters in accordance with current mode
949 LightApp_SelectionMgr* sm = app->selectionMgr();
953 // Remove from selection temporary objects if necessary
954 if ( !theModes.Contains( GEOM_PREVIEW ) )
955 clearTemporary( sm );
957 //@ aSel->ClearIndex();
961 // Remove filters from AIS_InteractiveContext
962 Handle(AIS_InteractiveContext) ic;
963 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
966 ic = viewer->getAISContext();
971 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
974 SUIT_SelectionFilter* aFilter;
975 if ( theModes.Extent() == 1 )
977 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
978 aFilter = getFilter( aMode );
980 else if ( theModes.Extent() > 1 )
982 TColStd_MapOfInteger aTopAbsModes;
983 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
984 QPtrList<SUIT_SelectionFilter> aListOfFilters;
985 for ( ; anIter.More(); anIter.Next() )
987 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
989 aListOfFilters.append( aFilter );
992 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
999 sm->installFilter( aFilter );
1002 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1003 ic->AddFilter( anOCCFilter );
1008 //=================================================================
1010 * GEOM_Displayer::LocalSelection
1011 * Activate selection of CAD shapes with activisation of selection
1012 * of their sub-shapes (with opened local context for OCC viewer)
1014 //=================================================================
1015 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1017 SALOME_ListIteratorOfListIO Iter( theIOList );
1018 for ( ; Iter.More(); Iter.Next() )
1019 LocalSelection( Iter.Value(), theMode );
1022 //=================================================================
1024 * GEOM_Displayer::BeforeDisplay
1025 * Called before displaying of pars. Close local context
1026 * [ Reimplemented from SALOME_Displayer ]
1028 //=================================================================
1029 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1031 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1034 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1037 if ( ic->HasOpenedContext() )
1038 ic->CloseAllContexts();
1043 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1048 //=================================================================
1050 * GEOM_Displayer::SetColor
1051 * Set color for shape displaying. If it is equal -1 then default color is used.
1052 * Available values are from Quantity_NameOfColor enumeration
1054 //=================================================================
1055 void GEOM_Displayer::SetColor( const int color )
1060 int GEOM_Displayer::GetColor() const
1065 bool GEOM_Displayer::HasColor() const
1067 return myColor != -1;
1070 void GEOM_Displayer::UnsetColor()
1075 //=================================================================
1077 * GEOM_Displayer::SetWidth
1078 * Set width of shape displaying. If it is equal -1 then default width is used.
1080 //=================================================================
1081 void GEOM_Displayer::SetWidth( const double width )
1086 double GEOM_Displayer::GetWidth() const
1091 bool GEOM_Displayer::HasWidth() const
1093 return myWidth != -1;
1096 void GEOM_Displayer::UnsetWidth()
1101 //=================================================================
1103 * GEOM_Displayer::SetToActivate
1104 * This method is used for activisation/deactivisation of objects to be displayed
1106 //=================================================================
1107 void GEOM_Displayer::SetToActivate( const bool toActivate )
1109 myToActivate = toActivate;
1111 bool GEOM_Displayer::ToActivate() const
1113 return myToActivate;
1116 //=================================================================
1118 * GEOM_Displayer::clearTemporary
1119 * Removes from selection temporary objects
1121 //=================================================================
1122 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1124 SALOME_ListIO selected, toSelect;
1125 theSelMgr->selectedObjects( selected );
1127 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1128 Handle(SALOME_InteractiveObject) io = it.Value();
1129 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1130 toSelect.Append( it.Value() );
1133 theSelMgr->setSelectedObjects( toSelect, true );
1136 void GEOM_Displayer::SetName( const char* theName )
1141 void GEOM_Displayer::UnsetName()
1146 SalomeApp_Study* GEOM_Displayer::getStudy() const
1148 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1151 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1156 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1161 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1163 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();