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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER
29 #include <SOCC_ViewModel.h>
31 #include "GEOM_Displayer.h"
32 #include "GEOMImpl_Types.hxx"
34 #include "GEOM_TypeFilter.h"
35 #include "GEOM_EdgeFilter.h"
36 #include "GEOM_FaceFilter.h"
37 #include "GEOM_PreviewFilter.h"
38 #include "GEOM_LogicalFilter.h"
39 #include "GEOM_OCCFilter.h"
41 #include "GEOM_AssemblyBuilder.h"
42 #include "GEOM_Actor.h"
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 <SalomeApp_SelectionMgr.h>
55 #include <SalomeApp_TypeFilter.h>
57 #include <SALOME_ListIteratorOfListIO.hxx>
58 #include <SALOMEDSClient.hxx>
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDSClient_SObject.hxx>
65 #include <SVTK_ViewModel.h>
67 #include <TColStd_MapOfInteger.hxx>
68 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
70 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
72 #include <GeometryGUI.h>
73 #include <GEOM_AISShape.hxx>
74 #include <AIS_ListIteratorOfListOfInteractive.hxx>
75 #include <AIS_Drawer.hxx>
76 #include <Prs3d_PointAspect.hxx>
77 #include <Graphic3d_AspectMarker3d.hxx>
78 #include <Geom_Plane.hxx>
79 #include <TopoDS_Face.hxx>
80 #include <BRep_Tool.hxx>
82 #include <Geom_Axis2Placement.hxx>
83 #include <StdSelect_TypeOfEdge.hxx>
84 #include <StdSelect_TypeOfFace.hxx>
85 #include <vtkActorCollection.h>
91 //================================================================
92 // Function : getActiveStudy
93 // Purpose : Get active study, returns 0 if no open study frame
94 //================================================================
95 static inline SalomeApp_Study* getActiveStudy()
97 SUIT_Session* session = SUIT_Session::session();
98 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
100 return ( SalomeApp_Study* )app->activeStudy();
104 //================================================================
105 // Function : getTopAbsMode
106 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
107 // one from GEOMImpl_Types.h
108 //================================================================
109 static inline int getTopAbsMode( const int implType )
113 case GEOM_COMPOUND : return TopAbs_COMPOUND;
114 case GEOM_SOLID : return TopAbs_SOLID;
115 case GEOM_SHELL : return TopAbs_SHELL;
116 case GEOM_FACE : return TopAbs_FACE;
117 case GEOM_WIRE : return TopAbs_WIRE;
118 case GEOM_EDGE : return TopAbs_EDGE;
119 case GEOM_POINT : return TopAbs_VERTEX;
124 //================================================================
125 // Function : getFilter
126 // Purpose : Get filter corresponding to the type of object
127 // from GEOMImpl_Types.h
128 //================================================================
129 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
131 SUIT_SelectionFilter* aFilter;
133 int aTopAbsMode = getTopAbsMode( theMode );
134 if ( aTopAbsMode != -1 )
135 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
139 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
140 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
142 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
143 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
144 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
145 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
146 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
147 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
149 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
151 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
152 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
154 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
160 //================================================================
161 // Function : getEntry
163 //================================================================
164 static char* getEntry( GEOM::GEOM_Object_ptr object )
166 SUIT_Session* session = SUIT_Session::session();
167 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
170 string IOR = app->orb()->object_to_string( object );
173 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
174 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
176 return (char*)(SO->GetID().c_str());
182 //================================================================
183 // Function : getName
185 //================================================================
186 static const char* getName( GEOM::GEOM_Object_ptr object )
188 SUIT_Session* session = SUIT_Session::session();
189 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
192 string IOR = app->orb()->object_to_string( object );
195 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
196 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) );
198 _PTR(GenericAttribute) anAttr;
200 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
202 _PTR(AttributeName) aNameAttr( anAttr );
203 return aNameAttr->Value().c_str();
211 //=================================================================
213 * GEOM_Displayer::GEOM_Displayer
216 //=================================================================
217 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study )
222 SUIT_Session* session = SUIT_Session::session();
223 SUIT_ResourceMgr* resMgr = session->resourceMgr();
224 QColor col = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "goldenrod" ) );
226 // TO DO: make some utility method to convert QColor into Quantity_Color
227 // myShadingColor = SUIT_Tools::color( col );
228 myShadingColor = Quantity_NOC_RED;
231 // This color is used for shape displaying. If it is equal -1 then
232 // default color is used.
238 // This parameter is used for activisation/deactivisation of objects to be displayed
243 //=================================================================
245 * GEOM_Displayer::~GEOM_Displayer
248 //=================================================================
249 GEOM_Displayer::~GEOM_Displayer()
253 //=================================================================
256 * Get active study frame, returns 0 if no open study frame
258 //=================================================================
259 SALOME_View* GEOM_Displayer::GetActiveView()
261 SUIT_Session* session = SUIT_Session::session();
262 SUIT_Application* app = session->activeApplication();
265 SUIT_Desktop* desk = app->desktop();
268 SUIT_ViewWindow* win = desk->activeWindow();
271 SUIT_ViewManager* vman = win->getViewManager();
274 SUIT_ViewModel* vmodel = vman->getViewModel();
277 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
287 //=================================================================
289 * GEOM_Displayer::Display
290 * Display interactive object in the current viewer
292 //=================================================================
293 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
294 const bool updateViewer,
295 SALOME_View* theViewFrame )
297 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
300 SALOME_Prs* prs = buildPresentation( theIO, vf );
304 vf->BeforeDisplay( this );
306 vf->AfterDisplay( this );
311 delete prs; // delete presentation because displayer is its owner
316 //=================================================================
318 * GEOM_Displayer::Display
319 * This overloaded Display() method can be useful for operations
320 * not using dialog boxes.
322 //=================================================================
323 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
325 if ( theObj->_is_nil() )
328 string entry = getEntry( theObj );
330 Display( new SALOME_InteractiveObject(
331 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer );
335 //=================================================================
337 * GEOM_Displayer::Erase
338 * Erase interactive object in the current viewer
340 //=================================================================
341 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
343 const bool updateViewer,
344 SALOME_View* theViewFrame )
346 if ( theIO.IsNull() )
349 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
352 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
354 vf->Erase( prs, forced );
357 delete prs; // delete presentation because displayer is its owner
362 //=================================================================
364 * GEOM_Displayer::Erase
365 * Erase geometry object in the current viewer
367 //=================================================================
368 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
370 const bool updateViewer )
372 string entry = getEntry( theObj );
375 Erase( new SALOME_InteractiveObject(
376 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer );
380 //=================================================================
382 * GEOM_Displayer::EraseAll
383 * Erase all objects in the current viewer
385 //=================================================================
386 void GEOM_Displayer::EraseAll ( const bool forced,
387 const bool updateViewer,
388 SALOME_View* theViewFrame )
390 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
393 vf->EraseAll( forced );
399 //=================================================================
401 * GEOM_Displayer::Redisplay
402 * Redisplay (erase and then display again) interactive object
403 * in the current viewer
405 //=================================================================
406 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
407 const bool updateViewer )
409 // Remove the object permanently (<forced> == true)
410 SUIT_Session* ses = SUIT_Session::session();
411 SUIT_Application* app = ses->activeApplication();
414 SUIT_Desktop* desk = app->desktop();
415 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
416 SUIT_ViewWindow* wnd;
417 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
419 SUIT_ViewManager* vman = wnd->getViewManager();
422 SUIT_ViewModel* vmodel = vman->getViewModel();
425 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
428 if ( view->isVisible( theIO ) || view == GetActiveView() )
430 Erase( theIO, true, false, view );
431 Display( theIO, updateViewer, view );
440 //=================================================================
442 * GEOM_Displayer::Display
443 * Calls Display() method for each object in the given list
445 //=================================================================
446 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
448 SALOME_ListIteratorOfListIO Iter( theIOList );
449 for ( ; Iter.More(); Iter.Next() ) {
450 Display( Iter.Value(), false );
456 //=================================================================
458 * GEOM_Displayer::Erase
459 * Calls Erase() method for each object in the given list
461 //=================================================================
462 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
464 const bool updateViewer )
466 SALOME_ListIteratorOfListIO Iter( theIOList );
467 for ( ; Iter.More(); Iter.Next() )
468 Erase( Iter.Value(), forced, false );
474 //=================================================================
476 * GEOM_Displayer::Redisplay
477 * Calls Redisplay() method for each object in the given list
479 //=================================================================
480 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
482 SALOME_ListIteratorOfListIO Iter( theIOList );
483 for ( ; Iter.More(); Iter.Next() )
484 Redisplay( Iter.Value(), false );
490 //=================================================================
492 * GEOM_Displayer::UpdateViewer
493 * Update current viewer
495 //=================================================================
496 void GEOM_Displayer::UpdateViewer()
498 SALOME_View* vf = GetActiveView();
503 //=================================================================
505 * GEOM_Displayer::Update
506 * Update OCC presentaion
507 * [ Reimplemented from SALOME_Displayer ]
509 //=================================================================
510 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
512 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
516 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
518 TopoDS_Face aFace = TopoDS::Face( myShape );
519 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
520 if ( !aPlane.IsNull() )
522 gp_Ax3 aPos = aPlane->Pln().Position();
523 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
525 Handle(GEOM_AISTrihedron) aTrh;
527 if ( occPrs->IsNull() )
529 aTrh = new GEOM_AISTrihedron( aPlc );
532 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
535 aTrh->SetWidth( GetWidth() );
537 if ( !myIO.IsNull() )
540 aTrh->SetOwner( myIO );
543 occPrs->AddObject( aTrh );
547 AIS_ListOfInteractive aList;
548 occPrs->GetObjects( aList );
549 AIS_ListIteratorOfListOfInteractive anIter( aList );
550 for ( ; anIter.More(); anIter.Next() )
552 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
553 if ( !aTrh.IsNull() )
555 aTrh->SetComponent( aPlc );
561 occPrs->SetToActivate( ToActivate() );
566 // if presentation is empty we try to create new one
567 if ( occPrs->IsNull() )
569 if ( !myShape.IsNull() )
571 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
572 // Temporary staff: vertex must be infinite for correct visualization
573 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
575 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
576 AISShape->SetShadingColor( myShadingColor );
579 if ( myShape.ShapeType() == TopAbs_VERTEX )
581 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
582 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
583 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
584 AISShape->Attributes()->SetPointAspect( anAspect );
587 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
591 AISShape->SetWidth( GetWidth() );
593 if ( !myIO.IsNull() )
595 AISShape->setIO( myIO );
596 AISShape->SetOwner( myIO );
598 else if ( !myName.empty() )
600 // Workaround to allow selection of temporary objects
601 static int tempId = 0;
603 sprintf( buf, "TEMP_%d", tempId++ );
604 Handle( SALOME_InteractiveObject ) anObj =
605 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
606 AISShape->setIO( anObj );
607 AISShape->SetOwner( anObj );
609 // AISShape->SetName(???); ??? necessary to set name ???
610 occPrs->AddObject( AISShape );
612 // In accordance with ToActivate() value object will be activated/deactivated
613 // when it will be displayed
614 occPrs->SetToActivate( ToActivate() );
617 // if presentation is found -> set again shape for it
620 if ( !myShape.IsNull() )
622 AIS_ListOfInteractive IOList;
623 occPrs->GetObjects( IOList );
624 AIS_ListIteratorOfListOfInteractive Iter( IOList );
625 for ( ; Iter.More(); Iter.Next() )
627 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
628 if ( AISShape.IsNull() )
630 if ( AISShape->Shape() != myShape )
632 AISShape->Set( myShape );
633 AISShape->UpdateSelection();
634 AISShape->SetToUpdate();
636 if ( !myIO.IsNull() )
638 AISShape->setIO( myIO );
639 AISShape->SetOwner( myIO );
647 //=================================================================
649 * GEOM_Displayer::Update
650 * Update VTK presentaion
651 * [ Reimplemented from SALOME_Displayer ]
653 //=================================================================
654 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
656 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
657 if ( !vtkPrs || myShape.IsNull() )
660 vtkActorCollection* theActors = 0;
662 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
664 myToActivate = false;
665 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
669 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
670 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
673 Handle(Geom_Plane) aPlane =
674 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
675 if ( aPlane.IsNull() )
678 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
679 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
681 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
682 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
684 vtkPrs->AddObject( aTrh );
686 theActors = vtkActorCollection::New();
687 theActors->AddItem( aTrh );
690 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
692 theActors->InitTraversal();
694 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
696 vtkProperty* aProp = 0;
698 if ( HasColor() || HasWidth() )
700 aProp = vtkProperty::New();
701 aProp->SetRepresentationToWireframe();
706 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
707 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
712 aProp->SetLineWidth( GetWidth() );
715 while ( anActor != NULL )
717 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
719 GActor->setIO( myIO );
723 GActor->SetProperty( aProp );
724 GActor->SetPreviewProperty( aProp );
726 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
727 if ( aGeomGActor != 0 )
729 aGeomGActor->SetShadingProperty( aProp );
730 aGeomGActor->SetWireframeProperty( aProp );
735 GActor->PickableOn();
737 GActor->PickableOff();
739 vtkPrs->AddObject( GActor );
741 anActor = (vtkActor*)theActors->GetNextActor();
750 //=================================================================
752 * GEOM_Displayer::BuildPrs
753 * Build presentation accordint to the current viewer type
755 //=================================================================
756 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
758 if ( theObj->_is_nil() )
761 myViewFrame = GetActiveView();
762 if ( myViewFrame == 0 )
765 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
770 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
771 myType = theObj->GetType();
773 // Update presentation
779 //=================================================================
781 * GEOM_Displayer::BuildPrs
782 * Build presentation accordint to the current viewer type
784 //=================================================================
785 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
787 myViewFrame = GetActiveView();
788 if ( theShape.IsNull() || myViewFrame == 0 )
791 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
796 setShape( theShape );
804 //=================================================================
806 * GEOM_Displayer::buildPresentation
807 * Builds/finds object's presentation for the current viewer
808 * Calls corresponding Update() method by means of double dispatch
811 //=================================================================
812 SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveObject)& theIO,
813 SALOME_View* theViewFrame )
818 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
822 prs = myViewFrame->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 );
825 if ( !theIO.IsNull() )
827 // set interactive object
829 // Find SOBject (because shape should be published previously)
830 SUIT_Session* session = SUIT_Session::session();
831 SUIT_Application* app = session->activeApplication();
834 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
837 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
840 // get CORBA reference to data object
841 CORBA::Object_var object = dynamic_cast<SALOMEDS_SObject*>(SO.get())->GetObject();
842 if ( !CORBA::is_nil( object ) )
844 // downcast to GEOM object
845 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
846 if ( !GeomObject->_is_nil() )
849 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
850 myType = GeomObject->GetType();
857 UpdatePrs( prs ); // Update presentation by using of the double dispatch
863 //=================================================================
865 * GEOM_Displayer::internalReset
866 * Resets internal data
869 //=================================================================
870 void GEOM_Displayer::internalReset()
876 //=================================================================
878 * GEOM_Displayer::LocalSelection
879 * Activate selection of CAD shapes with activisation of selection
880 * of their sub-shapes (with opened local context for OCC viewer)
882 //=================================================================
883 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
885 SUIT_Session* session = SUIT_Session::session();
886 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
890 SalomeApp_SelectionMgr* sm = app->selectionMgr();
892 // remove all filters from selection
895 SALOME_View* vf = GetActiveView();
898 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
899 vf->LocalSelection( prs, theMode );
900 delete prs; // delete presentation because displayer is its owner
904 //=================================================================
906 * GEOM_Displayer::globalSelection
907 * Activate selection of CAD shapes without activisation of selection
908 * of their sub-shapes (without opened local context for OCC viewer)
910 //=================================================================
911 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
913 TColStd_MapOfInteger aModes;
914 aModes.Add( theMode );
915 GlobalSelection( aModes, update );
918 //=================================================================
920 * GEOM_Displayer::globalSelection
921 * Activate selection of CAD shapes without activisation of selection
922 * of their sub-shapes (without opened local context for OCC viewer)
924 //=================================================================
925 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
928 SUIT_Session* session = SUIT_Session::session();
929 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
933 SALOME_View* vf = GetActiveView();
937 // Close local context
938 vf->GlobalSelection( update );
940 // Set selection filters in accordance with current mode
941 SalomeApp_SelectionMgr* sm = app->selectionMgr();
945 // Remove from selection temporary objects if necessary
946 if ( !theModes.Contains( GEOM_PREVIEW ) )
947 clearTemporary( sm );
949 //@ aSel->ClearIndex();
953 // Remove filters from AIS_InteractiveContext
954 Handle(AIS_InteractiveContext) ic;
955 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
958 ic = viewer->getAISContext();
963 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
966 SUIT_SelectionFilter* aFilter;
967 if ( theModes.Extent() == 1 )
969 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
970 aFilter = getFilter( aMode );
972 else if ( theModes.Extent() > 1 )
974 TColStd_MapOfInteger aTopAbsModes;
975 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
976 QPtrList<SUIT_SelectionFilter> aListOfFilters;
977 for ( ; anIter.More(); anIter.Next() )
979 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
981 aListOfFilters.append( aFilter );
984 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
991 sm->installFilter( aFilter );
994 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
995 ic->AddFilter( anOCCFilter );
1000 //=================================================================
1002 * GEOM_Displayer::LocalSelection
1003 * Activate selection of CAD shapes with activisation of selection
1004 * of their sub-shapes (with opened local context for OCC viewer)
1006 //=================================================================
1007 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1009 SALOME_ListIteratorOfListIO Iter( theIOList );
1010 for ( ; Iter.More(); Iter.Next() )
1011 LocalSelection( Iter.Value(), theMode );
1014 //=================================================================
1016 * GEOM_Displayer::BeforeDisplay
1017 * Called before displaying of pars. Close local context
1018 * [ Reimplemented from SALOME_Displayer ]
1020 //=================================================================
1021 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1023 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1026 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1029 if ( ic->HasOpenedContext() )
1030 ic->CloseAllContexts();
1035 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1040 //=================================================================
1042 * GEOM_Displayer::SetColor
1043 * Set color for shape displaying. If it is equal -1 then default color is used.
1044 * Available values are from Quantity_NameOfColor enumeration
1046 //=================================================================
1047 void GEOM_Displayer::SetColor( const int color )
1052 int GEOM_Displayer::GetColor() const
1057 bool GEOM_Displayer::HasColor() const
1059 return myColor != -1;
1062 void GEOM_Displayer::UnsetColor()
1067 //=================================================================
1069 * GEOM_Displayer::SetWidth
1070 * Set width of shape displaying. If it is equal -1 then default width is used.
1072 //=================================================================
1073 void GEOM_Displayer::SetWidth( const double width )
1078 double GEOM_Displayer::GetWidth() const
1083 bool GEOM_Displayer::HasWidth() const
1085 return myWidth != -1;
1088 void GEOM_Displayer::UnsetWidth()
1093 //=================================================================
1095 * GEOM_Displayer::SetToActivate
1096 * This method is used for activisation/deactivisation of objects to be displayed
1098 //=================================================================
1099 void GEOM_Displayer::SetToActivate( const bool toActivate )
1101 myToActivate = toActivate;
1103 bool GEOM_Displayer::ToActivate() const
1105 return myToActivate;
1108 //=================================================================
1110 * GEOM_Displayer::clearTemporary
1111 * Removes from selection temporary objects
1113 //=================================================================
1114 void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr )
1116 SALOME_ListIO selected, toSelect;
1117 theSelMgr->selectedObjects( selected );
1119 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1120 Handle(SALOME_InteractiveObject) io = it.Value();
1121 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1122 toSelect.Append( it.Value() );
1125 theSelMgr->setSelectedObjects( toSelect, true );