1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOM_Displayer.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "GEOM_Displayer.h"
28 #include "GeometryGUI.h"
30 #include <GEOM_TypeFilter.h>
31 #include <GEOM_EdgeFilter.h>
32 #include <GEOM_FaceFilter.h>
33 #include <GEOM_PreviewFilter.h>
34 #include <GEOM_LogicalFilter.h>
35 #include <GEOM_OCCFilter.h>
37 #include <GEOM_Actor.h>
38 #include <GEOM_AssemblyBuilder.h>
39 #include <GEOM_AISShape.hxx>
40 #include <GEOM_AISVector.hxx>
41 #include <GEOM_AISTrihedron.hxx>
42 #include <GEOM_VTKTrihedron.hxx>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ViewWindow.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_ResourceMgr.h>
50 #include <SalomeApp_Study.h>
51 #include <SalomeApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <SalomeApp_TypeFilter.h>
54 #include <SalomeApp_Tools.h>
56 #include <SALOME_ListIteratorOfListIO.hxx>
57 #include <SALOME_ListIO.hxx>
58 #include <SALOME_Prs.h>
61 #include <SOCC_ViewModel.h>
64 #include <SVTK_ViewModel.h>
67 #include <AIS_Drawer.hxx>
68 #include <AIS_ListIteratorOfListOfInteractive.hxx>
69 #include <Prs3d_IsoAspect.hxx>
70 #include <Prs3d_PointAspect.hxx>
71 #include <StdSelect_TypeOfEdge.hxx>
72 #include <StdSelect_TypeOfFace.hxx>
73 #include <TopoDS_Face.hxx>
74 #include <BRep_Tool.hxx>
75 #include <Geom_Plane.hxx>
76 #include <Geom_Axis2Placement.hxx>
78 #include <TColStd_MapOfInteger.hxx>
79 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
82 #include <vtkActorCollection.h>
83 #include <vtkProperty.h>
86 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
88 #include <GEOMImpl_Types.hxx>
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 string getEntry( GEOM::GEOM_Object_ptr object )
167 SUIT_Session* session = SUIT_Session::session();
168 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
171 CORBA::String_var IOR = app->orb()->object_to_string( object );
172 if ( strcmp(IOR.in(), "") != 0 )
174 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
175 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
183 //================================================================
184 // Function : getName
186 //================================================================
187 static string getName( GEOM::GEOM_Object_ptr object )
189 SUIT_Session* session = SUIT_Session::session();
190 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
193 CORBA::String_var IOR = app->orb()->object_to_string( object );
194 if ( strcmp(IOR.in(), "") != 0 )
196 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
197 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
199 _PTR(GenericAttribute) anAttr;
201 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
203 _PTR(AttributeName) aNameAttr( anAttr );
204 return aNameAttr->Value();
212 //=================================================================
214 * GEOM_Displayer::GEOM_Displayer
217 //=================================================================
218 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
221 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
226 SUIT_Session* session = SUIT_Session::session();
227 SUIT_ResourceMgr* resMgr = session->resourceMgr();
229 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
230 myShadingColor = SalomeApp_Tools::color( col );
232 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
233 myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
234 myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
235 if(myScaleOfMarker < 1.0)
236 myScaleOfMarker = 1.0;
237 if(myScaleOfMarker > 7.)
238 myScaleOfMarker = 7.;
242 // This color is used for shape displaying. If it is equal -1 then
243 // default color is used.
249 // This parameter is used for activisation/deactivisation of objects to be displayed
254 //=================================================================
256 * GEOM_Displayer::~GEOM_Displayer
259 //=================================================================
260 GEOM_Displayer::~GEOM_Displayer()
264 //=================================================================
266 * GEOM_Displayer::Display
267 * Display interactive object in the current viewer
269 //=================================================================
270 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
271 const bool updateViewer,
272 SALOME_View* theViewFrame )
274 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
277 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
281 vf->BeforeDisplay( this );
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(entry.c_str(), "GEOM", getName(theObj).c_str()),
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 SALOME_View* theViewFrame )
323 if ( theIO.IsNull() )
326 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
329 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
331 vf->Erase( prs, forced );
334 delete prs; // delete presentation because displayer is its owner
339 //=================================================================
341 * GEOM_Displayer::Erase
342 * Erase geometry object in the current viewer
344 //=================================================================
345 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
347 const bool updateViewer )
349 string entry = getEntry( theObj );
352 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
353 forced, updateViewer);
357 //=================================================================
359 * GEOM_Displayer::Redisplay
360 * Redisplay (erase and then display again) interactive object
361 * in the current viewer
363 //=================================================================
364 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
365 const bool updateViewer )
367 // Remove the object permanently (<forced> == true)
368 SUIT_Session* ses = SUIT_Session::session();
369 SUIT_Application* app = ses->activeApplication();
372 SUIT_Desktop* desk = app->desktop();
373 QList<SUIT_ViewWindow*> wnds = desk->windows();
374 SUIT_ViewWindow* wnd;
375 QListIterator<SUIT_ViewWindow*> it( wnds );
376 while ( it.hasNext() && (wnd = it.next()) )
378 SUIT_ViewManager* vman = wnd->getViewManager();
381 SUIT_ViewModel* vmodel = vman->getViewModel();
384 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
387 if ( view->isVisible( theIO ) || view == GetActiveView() )
389 Erase( theIO, true, false, view );
390 Display( theIO, updateViewer, view );
399 //=================================================================
401 * GEOM_Displayer::Display
402 * Calls Display() method for each object in the given list
404 //=================================================================
405 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
407 SALOME_ListIteratorOfListIO Iter( theIOList );
408 for ( ; Iter.More(); Iter.Next() ) {
409 Display( Iter.Value(), false );
415 //=================================================================
417 * GEOM_Displayer::Erase
418 * Calls Erase() method for each object in the given list
420 //=================================================================
421 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
423 const bool updateViewer )
425 SALOME_ListIteratorOfListIO Iter( theIOList );
426 for ( ; Iter.More(); Iter.Next() )
427 Erase( Iter.Value(), forced, false );
433 //=================================================================
435 * GEOM_Displayer::Redisplay
436 * Calls Redisplay() method for each object in the given list
438 //=================================================================
439 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
441 SALOME_ListIteratorOfListIO Iter( theIOList );
442 for ( ; Iter.More(); Iter.Next() )
443 Redisplay( Iter.Value(), false );
449 //=================================================================
451 * GEOM_Displayer::Update
452 * Update OCC presentaion
453 * [ Reimplemented from SALOME_Displayer ]
455 //=================================================================
456 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
458 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
462 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
464 TopoDS_Face aFace = TopoDS::Face( myShape );
465 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
466 if ( !aPlane.IsNull() )
468 gp_Ax3 aPos = aPlane->Pln().Position();
469 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
471 Handle(GEOM_AISTrihedron) aTrh;
473 if ( occPrs->IsNull() )
475 aTrh = new GEOM_AISTrihedron( aPlc );
478 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
481 aTrh->SetWidth( GetWidth() );
483 if ( !myIO.IsNull() )
486 aTrh->SetOwner( myIO );
489 occPrs->AddObject( aTrh );
493 AIS_ListOfInteractive aList;
494 occPrs->GetObjects( aList );
495 AIS_ListIteratorOfListOfInteractive anIter( aList );
496 for ( ; anIter.More(); anIter.Next() )
498 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
499 if ( !aTrh.IsNull() )
501 aTrh->SetComponent( aPlc );
507 occPrs->SetToActivate( ToActivate() );
512 // if presentation is empty we try to create new one
513 if ( occPrs->IsNull() )
515 if ( !myShape.IsNull() )
517 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
518 Handle(GEOM_AISShape) AISShape;
519 if (myType == GEOM_VECTOR)
520 AISShape = new GEOM_AISVector (myShape, "");
522 AISShape = new GEOM_AISShape (myShape, "");
523 // Temporary staff: vertex must be infinite for correct visualization
524 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
526 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
527 AISShape->SetDisplayMode( myDisplayMode );
528 AISShape->SetShadingColor( myShadingColor );
530 // Set color and number for iso lines
531 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
532 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
533 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
534 Quantity_Color aColor = SalomeApp_Tools::color( col );
535 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
536 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
538 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
539 anAspect->SetNumber( anUIsoNumber );
540 anAspect->SetColor( aColor );
541 AISShape->Attributes()->SetUIsoAspect( anAspect );
543 anAspect = AISShape->Attributes()->VIsoAspect();
544 anAspect->SetNumber( aVIsoNumber );
545 anAspect->SetColor( aColor );
546 AISShape->Attributes()->SetVIsoAspect( anAspect );
550 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
551 if ( myShape.ShapeType() == TopAbs_VERTEX )
553 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
554 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
555 anAspect->SetScale( myScaleOfMarker );
556 anAspect->SetTypeOfMarker( myTypeOfMarker );
557 AISShape->Attributes()->SetPointAspect( anAspect );
562 if ( myShape.ShapeType() == TopAbs_VERTEX )
564 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
565 aColor = SalomeApp_Tools::color( col );
567 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
568 anAspect->SetColor( aColor );
569 anAspect->SetScale( myScaleOfMarker );
570 anAspect->SetTypeOfMarker( myTypeOfMarker );
571 AISShape->Attributes()->SetPointAspect( anAspect );
576 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
577 aColor = SalomeApp_Tools::color( col );
579 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
580 anAspect->SetColor( aColor );
581 AISShape->Attributes()->SetLineAspect( anAspect );
583 // Set unfree boundaries aspect
584 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
585 anAspect->SetColor( aColor );
586 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
588 // Set free boundaries aspect
589 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
590 aColor = SalomeApp_Tools::color( col );
592 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
593 anAspect->SetColor( aColor );
594 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
597 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
598 aColor = SalomeApp_Tools::color( col );
600 anAspect = AISShape->Attributes()->WireAspect();
601 anAspect->SetColor( aColor );
602 AISShape->Attributes()->SetWireAspect( anAspect );
607 AISShape->SetWidth( GetWidth() );
609 if ( !myIO.IsNull() )
611 AISShape->setIO( myIO );
612 AISShape->SetOwner( myIO );
614 else if ( !myName.empty() )
616 // Workaround to allow selection of temporary objects
617 static int tempId = 0;
619 sprintf( buf, "TEMP_%d", tempId++ );
620 Handle( SALOME_InteractiveObject ) anObj =
621 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
622 AISShape->setIO( anObj );
623 AISShape->SetOwner( anObj );
625 // AISShape->SetName(???); ??? necessary to set name ???
626 occPrs->AddObject( AISShape );
628 // In accordance with ToActivate() value object will be activated/deactivated
629 // when it will be displayed
630 occPrs->SetToActivate( ToActivate() );
633 // if presentation is found -> set again shape for it
636 if ( !myShape.IsNull() )
638 AIS_ListOfInteractive IOList;
639 occPrs->GetObjects( IOList );
640 AIS_ListIteratorOfListOfInteractive Iter( IOList );
641 for ( ; Iter.More(); Iter.Next() )
643 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
644 if ( AISShape.IsNull() )
646 if ( AISShape->Shape() != myShape )
648 AISShape->Set( myShape );
649 AISShape->UpdateSelection();
650 AISShape->SetToUpdate();
652 if ( !myIO.IsNull() )
654 AISShape->setIO( myIO );
655 AISShape->SetOwner( myIO );
663 //=================================================================
665 * GEOM_Displayer::Update
666 * Update VTK presentaion
667 * [ Reimplemented from SALOME_Displayer ]
669 //=================================================================
670 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
672 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
673 if ( !vtkPrs || myShape.IsNull() )
676 vtkActorCollection* theActors = 0;
678 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
680 myToActivate = false;
681 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
685 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
686 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
689 Handle(Geom_Plane) aPlane =
690 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
691 if ( aPlane.IsNull() )
694 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
695 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
697 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
698 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
700 vtkPrs->AddObject( aTrh );
702 theActors = vtkActorCollection::New();
703 theActors->AddItem( aTrh );
707 bool isVector = (myType == GEOM_VECTOR);
708 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
711 theActors->InitTraversal();
713 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
715 vtkProperty* aProp = 0;
717 if ( HasColor() || HasWidth() )
719 aProp = vtkProperty::New();
720 aProp->SetRepresentationToWireframe();
725 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
726 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
731 aProp->SetLineWidth( GetWidth() );
734 while ( anActor != NULL )
736 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
738 GActor->setIO( myIO );
742 GActor->SetProperty( aProp );
743 GActor->SetPreviewProperty( aProp );
745 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
746 if ( aGeomGActor != 0 )
748 aGeomGActor->SetShadingProperty( aProp );
749 aGeomGActor->SetWireframeProperty( aProp );
754 GActor->PickableOn();
756 GActor->PickableOff();
758 vtkPrs->AddObject( GActor );
760 anActor = (vtkActor*)theActors->GetNextActor();
769 //=================================================================
771 * GEOM_Displayer::BuildPrs
772 * Build presentation accordint to the current viewer type
774 //=================================================================
775 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
777 if ( theObj->_is_nil() )
780 myViewFrame = GetActiveView();
781 if ( myViewFrame == 0 )
784 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
789 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
790 myType = theObj->GetType();
792 // Update presentation
798 //=================================================================
800 * GEOM_Displayer::BuildPrs
801 * Build presentation accordint to the current viewer type
803 //=================================================================
804 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
806 myViewFrame = GetActiveView();
807 if ( theShape.IsNull() || myViewFrame == 0 )
810 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
815 setShape( theShape );
823 //=================================================================
825 * GEOM_Displayer::buildPresentation
826 * Builds/finds object's presentation for the current viewer
827 * Calls corresponding Update() method by means of double dispatch
830 //=================================================================
831 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
832 SALOME_View* theViewFrame )
837 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
841 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
844 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
845 theIO->setEntry( entry.toLatin1() );
846 if ( !theIO.IsNull() )
848 // set interactive object
850 // Find SOBject (because shape should be published previously)
851 SUIT_Session* session = SUIT_Session::session();
852 SUIT_Application* app = session->activeApplication();
855 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
858 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
861 // get CORBA reference to data object
862 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
863 if ( !CORBA::is_nil( object ) )
865 // downcast to GEOM object
866 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
867 if ( !GeomObject->_is_nil() )
870 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
871 myType = GeomObject->GetType();
878 UpdatePrs( prs ); // Update presentation by using of the double dispatch
884 //=================================================================
886 * GEOM_Displayer::internalReset
887 * Resets internal data
890 //=================================================================
891 void GEOM_Displayer::internalReset()
897 //=================================================================
899 * GEOM_Displayer::LocalSelection
900 * Activate selection of CAD shapes with activisation of selection
901 * of their sub-shapes (with opened local context for OCC viewer)
903 //=================================================================
904 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
906 SUIT_Session* session = SUIT_Session::session();
907 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
911 LightApp_SelectionMgr* sm = app->selectionMgr();
913 // remove all filters from selection
916 SALOME_View* vf = GetActiveView();
918 if (!theIO.IsNull() && !vf->isVisible(theIO))
920 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
921 vf->LocalSelection( prs, theMode );
922 delete prs; // delete presentation because displayer is its owner
926 //=================================================================
928 * GEOM_Displayer::globalSelection
929 * Activate selection of CAD shapes without activisation of selection
930 * of their sub-shapes (without opened local context for OCC viewer)
932 //=================================================================
933 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
935 TColStd_MapOfInteger aModes;
936 aModes.Add( theMode );
937 GlobalSelection( aModes, update );
940 //=================================================================
942 * GEOM_Displayer::globalSelection
943 * Activate selection of CAD shapes without activisation of selection
944 * of their sub-shapes (without opened local context for OCC viewer)
946 //=================================================================
947 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
950 SUIT_Session* session = SUIT_Session::session();
951 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
955 SALOME_View* vf = GetActiveView();
959 // Close local context
960 vf->GlobalSelection( update );
962 // Set selection filters in accordance with current mode
963 LightApp_SelectionMgr* sm = app->selectionMgr();
967 // Remove from selection temporary objects if necessary
968 if ( !theModes.Contains( GEOM_PREVIEW ) )
969 clearTemporary( sm );
971 //@ aSel->ClearIndex();
975 // Remove filters from AIS_InteractiveContext
976 Handle(AIS_InteractiveContext) ic;
977 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
980 ic = viewer->getAISContext();
985 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
988 SUIT_SelectionFilter* aFilter;
989 if ( theModes.Extent() == 1 )
991 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
992 aFilter = getFilter( aMode );
994 else if ( theModes.Extent() > 1 )
996 TColStd_MapOfInteger aTopAbsModes;
997 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
998 QList<SUIT_SelectionFilter*> aListOfFilters;
999 for ( ; anIter.More(); anIter.Next() )
1001 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
1003 aListOfFilters.append( aFilter );
1006 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1013 sm->installFilter( aFilter );
1016 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1017 ic->AddFilter( anOCCFilter );
1022 //=================================================================
1024 * GEOM_Displayer::LocalSelection
1025 * Activate selection of CAD shapes with activisation of selection
1026 * of their sub-shapes (with opened local context for OCC viewer)
1028 //=================================================================
1029 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1031 SALOME_ListIteratorOfListIO Iter( theIOList );
1032 for ( ; Iter.More(); Iter.Next() )
1033 LocalSelection( Iter.Value(), theMode );
1036 //=================================================================
1038 * GEOM_Displayer::BeforeDisplay
1039 * Called before displaying of pars. Close local context
1040 * [ Reimplemented from SALOME_Displayer ]
1042 //=================================================================
1043 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1045 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1048 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1051 if ( ic->HasOpenedContext() )
1052 ic->CloseAllContexts();
1057 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1062 //=================================================================
1064 * GEOM_Displayer::SetColor
1065 * Set color for shape displaying. If it is equal -1 then default color is used.
1066 * Available values are from Quantity_NameOfColor enumeration
1068 //=================================================================
1069 void GEOM_Displayer::SetColor( const int color )
1076 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1080 int GEOM_Displayer::GetColor() const
1085 bool GEOM_Displayer::HasColor() const
1087 return myColor != -1;
1090 void GEOM_Displayer::UnsetColor()
1094 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1095 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1096 myShadingColor = SalomeApp_Tools::color( col );
1099 //=================================================================
1101 * GEOM_Displayer::SetWidth
1102 * Set width of shape displaying. If it is equal -1 then default width is used.
1104 //=================================================================
1105 void GEOM_Displayer::SetWidth( const double width )
1110 double GEOM_Displayer::GetWidth() const
1115 bool GEOM_Displayer::HasWidth() const
1117 return myWidth != -1;
1120 void GEOM_Displayer::UnsetWidth()
1125 //=================================================================
1127 * GEOM_Displayer::SetToActivate
1128 * This method is used for activisation/deactivisation of objects to be displayed
1130 //=================================================================
1131 void GEOM_Displayer::SetToActivate( const bool toActivate )
1133 myToActivate = toActivate;
1135 bool GEOM_Displayer::ToActivate() const
1137 return myToActivate;
1140 //=================================================================
1142 * GEOM_Displayer::clearTemporary
1143 * Removes from selection temporary objects
1145 //=================================================================
1146 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1148 SALOME_ListIO selected, toSelect;
1149 theSelMgr->selectedObjects( selected );
1151 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1152 Handle(SALOME_InteractiveObject) io = it.Value();
1153 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1154 toSelect.Append( it.Value() );
1157 theSelMgr->setSelectedObjects( toSelect, true );
1160 void GEOM_Displayer::SetName( const char* theName )
1165 void GEOM_Displayer::UnsetName()
1170 SalomeApp_Study* GEOM_Displayer::getStudy() const
1172 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1175 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1180 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1185 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1187 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1190 int GEOM_Displayer::SetDisplayMode( const int theMode )
1192 int aPrevMode = myDisplayMode;
1193 if ( theMode != -1 )
1194 myDisplayMode = theMode;
1197 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1198 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1203 int GEOM_Displayer::GetDisplayMode() const
1205 return myDisplayMode;
1208 int GEOM_Displayer::UnsetDisplayMode()
1210 int aPrevMode = myDisplayMode;
1211 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1212 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );