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>
56 #include <SalomeApp_Tools.h>
58 #include <SALOME_ListIteratorOfListIO.hxx>
59 #include <SALOMEDSClient.hxx>
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDSClient_SObject.hxx>
66 #include <SVTK_ViewModel.h>
68 #include <TColStd_MapOfInteger.hxx>
69 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
71 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
73 #include <GeometryGUI.h>
74 #include <GEOM_AISShape.hxx>
75 #include <AIS_ListIteratorOfListOfInteractive.hxx>
76 #include <AIS_Drawer.hxx>
77 #include <Prs3d_PointAspect.hxx>
78 #include <Graphic3d_AspectMarker3d.hxx>
79 #include <Geom_Plane.hxx>
80 #include <TopoDS_Face.hxx>
81 #include <BRep_Tool.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <StdSelect_TypeOfEdge.hxx>
85 #include <StdSelect_TypeOfFace.hxx>
86 #include <vtkActorCollection.h>
92 //================================================================
93 // Function : getActiveStudy
94 // Purpose : Get active study, returns 0 if no open study frame
95 //================================================================
96 static inline SalomeApp_Study* getActiveStudy()
98 SUIT_Session* session = SUIT_Session::session();
99 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
101 return ( SalomeApp_Study* )app->activeStudy();
105 //================================================================
106 // Function : getTopAbsMode
107 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
108 // one from GEOMImpl_Types.h
109 //================================================================
110 static inline int getTopAbsMode( const int implType )
114 case GEOM_COMPOUND : return TopAbs_COMPOUND;
115 case GEOM_SOLID : return TopAbs_SOLID;
116 case GEOM_SHELL : return TopAbs_SHELL;
117 case GEOM_FACE : return TopAbs_FACE;
118 case GEOM_WIRE : return TopAbs_WIRE;
119 case GEOM_EDGE : return TopAbs_EDGE;
120 case GEOM_POINT : return TopAbs_VERTEX;
125 //================================================================
126 // Function : getFilter
127 // Purpose : Get filter corresponding to the type of object
128 // from GEOMImpl_Types.h
129 //================================================================
130 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
132 SUIT_SelectionFilter* aFilter;
134 int aTopAbsMode = getTopAbsMode( theMode );
135 if ( aTopAbsMode != -1 )
136 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
140 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
141 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
143 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
144 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
145 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
146 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
147 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
148 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
150 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
152 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
153 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
155 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
161 //================================================================
162 // Function : getEntry
164 //================================================================
165 static char* getEntry( GEOM::GEOM_Object_ptr object )
167 SUIT_Session* session = SUIT_Session::session();
168 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
171 string IOR = app->orb()->object_to_string( object );
174 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
175 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
177 return (char*)(SO->GetID().c_str());
183 //================================================================
184 // Function : getName
186 //================================================================
187 static const char* getName( GEOM::GEOM_Object_ptr object )
189 SUIT_Session* session = SUIT_Session::session();
190 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
193 string IOR = app->orb()->object_to_string( object );
196 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
197 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) );
199 _PTR(GenericAttribute) anAttr;
201 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
203 _PTR(AttributeName) aNameAttr( anAttr );
204 return aNameAttr->Value().c_str();
212 //=================================================================
214 * GEOM_Displayer::GEOM_Displayer
217 //=================================================================
218 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study )
223 SUIT_Session* session = SUIT_Session::session();
224 SUIT_ResourceMgr* resMgr = session->resourceMgr();
226 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
227 myShadingColor = SalomeApp_Tools::color( col );
229 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
232 // This color is used for shape displaying. If it is equal -1 then
233 // default color is used.
239 // This parameter is used for activisation/deactivisation of objects to be displayed
244 //=================================================================
246 * GEOM_Displayer::~GEOM_Displayer
249 //=================================================================
250 GEOM_Displayer::~GEOM_Displayer()
254 //=================================================================
257 * Get active study frame, returns 0 if no open study frame
259 //=================================================================
260 SALOME_View* GEOM_Displayer::GetActiveView()
262 SUIT_Session* session = SUIT_Session::session();
263 if ( SUIT_Application* app = session->activeApplication() ) {
264 if ( SalomeApp_Application* sApp = dynamic_cast<SalomeApp_Application*>( app ) ) {
265 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
266 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
267 return dynamic_cast<SALOME_View*>( vmod );
274 //=================================================================
276 * GEOM_Displayer::Display
277 * Display interactive object in the current viewer
279 //=================================================================
280 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
281 const bool updateViewer,
282 SALOME_View* theViewFrame )
284 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
287 SALOME_Prs* prs = buildPresentation( theIO, vf );
291 vf->BeforeDisplay( this );
293 vf->AfterDisplay( this );
298 delete prs; // delete presentation because displayer is its owner
303 //=================================================================
305 * GEOM_Displayer::Display
306 * This overloaded Display() method can be useful for operations
307 * not using dialog boxes.
309 //=================================================================
310 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
312 if ( theObj->_is_nil() )
315 string entry = getEntry( theObj );
317 Display( new SALOME_InteractiveObject(
318 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer );
322 //=================================================================
324 * GEOM_Displayer::Erase
325 * Erase interactive object in the current viewer
327 //=================================================================
328 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
330 const bool updateViewer,
331 SALOME_View* theViewFrame )
333 if ( theIO.IsNull() )
336 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
339 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
341 vf->Erase( prs, forced );
344 delete prs; // delete presentation because displayer is its owner
349 //=================================================================
351 * GEOM_Displayer::Erase
352 * Erase geometry object in the current viewer
354 //=================================================================
355 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
357 const bool updateViewer )
359 string entry = getEntry( theObj );
362 Erase( new SALOME_InteractiveObject(
363 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer );
367 //=================================================================
369 * GEOM_Displayer::EraseAll
370 * Erase all objects in the current viewer
372 //=================================================================
373 void GEOM_Displayer::EraseAll ( const bool forced,
374 const bool updateViewer,
375 SALOME_View* theViewFrame )
377 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
380 vf->EraseAll( forced );
386 //=================================================================
388 * GEOM_Displayer::Redisplay
389 * Redisplay (erase and then display again) interactive object
390 * in the current viewer
392 //=================================================================
393 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
394 const bool updateViewer )
396 // Remove the object permanently (<forced> == true)
397 SUIT_Session* ses = SUIT_Session::session();
398 SUIT_Application* app = ses->activeApplication();
401 SUIT_Desktop* desk = app->desktop();
402 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
403 SUIT_ViewWindow* wnd;
404 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
406 SUIT_ViewManager* vman = wnd->getViewManager();
409 SUIT_ViewModel* vmodel = vman->getViewModel();
412 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
415 if ( view->isVisible( theIO ) || view == GetActiveView() )
417 Erase( theIO, true, false, view );
418 Display( theIO, updateViewer, view );
427 //=================================================================
429 * GEOM_Displayer::Display
430 * Calls Display() method for each object in the given list
432 //=================================================================
433 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
435 SALOME_ListIteratorOfListIO Iter( theIOList );
436 for ( ; Iter.More(); Iter.Next() ) {
437 Display( Iter.Value(), false );
443 //=================================================================
445 * GEOM_Displayer::Erase
446 * Calls Erase() method for each object in the given list
448 //=================================================================
449 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
451 const bool updateViewer )
453 SALOME_ListIteratorOfListIO Iter( theIOList );
454 for ( ; Iter.More(); Iter.Next() )
455 Erase( Iter.Value(), forced, false );
461 //=================================================================
463 * GEOM_Displayer::Redisplay
464 * Calls Redisplay() method for each object in the given list
466 //=================================================================
467 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
469 SALOME_ListIteratorOfListIO Iter( theIOList );
470 for ( ; Iter.More(); Iter.Next() )
471 Redisplay( Iter.Value(), false );
477 //=================================================================
479 * GEOM_Displayer::UpdateViewer
480 * Update current viewer
482 //=================================================================
483 void GEOM_Displayer::UpdateViewer()
485 SALOME_View* vf = GetActiveView();
490 //=================================================================
492 * GEOM_Displayer::Update
493 * Update OCC presentaion
494 * [ Reimplemented from SALOME_Displayer ]
496 //=================================================================
497 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
499 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
503 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
505 TopoDS_Face aFace = TopoDS::Face( myShape );
506 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
507 if ( !aPlane.IsNull() )
509 gp_Ax3 aPos = aPlane->Pln().Position();
510 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
512 Handle(GEOM_AISTrihedron) aTrh;
514 if ( occPrs->IsNull() )
516 aTrh = new GEOM_AISTrihedron( aPlc );
519 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
522 aTrh->SetWidth( GetWidth() );
524 if ( !myIO.IsNull() )
527 aTrh->SetOwner( myIO );
530 occPrs->AddObject( aTrh );
534 AIS_ListOfInteractive aList;
535 occPrs->GetObjects( aList );
536 AIS_ListIteratorOfListOfInteractive anIter( aList );
537 for ( ; anIter.More(); anIter.Next() )
539 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
540 if ( !aTrh.IsNull() )
542 aTrh->SetComponent( aPlc );
548 occPrs->SetToActivate( ToActivate() );
553 // if presentation is empty we try to create new one
554 if ( occPrs->IsNull() )
556 if ( !myShape.IsNull() )
558 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
559 // Temporary staff: vertex must be infinite for correct visualization
560 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
562 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
563 AISShape->SetDisplayMode( myDisplayMode );
564 AISShape->SetShadingColor( myShadingColor );
568 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
569 if ( myShape.ShapeType() == TopAbs_VERTEX )
571 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
572 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
573 AISShape->Attributes()->SetPointAspect( anAspect );
578 AISShape->SetWidth( GetWidth() );
580 if ( !myIO.IsNull() )
582 AISShape->setIO( myIO );
583 AISShape->SetOwner( myIO );
585 else if ( !myName.empty() )
587 // Workaround to allow selection of temporary objects
588 static int tempId = 0;
590 sprintf( buf, "TEMP_%d", tempId++ );
591 Handle( SALOME_InteractiveObject ) anObj =
592 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
593 AISShape->setIO( anObj );
594 AISShape->SetOwner( anObj );
596 // AISShape->SetName(???); ??? necessary to set name ???
597 occPrs->AddObject( AISShape );
599 // In accordance with ToActivate() value object will be activated/deactivated
600 // when it will be displayed
601 occPrs->SetToActivate( ToActivate() );
604 // if presentation is found -> set again shape for it
607 if ( !myShape.IsNull() )
609 AIS_ListOfInteractive IOList;
610 occPrs->GetObjects( IOList );
611 AIS_ListIteratorOfListOfInteractive Iter( IOList );
612 for ( ; Iter.More(); Iter.Next() )
614 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
615 if ( AISShape.IsNull() )
617 if ( AISShape->Shape() != myShape )
619 AISShape->Set( myShape );
620 AISShape->UpdateSelection();
621 AISShape->SetToUpdate();
623 if ( !myIO.IsNull() )
625 AISShape->setIO( myIO );
626 AISShape->SetOwner( myIO );
634 //=================================================================
636 * GEOM_Displayer::Update
637 * Update VTK presentaion
638 * [ Reimplemented from SALOME_Displayer ]
640 //=================================================================
641 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
643 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
644 if ( !vtkPrs || myShape.IsNull() )
647 vtkActorCollection* theActors = 0;
649 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
651 myToActivate = false;
652 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
656 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
657 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
660 Handle(Geom_Plane) aPlane =
661 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
662 if ( aPlane.IsNull() )
665 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
666 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
668 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
669 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
671 vtkPrs->AddObject( aTrh );
673 theActors = vtkActorCollection::New();
674 theActors->AddItem( aTrh );
677 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
679 theActors->InitTraversal();
681 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
683 vtkProperty* aProp = 0;
685 if ( HasColor() || HasWidth() )
687 aProp = vtkProperty::New();
688 aProp->SetRepresentationToWireframe();
693 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
694 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
699 aProp->SetLineWidth( GetWidth() );
702 while ( anActor != NULL )
704 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
706 GActor->setIO( myIO );
710 GActor->SetProperty( aProp );
711 GActor->SetPreviewProperty( aProp );
713 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
714 if ( aGeomGActor != 0 )
716 aGeomGActor->SetShadingProperty( aProp );
717 aGeomGActor->SetWireframeProperty( aProp );
722 GActor->PickableOn();
724 GActor->PickableOff();
726 vtkPrs->AddObject( GActor );
728 anActor = (vtkActor*)theActors->GetNextActor();
737 //=================================================================
739 * GEOM_Displayer::BuildPrs
740 * Build presentation accordint to the current viewer type
742 //=================================================================
743 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
745 if ( theObj->_is_nil() )
748 myViewFrame = GetActiveView();
749 if ( myViewFrame == 0 )
752 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
757 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
758 myType = theObj->GetType();
760 // Update presentation
766 //=================================================================
768 * GEOM_Displayer::BuildPrs
769 * Build presentation accordint to the current viewer type
771 //=================================================================
772 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
774 myViewFrame = GetActiveView();
775 if ( theShape.IsNull() || myViewFrame == 0 )
778 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
783 setShape( theShape );
791 //=================================================================
793 * GEOM_Displayer::buildPresentation
794 * Builds/finds object's presentation for the current viewer
795 * Calls corresponding Update() method by means of double dispatch
798 //=================================================================
799 SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveObject)& theIO,
800 SALOME_View* theViewFrame )
805 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
809 prs = myViewFrame->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 );
812 if ( !theIO.IsNull() )
814 // set interactive object
816 // Find SOBject (because shape should be published previously)
817 SUIT_Session* session = SUIT_Session::session();
818 SUIT_Application* app = session->activeApplication();
821 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
824 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
827 // get CORBA reference to data object
828 CORBA::Object_var object = dynamic_cast<SALOMEDS_SObject*>(SO.get())->GetObject();
829 if ( !CORBA::is_nil( object ) )
831 // downcast to GEOM object
832 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
833 if ( !GeomObject->_is_nil() )
836 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
837 myType = GeomObject->GetType();
844 UpdatePrs( prs ); // Update presentation by using of the double dispatch
850 //=================================================================
852 * GEOM_Displayer::internalReset
853 * Resets internal data
856 //=================================================================
857 void GEOM_Displayer::internalReset()
863 //=================================================================
865 * GEOM_Displayer::LocalSelection
866 * Activate selection of CAD shapes with activisation of selection
867 * of their sub-shapes (with opened local context for OCC viewer)
869 //=================================================================
870 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
872 SUIT_Session* session = SUIT_Session::session();
873 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
877 SalomeApp_SelectionMgr* sm = app->selectionMgr();
879 // remove all filters from selection
882 SALOME_View* vf = GetActiveView();
885 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
886 vf->LocalSelection( prs, theMode );
887 delete prs; // delete presentation because displayer is its owner
891 //=================================================================
893 * GEOM_Displayer::globalSelection
894 * Activate selection of CAD shapes without activisation of selection
895 * of their sub-shapes (without opened local context for OCC viewer)
897 //=================================================================
898 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
900 TColStd_MapOfInteger aModes;
901 aModes.Add( theMode );
902 GlobalSelection( aModes, update );
905 //=================================================================
907 * GEOM_Displayer::globalSelection
908 * Activate selection of CAD shapes without activisation of selection
909 * of their sub-shapes (without opened local context for OCC viewer)
911 //=================================================================
912 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
915 SUIT_Session* session = SUIT_Session::session();
916 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
920 SALOME_View* vf = GetActiveView();
924 // Close local context
925 vf->GlobalSelection( update );
927 // Set selection filters in accordance with current mode
928 SalomeApp_SelectionMgr* sm = app->selectionMgr();
932 // Remove from selection temporary objects if necessary
933 if ( !theModes.Contains( GEOM_PREVIEW ) )
934 clearTemporary( sm );
936 //@ aSel->ClearIndex();
940 // Remove filters from AIS_InteractiveContext
941 Handle(AIS_InteractiveContext) ic;
942 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
945 ic = viewer->getAISContext();
950 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
953 SUIT_SelectionFilter* aFilter;
954 if ( theModes.Extent() == 1 )
956 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
957 aFilter = getFilter( aMode );
959 else if ( theModes.Extent() > 1 )
961 TColStd_MapOfInteger aTopAbsModes;
962 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
963 QPtrList<SUIT_SelectionFilter> aListOfFilters;
964 for ( ; anIter.More(); anIter.Next() )
966 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
968 aListOfFilters.append( aFilter );
971 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
978 sm->installFilter( aFilter );
981 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
982 ic->AddFilter( anOCCFilter );
987 //=================================================================
989 * GEOM_Displayer::LocalSelection
990 * Activate selection of CAD shapes with activisation of selection
991 * of their sub-shapes (with opened local context for OCC viewer)
993 //=================================================================
994 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
996 SALOME_ListIteratorOfListIO Iter( theIOList );
997 for ( ; Iter.More(); Iter.Next() )
998 LocalSelection( Iter.Value(), theMode );
1001 //=================================================================
1003 * GEOM_Displayer::BeforeDisplay
1004 * Called before displaying of pars. Close local context
1005 * [ Reimplemented from SALOME_Displayer ]
1007 //=================================================================
1008 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1010 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1013 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1016 if ( ic->HasOpenedContext() )
1017 ic->CloseAllContexts();
1022 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1027 //=================================================================
1029 * GEOM_Displayer::SetColor
1030 * Set color for shape displaying. If it is equal -1 then default color is used.
1031 * Available values are from Quantity_NameOfColor enumeration
1033 //=================================================================
1034 void GEOM_Displayer::SetColor( const int color )
1039 int GEOM_Displayer::GetColor() const
1044 bool GEOM_Displayer::HasColor() const
1046 return myColor != -1;
1049 void GEOM_Displayer::UnsetColor()
1054 //=================================================================
1056 * GEOM_Displayer::SetWidth
1057 * Set width of shape displaying. If it is equal -1 then default width is used.
1059 //=================================================================
1060 void GEOM_Displayer::SetWidth( const double width )
1065 double GEOM_Displayer::GetWidth() const
1070 bool GEOM_Displayer::HasWidth() const
1072 return myWidth != -1;
1075 void GEOM_Displayer::UnsetWidth()
1080 //=================================================================
1082 * GEOM_Displayer::SetToActivate
1083 * This method is used for activisation/deactivisation of objects to be displayed
1085 //=================================================================
1086 void GEOM_Displayer::SetToActivate( const bool toActivate )
1088 myToActivate = toActivate;
1090 bool GEOM_Displayer::ToActivate() const
1092 return myToActivate;
1095 //=================================================================
1097 * GEOM_Displayer::clearTemporary
1098 * Removes from selection temporary objects
1100 //=================================================================
1101 void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr )
1103 SALOME_ListIO selected, toSelect;
1104 theSelMgr->selectedObjects( selected );
1106 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1107 Handle(SALOME_InteractiveObject) io = it.Value();
1108 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1109 toSelect.Append( it.Value() );
1112 theSelMgr->setSelectedObjects( toSelect, true );