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_PointAspect.hxx>
73 #include <Graphic3d_AspectMarker3d.hxx>
74 #include <StdSelect_TypeOfEdge.hxx>
75 #include <StdSelect_TypeOfFace.hxx>
76 #include <TopoDS_Face.hxx>
77 #include <BRep_Tool.hxx>
78 #include <Geom_Plane.hxx>
79 #include <Geom_Axis2Placement.hxx>
81 #include <TColStd_MapOfInteger.hxx>
82 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
85 #include <vtkActorCollection.h>
86 #include <vtkProperty.h>
92 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
94 #include "GEOMImpl_Types.hxx"
98 //================================================================
99 // Function : getActiveStudy
100 // Purpose : Get active study, returns 0 if no open study frame
101 //================================================================
102 static inline SalomeApp_Study* getActiveStudy()
104 SUIT_Session* session = SUIT_Session::session();
105 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
107 return ( SalomeApp_Study* )app->activeStudy();
111 //================================================================
112 // Function : getTopAbsMode
113 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
114 // one from GEOMImpl_Types.h
115 //================================================================
116 static inline int getTopAbsMode( const int implType )
120 case GEOM_COMPOUND : return TopAbs_COMPOUND;
121 case GEOM_SOLID : return TopAbs_SOLID;
122 case GEOM_SHELL : return TopAbs_SHELL;
123 case GEOM_FACE : return TopAbs_FACE;
124 case GEOM_WIRE : return TopAbs_WIRE;
125 case GEOM_EDGE : return TopAbs_EDGE;
126 case GEOM_POINT : return TopAbs_VERTEX;
131 //================================================================
132 // Function : getFilter
133 // Purpose : Get filter corresponding to the type of object
134 // from GEOMImpl_Types.h
135 //================================================================
136 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
138 SUIT_SelectionFilter* aFilter;
140 int aTopAbsMode = getTopAbsMode( theMode );
141 if ( aTopAbsMode != -1 )
142 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
146 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
147 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
149 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
150 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
151 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
152 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
153 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
154 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
156 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
158 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
159 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
161 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
167 //================================================================
168 // Function : getEntry
170 //================================================================
171 static string getEntry( GEOM::GEOM_Object_ptr object )
173 SUIT_Session* session = SUIT_Session::session();
174 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
177 string IOR = app->orb()->object_to_string( object );
180 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
181 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
189 //================================================================
190 // Function : getName
192 //================================================================
193 static string getName( GEOM::GEOM_Object_ptr object )
195 SUIT_Session* session = SUIT_Session::session();
196 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
199 string IOR = app->orb()->object_to_string( object );
202 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
203 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) );
205 _PTR(GenericAttribute) anAttr;
207 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
209 _PTR(AttributeName) aNameAttr( anAttr );
210 return aNameAttr->Value();
218 //=================================================================
220 * GEOM_Displayer::GEOM_Displayer
223 //=================================================================
224 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
227 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
232 SUIT_Session* session = SUIT_Session::session();
233 SUIT_ResourceMgr* resMgr = session->resourceMgr();
235 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
236 myShadingColor = SalomeApp_Tools::color( col );
238 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
241 // This color is used for shape displaying. If it is equal -1 then
242 // default color is used.
248 // This parameter is used for activisation/deactivisation of objects to be displayed
253 //=================================================================
255 * GEOM_Displayer::~GEOM_Displayer
258 //=================================================================
259 GEOM_Displayer::~GEOM_Displayer()
263 //=================================================================
265 * GEOM_Displayer::Display
266 * Display interactive object in the current viewer
268 //=================================================================
269 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
270 const bool updateViewer,
271 SALOME_View* theViewFrame )
273 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
276 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
280 vf->BeforeDisplay( this );
282 vf->AfterDisplay( this );
287 delete prs; // delete presentation because displayer is its owner
292 //=================================================================
294 * GEOM_Displayer::Display
295 * This overloaded Display() method can be useful for operations
296 * not using dialog boxes.
298 //=================================================================
299 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
301 if ( theObj->_is_nil() )
304 string entry = getEntry( theObj );
306 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
311 //=================================================================
313 * GEOM_Displayer::Erase
314 * Erase interactive object in the current viewer
316 //=================================================================
317 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
319 const bool updateViewer,
320 SALOME_View* theViewFrame )
322 if ( theIO.IsNull() )
325 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
328 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
330 vf->Erase( prs, forced );
333 delete prs; // delete presentation because displayer is its owner
338 //=================================================================
340 * GEOM_Displayer::Erase
341 * Erase geometry object in the current viewer
343 //=================================================================
344 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
346 const bool updateViewer )
348 string entry = getEntry( theObj );
351 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
352 forced, updateViewer);
356 //=================================================================
358 * GEOM_Displayer::Redisplay
359 * Redisplay (erase and then display again) interactive object
360 * in the current viewer
362 //=================================================================
363 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
364 const bool updateViewer )
366 // Remove the object permanently (<forced> == true)
367 SUIT_Session* ses = SUIT_Session::session();
368 SUIT_Application* app = ses->activeApplication();
371 SUIT_Desktop* desk = app->desktop();
372 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
373 SUIT_ViewWindow* wnd;
374 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
376 SUIT_ViewManager* vman = wnd->getViewManager();
379 SUIT_ViewModel* vmodel = vman->getViewModel();
382 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
385 if ( view->isVisible( theIO ) || view == GetActiveView() )
387 Erase( theIO, true, false, view );
388 Display( theIO, updateViewer, view );
397 //=================================================================
399 * GEOM_Displayer::Display
400 * Calls Display() method for each object in the given list
402 //=================================================================
403 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
405 SALOME_ListIteratorOfListIO Iter( theIOList );
406 for ( ; Iter.More(); Iter.Next() ) {
407 Display( Iter.Value(), false );
413 //=================================================================
415 * GEOM_Displayer::Erase
416 * Calls Erase() method for each object in the given list
418 //=================================================================
419 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
421 const bool updateViewer )
423 SALOME_ListIteratorOfListIO Iter( theIOList );
424 for ( ; Iter.More(); Iter.Next() )
425 Erase( Iter.Value(), forced, false );
431 //=================================================================
433 * GEOM_Displayer::Redisplay
434 * Calls Redisplay() method for each object in the given list
436 //=================================================================
437 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
439 SALOME_ListIteratorOfListIO Iter( theIOList );
440 for ( ; Iter.More(); Iter.Next() )
441 Redisplay( Iter.Value(), false );
447 //=================================================================
449 * GEOM_Displayer::Update
450 * Update OCC presentaion
451 * [ Reimplemented from SALOME_Displayer ]
453 //=================================================================
454 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
456 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
460 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
462 TopoDS_Face aFace = TopoDS::Face( myShape );
463 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
464 if ( !aPlane.IsNull() )
466 gp_Ax3 aPos = aPlane->Pln().Position();
467 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
469 Handle(GEOM_AISTrihedron) aTrh;
471 if ( occPrs->IsNull() )
473 aTrh = new GEOM_AISTrihedron( aPlc );
476 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
479 aTrh->SetWidth( GetWidth() );
481 if ( !myIO.IsNull() )
484 aTrh->SetOwner( myIO );
487 occPrs->AddObject( aTrh );
491 AIS_ListOfInteractive aList;
492 occPrs->GetObjects( aList );
493 AIS_ListIteratorOfListOfInteractive anIter( aList );
494 for ( ; anIter.More(); anIter.Next() )
496 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
497 if ( !aTrh.IsNull() )
499 aTrh->SetComponent( aPlc );
505 occPrs->SetToActivate( ToActivate() );
510 // if presentation is empty we try to create new one
511 if ( occPrs->IsNull() )
513 if ( !myShape.IsNull() )
515 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
516 // Temporary staff: vertex must be infinite for correct visualization
517 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
519 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
520 AISShape->SetDisplayMode( myDisplayMode );
521 AISShape->SetShadingColor( myShadingColor );
525 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
526 if ( myShape.ShapeType() == TopAbs_VERTEX )
528 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
529 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
530 AISShape->Attributes()->SetPointAspect( anAspect );
535 AISShape->SetWidth( GetWidth() );
537 if ( !myIO.IsNull() )
539 AISShape->setIO( myIO );
540 AISShape->SetOwner( myIO );
542 else if ( !myName.empty() )
544 // Workaround to allow selection of temporary objects
545 static int tempId = 0;
547 sprintf( buf, "TEMP_%d", tempId++ );
548 Handle( SALOME_InteractiveObject ) anObj =
549 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
550 AISShape->setIO( anObj );
551 AISShape->SetOwner( anObj );
553 // AISShape->SetName(???); ??? necessary to set name ???
554 occPrs->AddObject( AISShape );
556 // In accordance with ToActivate() value object will be activated/deactivated
557 // when it will be displayed
558 occPrs->SetToActivate( ToActivate() );
561 // if presentation is found -> set again shape for it
564 if ( !myShape.IsNull() )
566 AIS_ListOfInteractive IOList;
567 occPrs->GetObjects( IOList );
568 AIS_ListIteratorOfListOfInteractive Iter( IOList );
569 for ( ; Iter.More(); Iter.Next() )
571 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
572 if ( AISShape.IsNull() )
574 if ( AISShape->Shape() != myShape )
576 AISShape->Set( myShape );
577 AISShape->UpdateSelection();
578 AISShape->SetToUpdate();
580 if ( !myIO.IsNull() )
582 AISShape->setIO( myIO );
583 AISShape->SetOwner( myIO );
591 //=================================================================
593 * GEOM_Displayer::Update
594 * Update VTK presentaion
595 * [ Reimplemented from SALOME_Displayer ]
597 //=================================================================
598 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
600 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
601 if ( !vtkPrs || myShape.IsNull() )
604 vtkActorCollection* theActors = 0;
606 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
608 myToActivate = false;
609 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
613 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
614 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
617 Handle(Geom_Plane) aPlane =
618 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
619 if ( aPlane.IsNull() )
622 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
623 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
625 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
626 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
628 vtkPrs->AddObject( aTrh );
630 theActors = vtkActorCollection::New();
631 theActors->AddItem( aTrh );
634 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
636 theActors->InitTraversal();
638 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
640 vtkProperty* aProp = 0;
642 if ( HasColor() || HasWidth() )
644 aProp = vtkProperty::New();
645 aProp->SetRepresentationToWireframe();
650 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
651 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
656 aProp->SetLineWidth( GetWidth() );
659 while ( anActor != NULL )
661 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
663 GActor->setIO( myIO );
667 GActor->SetProperty( aProp );
668 GActor->SetPreviewProperty( aProp );
670 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
671 if ( aGeomGActor != 0 )
673 aGeomGActor->SetShadingProperty( aProp );
674 aGeomGActor->SetWireframeProperty( aProp );
679 GActor->PickableOn();
681 GActor->PickableOff();
683 vtkPrs->AddObject( GActor );
685 anActor = (vtkActor*)theActors->GetNextActor();
694 //=================================================================
696 * GEOM_Displayer::BuildPrs
697 * Build presentation accordint to the current viewer type
699 //=================================================================
700 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
702 if ( theObj->_is_nil() )
705 myViewFrame = GetActiveView();
706 if ( myViewFrame == 0 )
709 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
714 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
715 myType = theObj->GetType();
717 // Update presentation
723 //=================================================================
725 * GEOM_Displayer::BuildPrs
726 * Build presentation accordint to the current viewer type
728 //=================================================================
729 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
731 myViewFrame = GetActiveView();
732 if ( theShape.IsNull() || myViewFrame == 0 )
735 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
740 setShape( theShape );
748 //=================================================================
750 * GEOM_Displayer::buildPresentation
751 * Builds/finds object's presentation for the current viewer
752 * Calls corresponding Update() method by means of double dispatch
755 //=================================================================
756 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
757 SALOME_View* theViewFrame )
762 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
766 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
769 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
770 theIO->setEntry( entry.latin1() );
771 if ( !theIO.IsNull() )
773 // set interactive object
775 // Find SOBject (because shape should be published previously)
776 SUIT_Session* session = SUIT_Session::session();
777 SUIT_Application* app = session->activeApplication();
780 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
783 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
786 // get CORBA reference to data object
787 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
788 if ( !CORBA::is_nil( object ) )
790 // downcast to GEOM object
791 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
792 if ( !GeomObject->_is_nil() )
795 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
796 myType = GeomObject->GetType();
803 UpdatePrs( prs ); // Update presentation by using of the double dispatch
809 //=================================================================
811 * GEOM_Displayer::internalReset
812 * Resets internal data
815 //=================================================================
816 void GEOM_Displayer::internalReset()
822 //=================================================================
824 * GEOM_Displayer::LocalSelection
825 * Activate selection of CAD shapes with activisation of selection
826 * of their sub-shapes (with opened local context for OCC viewer)
828 //=================================================================
829 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
831 SUIT_Session* session = SUIT_Session::session();
832 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
836 LightApp_SelectionMgr* sm = app->selectionMgr();
838 // remove all filters from selection
841 SALOME_View* vf = GetActiveView();
843 if (!theIO.IsNull() && !vf->isVisible(theIO))
845 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
846 vf->LocalSelection( prs, theMode );
847 delete prs; // delete presentation because displayer is its owner
851 //=================================================================
853 * GEOM_Displayer::globalSelection
854 * Activate selection of CAD shapes without activisation of selection
855 * of their sub-shapes (without opened local context for OCC viewer)
857 //=================================================================
858 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
860 TColStd_MapOfInteger aModes;
861 aModes.Add( theMode );
862 GlobalSelection( aModes, update );
865 //=================================================================
867 * GEOM_Displayer::globalSelection
868 * Activate selection of CAD shapes without activisation of selection
869 * of their sub-shapes (without opened local context for OCC viewer)
871 //=================================================================
872 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
875 SUIT_Session* session = SUIT_Session::session();
876 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
880 SALOME_View* vf = GetActiveView();
884 // Close local context
885 vf->GlobalSelection( update );
887 // Set selection filters in accordance with current mode
888 LightApp_SelectionMgr* sm = app->selectionMgr();
892 // Remove from selection temporary objects if necessary
893 if ( !theModes.Contains( GEOM_PREVIEW ) )
894 clearTemporary( sm );
896 //@ aSel->ClearIndex();
900 // Remove filters from AIS_InteractiveContext
901 Handle(AIS_InteractiveContext) ic;
902 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
905 ic = viewer->getAISContext();
910 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
913 SUIT_SelectionFilter* aFilter;
914 if ( theModes.Extent() == 1 )
916 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
917 aFilter = getFilter( aMode );
919 else if ( theModes.Extent() > 1 )
921 TColStd_MapOfInteger aTopAbsModes;
922 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
923 QPtrList<SUIT_SelectionFilter> aListOfFilters;
924 for ( ; anIter.More(); anIter.Next() )
926 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
928 aListOfFilters.append( aFilter );
931 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
938 sm->installFilter( aFilter );
941 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
942 ic->AddFilter( anOCCFilter );
947 //=================================================================
949 * GEOM_Displayer::LocalSelection
950 * Activate selection of CAD shapes with activisation of selection
951 * of their sub-shapes (with opened local context for OCC viewer)
953 //=================================================================
954 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
956 SALOME_ListIteratorOfListIO Iter( theIOList );
957 for ( ; Iter.More(); Iter.Next() )
958 LocalSelection( Iter.Value(), theMode );
961 //=================================================================
963 * GEOM_Displayer::BeforeDisplay
964 * Called before displaying of pars. Close local context
965 * [ Reimplemented from SALOME_Displayer ]
967 //=================================================================
968 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
970 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
973 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
976 if ( ic->HasOpenedContext() )
977 ic->CloseAllContexts();
982 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
987 //=================================================================
989 * GEOM_Displayer::SetColor
990 * Set color for shape displaying. If it is equal -1 then default color is used.
991 * Available values are from Quantity_NameOfColor enumeration
993 //=================================================================
994 void GEOM_Displayer::SetColor( const int color )
999 int GEOM_Displayer::GetColor() const
1004 bool GEOM_Displayer::HasColor() const
1006 return myColor != -1;
1009 void GEOM_Displayer::UnsetColor()
1014 //=================================================================
1016 * GEOM_Displayer::SetWidth
1017 * Set width of shape displaying. If it is equal -1 then default width is used.
1019 //=================================================================
1020 void GEOM_Displayer::SetWidth( const double width )
1025 double GEOM_Displayer::GetWidth() const
1030 bool GEOM_Displayer::HasWidth() const
1032 return myWidth != -1;
1035 void GEOM_Displayer::UnsetWidth()
1040 //=================================================================
1042 * GEOM_Displayer::SetToActivate
1043 * This method is used for activisation/deactivisation of objects to be displayed
1045 //=================================================================
1046 void GEOM_Displayer::SetToActivate( const bool toActivate )
1048 myToActivate = toActivate;
1050 bool GEOM_Displayer::ToActivate() const
1052 return myToActivate;
1055 //=================================================================
1057 * GEOM_Displayer::clearTemporary
1058 * Removes from selection temporary objects
1060 //=================================================================
1061 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1063 SALOME_ListIO selected, toSelect;
1064 theSelMgr->selectedObjects( selected );
1066 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1067 Handle(SALOME_InteractiveObject) io = it.Value();
1068 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1069 toSelect.Append( it.Value() );
1072 theSelMgr->setSelectedObjects( toSelect, true );
1075 void GEOM_Displayer::SetName( const char* theName )
1080 void GEOM_Displayer::UnsetName()
1085 SalomeApp_Study* GEOM_Displayer::getStudy() const
1087 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1090 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1095 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1100 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1102 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();