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"
30 #include "GEOM_ShapeTypeFilter.hxx"
31 #include "GEOM_TypeFilter.hxx"
32 #include "QAD_Desktop.h"
33 #include "QAD_Application.h"
34 #include "QAD_Study.h"
35 #include "QAD_StudyFrame.h"
36 #include "QAD_RightFrame.h"
37 #include "QAD_ViewFrame.h"
38 #include "QAD_Config.h"
39 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "OCCViewer_Prs.h"
41 #include "OCCViewer_ViewFrame.h"
42 #include "OCCViewer_Viewer3d.h"
43 #include "VTKViewer_Prs.h"
44 #include "VTKViewer_ViewFrame.h"
45 #include "GEOMImpl_Types.hxx"
46 #include "TColStd_MapOfInteger.hxx"
47 #include "TColStd_MapIteratorOfMapOfInteger.hxx"
48 #include "GEOM_EdgeFilter.hxx"
49 #include "GEOM_FaceFilter.hxx"
50 #include "GEOM_PreviewFilter.hxx"
51 #include "GEOM_LogicalFilter.hxx"
52 #include "GEOM_AssemblyBuilder.h"
53 #include "GEOM_Actor.h"
54 #include "GEOM_AISTrihedron.hxx"
55 #include "GEOM_VTKTrihedron.hxx"
57 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
59 #include "GeometryGUI.h"
60 #include "GEOM_AISShape.hxx"
61 #include <AIS_ListIteratorOfListOfInteractive.hxx>
62 #include <AIS_Drawer.hxx>
63 #include <Prs3d_PointAspect.hxx>
64 #include <Graphic3d_AspectMarker3d.hxx>
65 #include <Geom_Plane.hxx>
66 #include <TopoDS_Face.hxx>
67 #include <BRep_Tool.hxx>
69 #include <Geom_Axis2Placement.hxx>
71 #include <vtkActorCollection.h>
77 //================================================================
78 // Function : getActiveStudy
79 // Purpose : Get active study, returns 0 if no open study frame
80 //================================================================
81 static inline QAD_Study* getActiveStudy()
83 QAD_Desktop* desktop = QAD_Application::getDesktop();
85 QAD_Application* app = desktop->getActiveApp();
87 return app->getActiveStudy();
92 //================================================================
93 // Function : getTopAbsMode
94 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
95 // one from GEOMImpl_Types.h
96 //================================================================
97 static inline int getTopAbsMode( const int implType )
101 case GEOM_COMPOUND : return TopAbs_COMPOUND;
102 case GEOM_SOLID : return TopAbs_SOLID;
103 case GEOM_SHELL : return TopAbs_SHELL;
104 case GEOM_FACE : return TopAbs_FACE;
105 case GEOM_WIRE : return TopAbs_WIRE;
106 case GEOM_EDGE : return TopAbs_EDGE;
107 case GEOM_POINT : return TopAbs_VERTEX;
112 //================================================================
113 // Function : getTopAbsMode
114 // Purpose : Get filter corresponding to the type of object
115 // from GEOMImpl_Types.h
116 //================================================================
117 static inline Handle(SALOME_Filter) getFilter( const int theMode )
119 Handle(SALOME_Filter) aFilter;
121 int aTopAbsMode = getTopAbsMode( theMode );
122 if ( aTopAbsMode != -1 )
123 aFilter = new GEOM_ShapeTypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
127 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( StdSelect_Line ); break;
128 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( StdSelect_Circle ); break;
130 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( StdSelect_Plane ); break;
131 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( StdSelect_Cylinder ); break;
132 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( StdSelect_Sphere ); break;
133 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( StdSelect_Torus ); break;
134 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( StdSelect_Revol ); break;
135 case GEOM_CONE : aFilter = new GEOM_FaceFilter( StdSelect_Cone ); break;
137 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter(); break;
139 case GEOM_ALLSHAPES : aFilter = new GEOM_ShapeTypeFilter( -1, true ); break;
140 case GEOM_ALLGEOM : aFilter = new SALOME_TypeFilter( "GEOM" ); break;
142 default : aFilter = new GEOM_TypeFilter( theMode ); break;
148 //================================================================
149 // Function : getEntry
151 //================================================================
152 static char* getEntry( GEOM::GEOM_Object_ptr object )
154 QAD_Study* study = getActiveStudy();
156 string IOR = GeometryGUI::GetORB()->object_to_string( object );
158 SALOMEDS::SObject_var SO = study->getStudyDocument()->FindObjectIOR( IOR.c_str() );
159 if ( !SO->_is_nil() ) {
167 //================================================================
168 // Function : getName
170 //================================================================
171 static const char* getName( GEOM::GEOM_Object_ptr theObj )
173 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
177 string anIOR = GeometryGUI::GetORB()->object_to_string( theObj );
180 SALOMEDS::SObject_var aSObj = aStudy->getStudyDocument()->FindObjectIOR( anIOR.c_str() );
181 SALOMEDS::GenericAttribute_var anAttr;
183 if ( !aSObj->_is_nil() && aSObj->FindAttribute( anAttr, "AttributeName") )
185 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
186 return aNameAttr->Value();
194 //=================================================================
196 * GEOM_Displayer::GEOM_Displayer
199 //=================================================================
200 GEOM_Displayer::GEOM_Displayer()
203 QString SCr = QAD_CONFIG->getSetting( "Geometry:SettingsShadingColorRed" );
204 QString SCg = QAD_CONFIG->getSetting( "Geometry:SettingsShadingColorGreen" );
205 QString SCb = QAD_CONFIG->getSetting( "Geometry:SettingsShadingColorBlue" );
206 if ( !SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty() )
207 myShadingColor = Quantity_Color(
208 SCr.toInt()/255., SCg.toInt()/255., SCb.toInt()/255., Quantity_TOC_RGB );
210 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
213 // This color is used for shape displaying. If it is equal -1 then
214 // default color is used.
220 // This parameter is used for activisation/deactivisation of objects to be displayed
225 //=================================================================
227 * GEOM_Displayer::~GEOM_Displayer
230 //=================================================================
231 GEOM_Displayer::~GEOM_Displayer()
235 //=================================================================
238 * Get active study frame, returns 0 if no open study frame
240 //=================================================================
241 QAD_ViewFrame* GEOM_Displayer::GetActiveView()
243 QAD_Study* activeStudy = getActiveStudy();
246 QAD_StudyFrame* sf = activeStudy->getActiveStudyFrame();
249 return sf->getRightFrame()->getViewFrame();
255 //=================================================================
257 * GEOM_Displayer::Display
258 * Display interactive object in the current viewer
260 //=================================================================
261 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, const bool updateViewer,
262 QAD_ViewFrame* theViewFrame )
264 QAD_ViewFrame* vf = theViewFrame;
266 vf = GetActiveView();
270 if ( vf->inherits( "VTKViewer_ViewFrame" ) )
272 SALOME_Prs* prs = vf->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 );
273 ((SALOME_View*)vf)->Erase( prs, true );
277 SALOME_Prs* prs = buildPresentation( theIO, vf );
281 vf->BeforeDisplay( this );
282 ((SALOME_View*)vf)->Display( prs );
283 vf->AfterDisplay( this );
288 delete prs; // delete presentation because displayer is its owner
293 //=================================================================
295 * GEOM_Displayer::Display
296 * This overloaded Display() method can be useful for operations
297 * not using dialog boxes.
299 //=================================================================
300 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
302 if ( theObj->_is_nil() )
305 string entry = getEntry( theObj );
307 Display( new SALOME_InteractiveObject(
308 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer );
312 //=================================================================
314 * GEOM_Displayer::Erase
315 * Erase interactive object in the current viewer
317 //=================================================================
318 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
320 const bool updateViewer,
321 QAD_ViewFrame* theViewFrame )
323 if ( theIO.IsNull() )
326 QAD_ViewFrame* vf = theViewFrame;
328 vf = GetActiveView();
331 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
333 ((SALOME_View*)vf)->Erase( prs, forced );
336 delete prs; // delete presentation because displayer is its owner
341 //=================================================================
343 * GEOM_Displayer::Erase
344 * Erase geometry object in the current viewer
346 //=================================================================
347 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
349 const bool updateViewer )
351 string entry = getEntry( theObj );
354 Erase( new SALOME_InteractiveObject(
355 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer );
359 //=================================================================
361 * GEOM_Displayer::Redisplay
362 * Redisplay (erase and then display again) interactive object
363 * in the current viewer
365 //=================================================================
366 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
367 const bool updateViewer )
369 // Remove the object permanently (<forced> == true)
371 QAD_Study* activeStudy = getActiveStudy();
375 int aNbFrames = activeStudy->getStudyFramesCount();
376 for (int i = 0; i < aNbFrames; i++)
378 QAD_StudyFrame* sf = activeStudy->getStudyFrame(i);
382 QAD_ViewFrame* vf = sf->getRightFrame()->getViewFrame();
386 if ( vf->isVisible(theIO) || vf == GetActiveView() )
388 Erase( theIO, true, false, vf );
389 Display( theIO, updateViewer, vf );
394 //=================================================================
396 * GEOM_Displayer::Display
397 * Calls Display() method for each object in the given list
399 //=================================================================
400 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
402 SALOME_ListIteratorOfListIO Iter( theIOList );
403 for ( ; Iter.More(); Iter.Next() ) {
404 Display( Iter.Value(), false );
410 //=================================================================
412 * GEOM_Displayer::Erase
413 * Calls Erase() method for each object in the given list
415 //=================================================================
416 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
418 const bool updateViewer )
420 SALOME_ListIteratorOfListIO Iter( theIOList );
421 for ( ; Iter.More(); Iter.Next() )
422 Erase( Iter.Value(), forced, false );
428 //=================================================================
430 * GEOM_Displayer::Redisplay
431 * Calls Redisplay() method for each object in the given list
433 //=================================================================
434 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
436 SALOME_ListIteratorOfListIO Iter( theIOList );
437 for ( ; Iter.More(); Iter.Next() ) {
438 Redisplay( Iter.Value(), false );
444 //=================================================================
446 * GEOM_Displayer::UpdateViewer
447 * Update current viewer
449 //=================================================================
450 void GEOM_Displayer::UpdateViewer()
452 QAD_ViewFrame* vf = GetActiveView();
457 //=================================================================
459 * GEOM_Displayer::Update
460 * Update OCC presentaion
461 * [ Reimplemented from SALOME_Displayer ]
463 //=================================================================
464 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
466 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
470 OCCViewer_ViewFrame* vf = dynamic_cast<OCCViewer_ViewFrame*>( myViewFrame );
474 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
476 TopoDS_Face aFace = TopoDS::Face( myShape );
477 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
478 if ( !aPlane.IsNull() )
480 gp_Ax3 aPos = aPlane->Pln().Position();
481 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
483 Handle(GEOM_AISTrihedron) aTrh;
485 if ( occPrs->IsNull() )
487 aTrh = new GEOM_AISTrihedron( aPlc );
490 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
493 aTrh->SetWidth( GetWidth() );
495 if ( !myIO.IsNull() )
498 aTrh->SetOwner( myIO );
501 occPrs->AddObject( aTrh );
505 AIS_ListOfInteractive aList;
506 occPrs->GetObjects( aList );
507 AIS_ListIteratorOfListOfInteractive anIter( aList );
508 for ( ; anIter.More(); anIter.Next() )
510 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
511 if ( !aTrh.IsNull() )
513 aTrh->SetComponent( aPlc );
519 occPrs->SetToActivate( ToActivate() );
524 // if presentation is empty we try to create new one
525 if ( occPrs->IsNull() )
527 if ( !myShape.IsNull() )
529 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
530 // Temporary staff: vertex must be infinite for correct visualization
531 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
533 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
534 AISShape->SetShadingColor( myShadingColor );
537 if ( myShape.ShapeType() == TopAbs_VERTEX )
539 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
540 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
541 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
542 AISShape->Attributes()->SetPointAspect( anAspect );
545 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
549 AISShape->SetWidth( GetWidth() );
551 if ( !myIO.IsNull() )
553 AISShape->setIO( myIO );
554 AISShape->SetOwner( myIO );
556 else if ( !myName.empty() )
558 // Workaround to allow selection of temporary objects
559 static int tempId = 0;
561 sprintf( buf, "TEMP_%d", tempId++ );
562 Handle( SALOME_InteractiveObject ) anObj =
563 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
564 AISShape->setIO( anObj );
565 AISShape->SetOwner( anObj );
567 // AISShape->SetName(???); ??? necessary to set name ???
568 occPrs->AddObject( AISShape );
570 // In accordance with ToActivate() value object will be activated/deactivated
571 // when it will be displayed
572 occPrs->SetToActivate( ToActivate() );
575 // if presentation is found -> set again shape for it
578 if ( !myShape.IsNull() )
580 AIS_ListOfInteractive IOList;
581 occPrs->GetObjects( IOList );
582 AIS_ListIteratorOfListOfInteractive Iter( IOList );
583 for ( ; Iter.More(); Iter.Next() )
585 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
586 if ( AISShape.IsNull() )
588 if ( AISShape->Shape() != myShape )
590 AISShape->Set( myShape );
591 AISShape->UpdateSelection();
592 AISShape->SetToUpdate();
594 if ( !myIO.IsNull() )
596 AISShape->setIO( myIO );
597 AISShape->SetOwner( myIO );
605 //=================================================================
607 * GEOM_Displayer::Update
608 * Update VTK presentaion
609 * [ Reimplemented from SALOME_Displayer ]
611 //=================================================================
612 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
614 VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( prs );
615 if ( !vtkPrs || myShape.IsNull() )
618 vtkActorCollection* theActors = 0;
620 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
622 myToActivate = false;
623 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
627 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
628 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
631 Handle(Geom_Plane) aPlane =
632 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
633 if ( aPlane.IsNull() )
636 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
637 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
639 if ( VTKViewer_ViewFrame* vf = dynamic_cast<VTKViewer_ViewFrame*>( GetActiveView() ) )
640 aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
642 vtkPrs->AddObject( aTrh );
644 theActors = vtkActorCollection::New();
645 theActors->AddItem( aTrh );
648 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
650 theActors->InitTraversal();
652 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
654 vtkProperty* aProp = 0;
656 if ( HasColor() || HasWidth() )
658 aProp = vtkProperty::New();
659 aProp->SetRepresentationToWireframe();
664 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
665 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
670 aProp->SetLineWidth( GetWidth() );
673 while ( anActor != NULL )
675 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
677 GActor->setIO( myIO );
681 GActor->SetProperty( aProp );
682 GActor->SetPreviewProperty( aProp );
684 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
685 if ( aGeomGActor != 0 )
687 aGeomGActor->SetShadingProperty( aProp );
688 aGeomGActor->SetWireframeProperty( aProp );
693 GActor->PickableOn();
695 GActor->PickableOff();
697 vtkPrs->AddObject( GActor );
699 anActor = (vtkActor*)theActors->GetNextActor();
708 //=================================================================
710 * GEOM_Displayer::BuildPrs
711 * Build presentation accordint to the current viewer type
713 //=================================================================
714 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
716 if ( theObj->_is_nil() )
719 GeometryGUI* geomGUI = GeometryGUI::GetGeomGUI();
721 myViewFrame = GetActiveView();
722 if ( myViewFrame == 0 )
725 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
730 setShape( geomGUI->GetShapeReader().GetShape( geomGUI->GetGeomGen(), theObj ) );
731 myType = theObj->GetType();
733 // Update presentation
739 //=================================================================
741 * GEOM_Displayer::BuildPrs
742 * Build presentation accordint to the current viewer type
744 //=================================================================
745 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
747 myViewFrame = GetActiveView();
748 if ( theShape.IsNull() || myViewFrame == 0 )
751 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
756 setShape( theShape );
764 //=================================================================
766 * GEOM_Displayer::buildPresentation
767 * Builds/finds object's presentation for the current viewer
768 * Calls corresponding Update() method by means of double dispatch
771 //=================================================================
772 SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveObject)& theIO,
773 QAD_ViewFrame* theViewFrame )
778 GeometryGUI* geomGUI = GeometryGUI::GetGeomGUI();
780 myViewFrame = theViewFrame; // no dynamic_cast here to use double dispatch
782 myViewFrame = GetActiveView();
785 prs = myViewFrame->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 );
787 if ( !theIO.IsNull() ) {
788 // set interactive object
790 // Find SOBject (because shape should be published previously)
791 SALOMEDS::SObject_var SO = getActiveStudy()->getStudyDocument()->FindObjectID( theIO->getEntry() );
792 if ( !SO->_is_nil() ) {
793 // get CORBA reference to data object
794 CORBA::Object_var object = SO->GetObject();
795 if ( !CORBA::is_nil( object ) ) {
796 // downcast to GEOM object
797 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
798 if ( !GeomObject->_is_nil() ) {
800 setShape( geomGUI->GetShapeReader().GetShape( geomGUI->GetGeomGen(), GeomObject ) );
801 myType = GeomObject->GetType();
806 UpdatePrs( prs ); // Update presentation by using of the double dispatch
812 //=================================================================
814 * GEOM_Displayer::internalReset
815 * Resets internal data
818 //=================================================================
819 void GEOM_Displayer::internalReset()
825 //=================================================================
827 * GEOM_Displayer::LocalSelection
828 * Activate selection of CAD shapes with activisation of selection
829 * of their sub-shapes (with opened local context for OCC viewer)
831 //=================================================================
832 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
834 // remove all filters from selection
835 SALOME_Selection* aSel = SALOME_Selection::Selection(
836 QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
838 aSel->ClearFilters();
840 QAD_ViewFrame* vf = GetActiveView();
843 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
844 ((SALOME_View*)vf)->LocalSelection( prs, theMode );
845 delete prs; // delete presentation because displayer is its owner
849 //=================================================================
851 * GEOM_Displayer::globalSelection
852 * Activate selection of CAD shapes without activisation of selection
853 * of their sub-shapes (without opened local context for OCC viewer)
855 //=================================================================
856 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
858 TColStd_MapOfInteger aModes;
859 aModes.Add( theMode );
860 GlobalSelection( aModes, update );
863 //=================================================================
865 * GEOM_Displayer::globalSelection
866 * Activate selection of CAD shapes without activisation of selection
867 * of their sub-shapes (without opened local context for OCC viewer)
869 //=================================================================
870 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
873 QAD_ViewFrame* vf = GetActiveView();
877 // Close local context
878 vf->GlobalSelection( update );
880 // Set selection filters in accordance with current mode
881 SALOME_Selection* aSel = SALOME_Selection::Selection(
882 QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
884 // Remove from selection temporary objects if necessary
885 if ( !theModes.Contains( GEOM_PREVIEW ) )
886 clearTemporary( aSel );
890 aSel->ClearFilters();
892 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
895 Handle(SALOME_Filter) aFilter;
896 if ( theModes.Extent() == 1 )
898 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
899 aFilter = getFilter( aMode );
901 else if ( theModes.Extent() > 1 )
903 TColStd_MapOfInteger aTopAbsModes;
904 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
905 GEOM_ListOfFilter aListOfFilters;
906 for ( ; anIter.More(); anIter.Next() )
908 Handle(SALOME_Filter) aFilter = getFilter( anIter.Key() );
909 if ( !aFilter.IsNull() )
910 aListOfFilters.Append( aFilter );
913 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
918 if ( !aFilter.IsNull() )
919 aSel->AddFilter( aFilter );
922 //=================================================================
924 * GEOM_Displayer::LocalSelection
925 * Activate selection of CAD shapes with activisation of selection
926 * of their sub-shapes (with opened local context for OCC viewer)
928 //=================================================================
929 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
931 SALOME_ListIteratorOfListIO Iter( theIOList );
932 for ( ; Iter.More(); Iter.Next() )
933 LocalSelection( Iter.Value(), theMode );
936 //=================================================================
938 * GEOM_Displayer::BeforeDisplay
939 * Called before displaying of pars. Close local context
940 * [ Reimplemented from SALOME_Displayer ]
942 //=================================================================
943 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
945 OCCViewer_ViewFrame* vf = dynamic_cast<OCCViewer_ViewFrame*>( v );
948 Handle(AIS_InteractiveContext) ic = vf->getViewer()->getAISContext();
951 if ( ic->HasOpenedContext() )
952 ic->CloseAllContexts();
957 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
962 //=================================================================
964 * GEOM_Displayer::SetColor
965 * Set color for shape displaying. If it is equal -1 then default color is used.
966 * Available values are from Quantity_NameOfColor enumeration
968 //=================================================================
969 void GEOM_Displayer::SetColor( const int color )
974 int GEOM_Displayer::GetColor() const
979 bool GEOM_Displayer::HasColor() const
981 return myColor != -1;
984 void GEOM_Displayer::UnsetColor()
989 //=================================================================
991 * GEOM_Displayer::SetWidth
992 * Set width of shape displaying. If it is equal -1 then default width is used.
994 //=================================================================
995 void GEOM_Displayer::SetWidth( const double width )
1000 double GEOM_Displayer::GetWidth() const
1005 bool GEOM_Displayer::HasWidth() const
1007 return myWidth != -1;
1010 void GEOM_Displayer::UnsetWidth()
1015 //=================================================================
1017 * GEOM_Displayer::SetToActivate
1018 * This method is used for activisation/deactivisation of objects to be displayed
1020 //=================================================================
1021 void GEOM_Displayer::SetToActivate( const bool toActivate )
1023 myToActivate = toActivate;
1025 bool GEOM_Displayer::ToActivate() const
1027 return myToActivate;
1030 //=================================================================
1032 * GEOM_Displayer::clearTemporary
1033 * Removes from selection temporary objects
1035 //=================================================================
1036 void GEOM_Displayer::clearTemporary( SALOME_Selection* theSel )
1038 SALOME_ListIO toBeRemoved;
1039 SALOME_ListIteratorOfListIO anIter( theSel->StoredIObjects() );
1040 for ( ; anIter.More(); anIter.Next() )
1042 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
1043 if ( anIO->hasEntry() && ( strncmp( anIO->getEntry(), "TEMP_", 5 ) == 0 ) )
1044 toBeRemoved.Append( anIO );
1047 SALOME_ListIteratorOfListIO anIter2( toBeRemoved );
1048 for ( ; anIter2.More(); anIter2.Next() )
1049 theSel->RemoveIObject( anIter2.Value(), false );