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 SUIT_Application* app = session->activeApplication();
266 SUIT_Desktop* desk = app->desktop();
269 SUIT_ViewWindow* win = desk->activeWindow();
272 SUIT_ViewManager* vman = win->getViewManager();
275 SUIT_ViewModel* vmodel = vman->getViewModel();
278 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
288 //=================================================================
290 * GEOM_Displayer::Display
291 * Display interactive object in the current viewer
293 //=================================================================
294 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
295 const bool updateViewer,
296 SALOME_View* theViewFrame )
298 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
301 SALOME_Prs* prs = buildPresentation( theIO, vf );
305 vf->BeforeDisplay( this );
307 vf->AfterDisplay( this );
312 delete prs; // delete presentation because displayer is its owner
317 //=================================================================
319 * GEOM_Displayer::Display
320 * This overloaded Display() method can be useful for operations
321 * not using dialog boxes.
323 //=================================================================
324 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
326 if ( theObj->_is_nil() )
329 string entry = getEntry( theObj );
331 Display( new SALOME_InteractiveObject(
332 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer );
336 //=================================================================
338 * GEOM_Displayer::Erase
339 * Erase interactive object in the current viewer
341 //=================================================================
342 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
344 const bool updateViewer,
345 SALOME_View* theViewFrame )
347 if ( theIO.IsNull() )
350 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
353 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
355 vf->Erase( prs, forced );
358 delete prs; // delete presentation because displayer is its owner
363 //=================================================================
365 * GEOM_Displayer::Erase
366 * Erase geometry object in the current viewer
368 //=================================================================
369 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
371 const bool updateViewer )
373 string entry = getEntry( theObj );
376 Erase( new SALOME_InteractiveObject(
377 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer );
381 //=================================================================
383 * GEOM_Displayer::EraseAll
384 * Erase all objects in the current viewer
386 //=================================================================
387 void GEOM_Displayer::EraseAll ( const bool forced,
388 const bool updateViewer,
389 SALOME_View* theViewFrame )
391 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
394 vf->EraseAll( forced );
400 //=================================================================
402 * GEOM_Displayer::Redisplay
403 * Redisplay (erase and then display again) interactive object
404 * in the current viewer
406 //=================================================================
407 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
408 const bool updateViewer )
410 // Remove the object permanently (<forced> == true)
411 SUIT_Session* ses = SUIT_Session::session();
412 SUIT_Application* app = ses->activeApplication();
415 SUIT_Desktop* desk = app->desktop();
416 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
417 SUIT_ViewWindow* wnd;
418 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
420 SUIT_ViewManager* vman = wnd->getViewManager();
423 SUIT_ViewModel* vmodel = vman->getViewModel();
426 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
429 if ( view->isVisible( theIO ) || view == GetActiveView() )
431 Erase( theIO, true, false, view );
432 Display( theIO, updateViewer, view );
441 //=================================================================
443 * GEOM_Displayer::Display
444 * Calls Display() method for each object in the given list
446 //=================================================================
447 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
449 SALOME_ListIteratorOfListIO Iter( theIOList );
450 for ( ; Iter.More(); Iter.Next() ) {
451 Display( Iter.Value(), false );
457 //=================================================================
459 * GEOM_Displayer::Erase
460 * Calls Erase() method for each object in the given list
462 //=================================================================
463 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
465 const bool updateViewer )
467 SALOME_ListIteratorOfListIO Iter( theIOList );
468 for ( ; Iter.More(); Iter.Next() )
469 Erase( Iter.Value(), forced, false );
475 //=================================================================
477 * GEOM_Displayer::Redisplay
478 * Calls Redisplay() method for each object in the given list
480 //=================================================================
481 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
483 SALOME_ListIteratorOfListIO Iter( theIOList );
484 for ( ; Iter.More(); Iter.Next() )
485 Redisplay( Iter.Value(), false );
491 //=================================================================
493 * GEOM_Displayer::UpdateViewer
494 * Update current viewer
496 //=================================================================
497 void GEOM_Displayer::UpdateViewer()
499 SALOME_View* vf = GetActiveView();
504 //=================================================================
506 * GEOM_Displayer::Update
507 * Update OCC presentaion
508 * [ Reimplemented from SALOME_Displayer ]
510 //=================================================================
511 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
513 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
517 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
519 TopoDS_Face aFace = TopoDS::Face( myShape );
520 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
521 if ( !aPlane.IsNull() )
523 gp_Ax3 aPos = aPlane->Pln().Position();
524 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
526 Handle(GEOM_AISTrihedron) aTrh;
528 if ( occPrs->IsNull() )
530 aTrh = new GEOM_AISTrihedron( aPlc );
533 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
536 aTrh->SetWidth( GetWidth() );
538 if ( !myIO.IsNull() )
541 aTrh->SetOwner( myIO );
544 occPrs->AddObject( aTrh );
548 AIS_ListOfInteractive aList;
549 occPrs->GetObjects( aList );
550 AIS_ListIteratorOfListOfInteractive anIter( aList );
551 for ( ; anIter.More(); anIter.Next() )
553 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
554 if ( !aTrh.IsNull() )
556 aTrh->SetComponent( aPlc );
562 occPrs->SetToActivate( ToActivate() );
567 // if presentation is empty we try to create new one
568 if ( occPrs->IsNull() )
570 if ( !myShape.IsNull() )
572 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
573 // Temporary staff: vertex must be infinite for correct visualization
574 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
576 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
577 AISShape->SetDisplayMode( myDisplayMode );
578 AISShape->SetShadingColor( myShadingColor );
582 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
583 if ( myShape.ShapeType() == TopAbs_VERTEX )
585 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
586 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
587 AISShape->Attributes()->SetPointAspect( anAspect );
592 AISShape->SetWidth( GetWidth() );
594 if ( !myIO.IsNull() )
596 AISShape->setIO( myIO );
597 AISShape->SetOwner( myIO );
599 else if ( !myName.empty() )
601 // Workaround to allow selection of temporary objects
602 static int tempId = 0;
604 sprintf( buf, "TEMP_%d", tempId++ );
605 Handle( SALOME_InteractiveObject ) anObj =
606 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
607 AISShape->setIO( anObj );
608 AISShape->SetOwner( anObj );
610 // AISShape->SetName(???); ??? necessary to set name ???
611 occPrs->AddObject( AISShape );
613 // In accordance with ToActivate() value object will be activated/deactivated
614 // when it will be displayed
615 occPrs->SetToActivate( ToActivate() );
618 // if presentation is found -> set again shape for it
621 if ( !myShape.IsNull() )
623 AIS_ListOfInteractive IOList;
624 occPrs->GetObjects( IOList );
625 AIS_ListIteratorOfListOfInteractive Iter( IOList );
626 for ( ; Iter.More(); Iter.Next() )
628 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
629 if ( AISShape.IsNull() )
631 if ( AISShape->Shape() != myShape )
633 AISShape->Set( myShape );
634 AISShape->UpdateSelection();
635 AISShape->SetToUpdate();
637 if ( !myIO.IsNull() )
639 AISShape->setIO( myIO );
640 AISShape->SetOwner( myIO );
648 //=================================================================
650 * GEOM_Displayer::Update
651 * Update VTK presentaion
652 * [ Reimplemented from SALOME_Displayer ]
654 //=================================================================
655 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
657 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
658 if ( !vtkPrs || myShape.IsNull() )
661 vtkActorCollection* theActors = 0;
663 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
665 myToActivate = false;
666 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
670 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
671 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
674 Handle(Geom_Plane) aPlane =
675 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
676 if ( aPlane.IsNull() )
679 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
680 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
682 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
683 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
685 vtkPrs->AddObject( aTrh );
687 theActors = vtkActorCollection::New();
688 theActors->AddItem( aTrh );
691 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
693 theActors->InitTraversal();
695 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
697 vtkProperty* aProp = 0;
699 if ( HasColor() || HasWidth() )
701 aProp = vtkProperty::New();
702 aProp->SetRepresentationToWireframe();
707 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
708 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
713 aProp->SetLineWidth( GetWidth() );
716 while ( anActor != NULL )
718 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
720 GActor->setIO( myIO );
724 GActor->SetProperty( aProp );
725 GActor->SetPreviewProperty( aProp );
727 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
728 if ( aGeomGActor != 0 )
730 aGeomGActor->SetShadingProperty( aProp );
731 aGeomGActor->SetWireframeProperty( aProp );
736 GActor->PickableOn();
738 GActor->PickableOff();
740 vtkPrs->AddObject( GActor );
742 anActor = (vtkActor*)theActors->GetNextActor();
751 //=================================================================
753 * GEOM_Displayer::BuildPrs
754 * Build presentation accordint to the current viewer type
756 //=================================================================
757 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
759 if ( theObj->_is_nil() )
762 myViewFrame = GetActiveView();
763 if ( myViewFrame == 0 )
766 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
771 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
772 myType = theObj->GetType();
774 // Update presentation
780 //=================================================================
782 * GEOM_Displayer::BuildPrs
783 * Build presentation accordint to the current viewer type
785 //=================================================================
786 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
788 myViewFrame = GetActiveView();
789 if ( theShape.IsNull() || myViewFrame == 0 )
792 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
797 setShape( theShape );
805 //=================================================================
807 * GEOM_Displayer::buildPresentation
808 * Builds/finds object's presentation for the current viewer
809 * Calls corresponding Update() method by means of double dispatch
812 //=================================================================
813 SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveObject)& theIO,
814 SALOME_View* theViewFrame )
819 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
823 prs = myViewFrame->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 );
826 if ( !theIO.IsNull() )
828 // set interactive object
830 // Find SOBject (because shape should be published previously)
831 SUIT_Session* session = SUIT_Session::session();
832 SUIT_Application* app = session->activeApplication();
835 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
838 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
841 // get CORBA reference to data object
842 CORBA::Object_var object = dynamic_cast<SALOMEDS_SObject*>(SO.get())->GetObject();
843 if ( !CORBA::is_nil( object ) )
845 // downcast to GEOM object
846 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
847 if ( !GeomObject->_is_nil() )
850 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
851 myType = GeomObject->GetType();
858 UpdatePrs( prs ); // Update presentation by using of the double dispatch
864 //=================================================================
866 * GEOM_Displayer::internalReset
867 * Resets internal data
870 //=================================================================
871 void GEOM_Displayer::internalReset()
877 //=================================================================
879 * GEOM_Displayer::LocalSelection
880 * Activate selection of CAD shapes with activisation of selection
881 * of their sub-shapes (with opened local context for OCC viewer)
883 //=================================================================
884 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
886 SUIT_Session* session = SUIT_Session::session();
887 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
891 SalomeApp_SelectionMgr* sm = app->selectionMgr();
893 // remove all filters from selection
896 SALOME_View* vf = GetActiveView();
899 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
900 vf->LocalSelection( prs, theMode );
901 delete prs; // delete presentation because displayer is its owner
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 int theMode, const bool update )
914 TColStd_MapOfInteger aModes;
915 aModes.Add( theMode );
916 GlobalSelection( aModes, update );
919 //=================================================================
921 * GEOM_Displayer::globalSelection
922 * Activate selection of CAD shapes without activisation of selection
923 * of their sub-shapes (without opened local context for OCC viewer)
925 //=================================================================
926 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
929 SUIT_Session* session = SUIT_Session::session();
930 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
934 SALOME_View* vf = GetActiveView();
938 // Close local context
939 vf->GlobalSelection( update );
941 // Set selection filters in accordance with current mode
942 SalomeApp_SelectionMgr* sm = app->selectionMgr();
946 // Remove from selection temporary objects if necessary
947 if ( !theModes.Contains( GEOM_PREVIEW ) )
948 clearTemporary( sm );
950 //@ aSel->ClearIndex();
954 // Remove filters from AIS_InteractiveContext
955 Handle(AIS_InteractiveContext) ic;
956 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
959 ic = viewer->getAISContext();
964 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
967 SUIT_SelectionFilter* aFilter;
968 if ( theModes.Extent() == 1 )
970 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
971 aFilter = getFilter( aMode );
973 else if ( theModes.Extent() > 1 )
975 TColStd_MapOfInteger aTopAbsModes;
976 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
977 QPtrList<SUIT_SelectionFilter> aListOfFilters;
978 for ( ; anIter.More(); anIter.Next() )
980 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
982 aListOfFilters.append( aFilter );
985 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
992 sm->installFilter( aFilter );
995 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
996 ic->AddFilter( anOCCFilter );
1001 //=================================================================
1003 * GEOM_Displayer::LocalSelection
1004 * Activate selection of CAD shapes with activisation of selection
1005 * of their sub-shapes (with opened local context for OCC viewer)
1007 //=================================================================
1008 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1010 SALOME_ListIteratorOfListIO Iter( theIOList );
1011 for ( ; Iter.More(); Iter.Next() )
1012 LocalSelection( Iter.Value(), theMode );
1015 //=================================================================
1017 * GEOM_Displayer::BeforeDisplay
1018 * Called before displaying of pars. Close local context
1019 * [ Reimplemented from SALOME_Displayer ]
1021 //=================================================================
1022 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1024 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1027 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1030 if ( ic->HasOpenedContext() )
1031 ic->CloseAllContexts();
1036 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1041 //=================================================================
1043 * GEOM_Displayer::SetColor
1044 * Set color for shape displaying. If it is equal -1 then default color is used.
1045 * Available values are from Quantity_NameOfColor enumeration
1047 //=================================================================
1048 void GEOM_Displayer::SetColor( const int color )
1053 int GEOM_Displayer::GetColor() const
1058 bool GEOM_Displayer::HasColor() const
1060 return myColor != -1;
1063 void GEOM_Displayer::UnsetColor()
1068 //=================================================================
1070 * GEOM_Displayer::SetWidth
1071 * Set width of shape displaying. If it is equal -1 then default width is used.
1073 //=================================================================
1074 void GEOM_Displayer::SetWidth( const double width )
1079 double GEOM_Displayer::GetWidth() const
1084 bool GEOM_Displayer::HasWidth() const
1086 return myWidth != -1;
1089 void GEOM_Displayer::UnsetWidth()
1094 //=================================================================
1096 * GEOM_Displayer::SetToActivate
1097 * This method is used for activisation/deactivisation of objects to be displayed
1099 //=================================================================
1100 void GEOM_Displayer::SetToActivate( const bool toActivate )
1102 myToActivate = toActivate;
1104 bool GEOM_Displayer::ToActivate() const
1106 return myToActivate;
1109 //=================================================================
1111 * GEOM_Displayer::clearTemporary
1112 * Removes from selection temporary objects
1114 //=================================================================
1115 void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr )
1117 SALOME_ListIO selected, toSelect;
1118 theSelMgr->selectedObjects( selected );
1120 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1121 Handle(SALOME_InteractiveObject) io = it.Value();
1122 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1123 toSelect.Append( it.Value() );
1126 theSelMgr->setSelectedObjects( toSelect, true );