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 "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>
91 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
93 #include "GEOMImpl_Types.hxx"
97 //================================================================
98 // Function : getActiveStudy
99 // Purpose : Get active study, returns 0 if no open study frame
100 //================================================================
101 static inline SalomeApp_Study* getActiveStudy()
103 SUIT_Session* session = SUIT_Session::session();
104 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
106 return ( SalomeApp_Study* )app->activeStudy();
110 //================================================================
111 // Function : getTopAbsMode
112 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
113 // one from GEOMImpl_Types.h
114 //================================================================
115 static inline int getTopAbsMode( const int implType )
119 case GEOM_COMPOUND : return TopAbs_COMPOUND;
120 case GEOM_SOLID : return TopAbs_SOLID;
121 case GEOM_SHELL : return TopAbs_SHELL;
122 case GEOM_FACE : return TopAbs_FACE;
123 case GEOM_WIRE : return TopAbs_WIRE;
124 case GEOM_EDGE : return TopAbs_EDGE;
125 case GEOM_POINT : return TopAbs_VERTEX;
130 //================================================================
131 // Function : getFilter
132 // Purpose : Get filter corresponding to the type of object
133 // from GEOMImpl_Types.h
134 //================================================================
135 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
137 SUIT_SelectionFilter* aFilter;
139 int aTopAbsMode = getTopAbsMode( theMode );
140 if ( aTopAbsMode != -1 )
141 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
145 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
146 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
148 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
149 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
150 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
151 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
152 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
153 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
155 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
157 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
158 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
160 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
166 //================================================================
167 // Function : getEntry
169 //================================================================
170 static string getEntry( GEOM::GEOM_Object_ptr object )
172 SUIT_Session* session = SUIT_Session::session();
173 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
176 string IOR = app->orb()->object_to_string( object );
179 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
180 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
188 //================================================================
189 // Function : getName
191 //================================================================
192 static string getName( GEOM::GEOM_Object_ptr object )
194 SUIT_Session* session = SUIT_Session::session();
195 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
198 string IOR = app->orb()->object_to_string( object );
201 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
202 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) );
204 _PTR(GenericAttribute) anAttr;
206 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
208 _PTR(AttributeName) aNameAttr( anAttr );
209 return aNameAttr->Value();
217 //=================================================================
219 * GEOM_Displayer::GEOM_Displayer
222 //=================================================================
223 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study )
228 SUIT_Session* session = SUIT_Session::session();
229 SUIT_ResourceMgr* resMgr = session->resourceMgr();
231 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
232 myShadingColor = SalomeApp_Tools::color( col );
234 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
237 // This color is used for shape displaying. If it is equal -1 then
238 // default color is used.
244 // This parameter is used for activisation/deactivisation of objects to be displayed
249 //=================================================================
251 * GEOM_Displayer::~GEOM_Displayer
254 //=================================================================
255 GEOM_Displayer::~GEOM_Displayer()
259 //=================================================================
261 * GEOM_Displayer::Display
262 * Display interactive object in the current viewer
264 //=================================================================
265 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
266 const bool updateViewer,
267 SALOME_View* theViewFrame )
269 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
272 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
276 vf->BeforeDisplay( this );
278 vf->AfterDisplay( this );
283 delete prs; // delete presentation because displayer is its owner
288 //=================================================================
290 * GEOM_Displayer::Display
291 * This overloaded Display() method can be useful for operations
292 * not using dialog boxes.
294 //=================================================================
295 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
297 if ( theObj->_is_nil() )
300 string entry = getEntry( theObj );
302 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
307 //=================================================================
309 * GEOM_Displayer::Erase
310 * Erase interactive object in the current viewer
312 //=================================================================
313 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
315 const bool updateViewer,
316 SALOME_View* theViewFrame )
318 if ( theIO.IsNull() )
321 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
324 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
326 vf->Erase( prs, forced );
329 delete prs; // delete presentation because displayer is its owner
334 //=================================================================
336 * GEOM_Displayer::Erase
337 * Erase geometry object in the current viewer
339 //=================================================================
340 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
342 const bool updateViewer )
344 string entry = getEntry( theObj );
347 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
348 forced, updateViewer);
352 //=================================================================
354 * GEOM_Displayer::Redisplay
355 * Redisplay (erase and then display again) interactive object
356 * in the current viewer
358 //=================================================================
359 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
360 const bool updateViewer )
362 // Remove the object permanently (<forced> == true)
363 SUIT_Session* ses = SUIT_Session::session();
364 SUIT_Application* app = ses->activeApplication();
367 SUIT_Desktop* desk = app->desktop();
368 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
369 SUIT_ViewWindow* wnd;
370 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
372 SUIT_ViewManager* vman = wnd->getViewManager();
375 SUIT_ViewModel* vmodel = vman->getViewModel();
378 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
381 if ( view->isVisible( theIO ) || view == GetActiveView() )
383 Erase( theIO, true, false, view );
384 Display( theIO, updateViewer, view );
393 //=================================================================
395 * GEOM_Displayer::Display
396 * Calls Display() method for each object in the given list
398 //=================================================================
399 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
401 SALOME_ListIteratorOfListIO Iter( theIOList );
402 for ( ; Iter.More(); Iter.Next() ) {
403 Display( Iter.Value(), false );
409 //=================================================================
411 * GEOM_Displayer::Erase
412 * Calls Erase() method for each object in the given list
414 //=================================================================
415 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
417 const bool updateViewer )
419 SALOME_ListIteratorOfListIO Iter( theIOList );
420 for ( ; Iter.More(); Iter.Next() )
421 Erase( Iter.Value(), forced, false );
427 //=================================================================
429 * GEOM_Displayer::Redisplay
430 * Calls Redisplay() method for each object in the given list
432 //=================================================================
433 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
435 SALOME_ListIteratorOfListIO Iter( theIOList );
436 for ( ; Iter.More(); Iter.Next() )
437 Redisplay( Iter.Value(), false );
443 //=================================================================
445 * GEOM_Displayer::Update
446 * Update OCC presentaion
447 * [ Reimplemented from SALOME_Displayer ]
449 //=================================================================
450 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
452 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
456 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
458 TopoDS_Face aFace = TopoDS::Face( myShape );
459 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
460 if ( !aPlane.IsNull() )
462 gp_Ax3 aPos = aPlane->Pln().Position();
463 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
465 Handle(GEOM_AISTrihedron) aTrh;
467 if ( occPrs->IsNull() )
469 aTrh = new GEOM_AISTrihedron( aPlc );
472 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
475 aTrh->SetWidth( GetWidth() );
477 if ( !myIO.IsNull() )
480 aTrh->SetOwner( myIO );
483 occPrs->AddObject( aTrh );
487 AIS_ListOfInteractive aList;
488 occPrs->GetObjects( aList );
489 AIS_ListIteratorOfListOfInteractive anIter( aList );
490 for ( ; anIter.More(); anIter.Next() )
492 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
493 if ( !aTrh.IsNull() )
495 aTrh->SetComponent( aPlc );
501 occPrs->SetToActivate( ToActivate() );
506 // if presentation is empty we try to create new one
507 if ( occPrs->IsNull() )
509 if ( !myShape.IsNull() )
511 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
512 // Temporary staff: vertex must be infinite for correct visualization
513 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
515 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
516 AISShape->SetDisplayMode( myDisplayMode );
517 AISShape->SetShadingColor( myShadingColor );
521 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
522 if ( myShape.ShapeType() == TopAbs_VERTEX )
524 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
525 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
526 AISShape->Attributes()->SetPointAspect( anAspect );
531 AISShape->SetWidth( GetWidth() );
533 if ( !myIO.IsNull() )
535 AISShape->setIO( myIO );
536 AISShape->SetOwner( myIO );
538 else if ( !myName.empty() )
540 // Workaround to allow selection of temporary objects
541 static int tempId = 0;
543 sprintf( buf, "TEMP_%d", tempId++ );
544 Handle( SALOME_InteractiveObject ) anObj =
545 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
546 AISShape->setIO( anObj );
547 AISShape->SetOwner( anObj );
549 // AISShape->SetName(???); ??? necessary to set name ???
550 occPrs->AddObject( AISShape );
552 // In accordance with ToActivate() value object will be activated/deactivated
553 // when it will be displayed
554 occPrs->SetToActivate( ToActivate() );
557 // if presentation is found -> set again shape for it
560 if ( !myShape.IsNull() )
562 AIS_ListOfInteractive IOList;
563 occPrs->GetObjects( IOList );
564 AIS_ListIteratorOfListOfInteractive Iter( IOList );
565 for ( ; Iter.More(); Iter.Next() )
567 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
568 if ( AISShape.IsNull() )
570 if ( AISShape->Shape() != myShape )
572 AISShape->Set( myShape );
573 AISShape->UpdateSelection();
574 AISShape->SetToUpdate();
576 if ( !myIO.IsNull() )
578 AISShape->setIO( myIO );
579 AISShape->SetOwner( myIO );
587 //=================================================================
589 * GEOM_Displayer::Update
590 * Update VTK presentaion
591 * [ Reimplemented from SALOME_Displayer ]
593 //=================================================================
594 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
596 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
597 if ( !vtkPrs || myShape.IsNull() )
600 vtkActorCollection* theActors = 0;
602 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
604 myToActivate = false;
605 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
609 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
610 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
613 Handle(Geom_Plane) aPlane =
614 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
615 if ( aPlane.IsNull() )
618 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
619 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
621 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
622 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
624 vtkPrs->AddObject( aTrh );
626 theActors = vtkActorCollection::New();
627 theActors->AddItem( aTrh );
630 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
632 theActors->InitTraversal();
634 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
636 vtkProperty* aProp = 0;
638 if ( HasColor() || HasWidth() )
640 aProp = vtkProperty::New();
641 aProp->SetRepresentationToWireframe();
646 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
647 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
652 aProp->SetLineWidth( GetWidth() );
655 while ( anActor != NULL )
657 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
659 GActor->setIO( myIO );
663 GActor->SetProperty( aProp );
664 GActor->SetPreviewProperty( aProp );
666 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
667 if ( aGeomGActor != 0 )
669 aGeomGActor->SetShadingProperty( aProp );
670 aGeomGActor->SetWireframeProperty( aProp );
675 GActor->PickableOn();
677 GActor->PickableOff();
679 vtkPrs->AddObject( GActor );
681 anActor = (vtkActor*)theActors->GetNextActor();
690 //=================================================================
692 * GEOM_Displayer::BuildPrs
693 * Build presentation accordint to the current viewer type
695 //=================================================================
696 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
698 if ( theObj->_is_nil() )
701 myViewFrame = GetActiveView();
702 if ( myViewFrame == 0 )
705 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
710 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
711 myType = theObj->GetType();
713 // Update presentation
719 //=================================================================
721 * GEOM_Displayer::BuildPrs
722 * Build presentation accordint to the current viewer type
724 //=================================================================
725 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
727 myViewFrame = GetActiveView();
728 if ( theShape.IsNull() || myViewFrame == 0 )
731 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
736 setShape( theShape );
744 //=================================================================
746 * GEOM_Displayer::buildPresentation
747 * Builds/finds object's presentation for the current viewer
748 * Calls corresponding Update() method by means of double dispatch
751 //=================================================================
752 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
753 SALOME_View* theViewFrame )
758 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
762 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
765 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
766 theIO->setEntry( entry.latin1() );
767 if ( !theIO.IsNull() )
769 // set interactive object
771 // Find SOBject (because shape should be published previously)
772 SUIT_Session* session = SUIT_Session::session();
773 SUIT_Application* app = session->activeApplication();
776 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
779 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
782 // get CORBA reference to data object
783 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
784 if ( !CORBA::is_nil( object ) )
786 // downcast to GEOM object
787 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
788 if ( !GeomObject->_is_nil() )
791 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
792 myType = GeomObject->GetType();
799 UpdatePrs( prs ); // Update presentation by using of the double dispatch
805 //=================================================================
807 * GEOM_Displayer::internalReset
808 * Resets internal data
811 //=================================================================
812 void GEOM_Displayer::internalReset()
818 //=================================================================
820 * GEOM_Displayer::LocalSelection
821 * Activate selection of CAD shapes with activisation of selection
822 * of their sub-shapes (with opened local context for OCC viewer)
824 //=================================================================
825 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
827 SUIT_Session* session = SUIT_Session::session();
828 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
832 LightApp_SelectionMgr* sm = app->selectionMgr();
834 // remove all filters from selection
837 SALOME_View* vf = GetActiveView();
840 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
841 vf->LocalSelection( prs, theMode );
842 delete prs; // delete presentation because displayer is its owner
846 //=================================================================
848 * GEOM_Displayer::globalSelection
849 * Activate selection of CAD shapes without activisation of selection
850 * of their sub-shapes (without opened local context for OCC viewer)
852 //=================================================================
853 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
855 TColStd_MapOfInteger aModes;
856 aModes.Add( theMode );
857 GlobalSelection( aModes, update );
860 //=================================================================
862 * GEOM_Displayer::globalSelection
863 * Activate selection of CAD shapes without activisation of selection
864 * of their sub-shapes (without opened local context for OCC viewer)
866 //=================================================================
867 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
870 SUIT_Session* session = SUIT_Session::session();
871 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
875 SALOME_View* vf = GetActiveView();
879 // Close local context
880 vf->GlobalSelection( update );
882 // Set selection filters in accordance with current mode
883 LightApp_SelectionMgr* sm = app->selectionMgr();
887 // Remove from selection temporary objects if necessary
888 if ( !theModes.Contains( GEOM_PREVIEW ) )
889 clearTemporary( sm );
891 //@ aSel->ClearIndex();
895 // Remove filters from AIS_InteractiveContext
896 Handle(AIS_InteractiveContext) ic;
897 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
900 ic = viewer->getAISContext();
905 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
908 SUIT_SelectionFilter* aFilter;
909 if ( theModes.Extent() == 1 )
911 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
912 aFilter = getFilter( aMode );
914 else if ( theModes.Extent() > 1 )
916 TColStd_MapOfInteger aTopAbsModes;
917 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
918 QPtrList<SUIT_SelectionFilter> aListOfFilters;
919 for ( ; anIter.More(); anIter.Next() )
921 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
923 aListOfFilters.append( aFilter );
926 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
933 sm->installFilter( aFilter );
936 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
937 ic->AddFilter( anOCCFilter );
942 //=================================================================
944 * GEOM_Displayer::LocalSelection
945 * Activate selection of CAD shapes with activisation of selection
946 * of their sub-shapes (with opened local context for OCC viewer)
948 //=================================================================
949 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
951 SALOME_ListIteratorOfListIO Iter( theIOList );
952 for ( ; Iter.More(); Iter.Next() )
953 LocalSelection( Iter.Value(), theMode );
956 //=================================================================
958 * GEOM_Displayer::BeforeDisplay
959 * Called before displaying of pars. Close local context
960 * [ Reimplemented from SALOME_Displayer ]
962 //=================================================================
963 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
965 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
968 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
971 if ( ic->HasOpenedContext() )
972 ic->CloseAllContexts();
977 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
982 //=================================================================
984 * GEOM_Displayer::SetColor
985 * Set color for shape displaying. If it is equal -1 then default color is used.
986 * Available values are from Quantity_NameOfColor enumeration
988 //=================================================================
989 void GEOM_Displayer::SetColor( const int color )
994 int GEOM_Displayer::GetColor() const
999 bool GEOM_Displayer::HasColor() const
1001 return myColor != -1;
1004 void GEOM_Displayer::UnsetColor()
1009 //=================================================================
1011 * GEOM_Displayer::SetWidth
1012 * Set width of shape displaying. If it is equal -1 then default width is used.
1014 //=================================================================
1015 void GEOM_Displayer::SetWidth( const double width )
1020 double GEOM_Displayer::GetWidth() const
1025 bool GEOM_Displayer::HasWidth() const
1027 return myWidth != -1;
1030 void GEOM_Displayer::UnsetWidth()
1035 //=================================================================
1037 * GEOM_Displayer::SetToActivate
1038 * This method is used for activisation/deactivisation of objects to be displayed
1040 //=================================================================
1041 void GEOM_Displayer::SetToActivate( const bool toActivate )
1043 myToActivate = toActivate;
1045 bool GEOM_Displayer::ToActivate() const
1047 return myToActivate;
1050 //=================================================================
1052 * GEOM_Displayer::clearTemporary
1053 * Removes from selection temporary objects
1055 //=================================================================
1056 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1058 SALOME_ListIO selected, toSelect;
1059 theSelMgr->selectedObjects( selected );
1061 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1062 Handle(SALOME_InteractiveObject) io = it.Value();
1063 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1064 toSelect.Append( it.Value() );
1067 theSelMgr->setSelectedObjects( toSelect, true );