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
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_AISVector.hxx"
44 #include "GEOM_AISTrihedron.hxx"
45 #include "GEOM_VTKTrihedron.hxx"
47 #include <SUIT_Desktop.h>
48 #include <SUIT_ViewWindow.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_ViewManager.h>
51 #include <SUIT_ResourceMgr.h>
53 #include <SalomeApp_Study.h>
54 #include <SalomeApp_Application.h>
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_TypeFilter.h>
57 #include <SalomeApp_Tools.h>
59 #include <SALOME_ListIteratorOfListIO.hxx>
60 #include <SALOME_ListIO.hxx>
61 #include <SALOME_Prs.h>
64 #include <SOCC_ViewModel.h>
67 #include <SVTK_ViewModel.h>
70 #include <AIS_Drawer.hxx>
71 #include <AIS_ListIteratorOfListOfInteractive.hxx>
72 #include <Prs3d_IsoAspect.hxx>
73 #include <Prs3d_PointAspect.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>
86 #include <vtkProperty.h>
89 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
91 #include "GEOMImpl_Types.hxx"
95 //================================================================
96 // Function : getActiveStudy
97 // Purpose : Get active study, returns 0 if no open study frame
98 //================================================================
99 static inline SalomeApp_Study* getActiveStudy()
101 SUIT_Session* session = SUIT_Session::session();
102 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
104 return ( SalomeApp_Study* )app->activeStudy();
108 //================================================================
109 // Function : getTopAbsMode
110 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
111 // one from GEOMImpl_Types.h
112 //================================================================
113 static inline int getTopAbsMode( const int implType )
117 case GEOM_COMPOUND : return TopAbs_COMPOUND;
118 case GEOM_SOLID : return TopAbs_SOLID;
119 case GEOM_SHELL : return TopAbs_SHELL;
120 case GEOM_FACE : return TopAbs_FACE;
121 case GEOM_WIRE : return TopAbs_WIRE;
122 case GEOM_EDGE : return TopAbs_EDGE;
123 case GEOM_POINT : return TopAbs_VERTEX;
128 //================================================================
129 // Function : getFilter
130 // Purpose : Get filter corresponding to the type of object
131 // from GEOMImpl_Types.h
132 //================================================================
133 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
135 SUIT_SelectionFilter* aFilter;
137 int aTopAbsMode = getTopAbsMode( theMode );
138 if ( aTopAbsMode != -1 )
139 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
143 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
144 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
146 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
147 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
148 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
149 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
150 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
151 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
153 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
155 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
156 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
158 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
164 //================================================================
165 // Function : getEntry
167 //================================================================
168 static string getEntry( GEOM::GEOM_Object_ptr object )
170 SUIT_Session* session = SUIT_Session::session();
171 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
174 CORBA::String_var IOR = app->orb()->object_to_string( object );
175 if ( strcmp(IOR.in(), "") != 0 )
177 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
178 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
186 //================================================================
187 // Function : getName
189 //================================================================
190 static string getName( GEOM::GEOM_Object_ptr object )
192 SUIT_Session* session = SUIT_Session::session();
193 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
196 CORBA::String_var IOR = app->orb()->object_to_string( object );
197 if ( strcmp(IOR.in(), "") != 0 )
199 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
200 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
202 _PTR(GenericAttribute) anAttr;
204 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
206 _PTR(AttributeName) aNameAttr( anAttr );
207 return aNameAttr->Value();
215 //=================================================================
217 * GEOM_Displayer::GEOM_Displayer
220 //=================================================================
221 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
224 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
229 SUIT_Session* session = SUIT_Session::session();
230 SUIT_ResourceMgr* resMgr = session->resourceMgr();
232 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
233 myShadingColor = SalomeApp_Tools::color( col );
235 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
236 myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
237 myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
238 if(myScaleOfMarker < 1.0)
239 myScaleOfMarker = 1.0;
240 if(myScaleOfMarker > 7.)
241 myScaleOfMarker = 7.;
245 // This color is used for shape displaying. If it is equal -1 then
246 // default color is used.
252 // This parameter is used for activisation/deactivisation of objects to be displayed
257 //=================================================================
259 * GEOM_Displayer::~GEOM_Displayer
262 //=================================================================
263 GEOM_Displayer::~GEOM_Displayer()
267 //=================================================================
269 * GEOM_Displayer::Display
270 * Display interactive object in the current viewer
272 //=================================================================
273 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
274 const bool updateViewer,
275 SALOME_View* theViewFrame )
277 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
280 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
284 vf->BeforeDisplay( this );
286 vf->AfterDisplay( this );
291 delete prs; // delete presentation because displayer is its owner
296 //=================================================================
298 * GEOM_Displayer::Display
299 * This overloaded Display() method can be useful for operations
300 * not using dialog boxes.
302 //=================================================================
303 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
305 if ( theObj->_is_nil() )
308 string entry = getEntry( theObj );
310 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
315 //=================================================================
317 * GEOM_Displayer::Erase
318 * Erase interactive object in the current viewer
320 //=================================================================
321 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
323 const bool updateViewer,
324 SALOME_View* theViewFrame )
326 if ( theIO.IsNull() )
329 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
332 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
334 vf->Erase( prs, forced );
337 delete prs; // delete presentation because displayer is its owner
342 //=================================================================
344 * GEOM_Displayer::Erase
345 * Erase geometry object in the current viewer
347 //=================================================================
348 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
350 const bool updateViewer )
352 string entry = getEntry( theObj );
355 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
356 forced, updateViewer);
360 //=================================================================
362 * GEOM_Displayer::Redisplay
363 * Redisplay (erase and then display again) interactive object
364 * in the current viewer
366 //=================================================================
367 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
368 const bool updateViewer )
370 // Remove the object permanently (<forced> == true)
371 SUIT_Session* ses = SUIT_Session::session();
372 SUIT_Application* app = ses->activeApplication();
375 SUIT_Desktop* desk = app->desktop();
376 QList<SUIT_ViewWindow*> wnds = desk->windows();
377 SUIT_ViewWindow* wnd;
378 QListIterator<SUIT_ViewWindow*> it( wnds );
379 while ( it.hasNext() && (wnd = it.next()) )
381 SUIT_ViewManager* vman = wnd->getViewManager();
384 SUIT_ViewModel* vmodel = vman->getViewModel();
387 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
390 if ( view->isVisible( theIO ) || view == GetActiveView() )
392 Erase( theIO, true, false, view );
393 Display( theIO, updateViewer, view );
402 //=================================================================
404 * GEOM_Displayer::Display
405 * Calls Display() method for each object in the given list
407 //=================================================================
408 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
410 SALOME_ListIteratorOfListIO Iter( theIOList );
411 for ( ; Iter.More(); Iter.Next() ) {
412 Display( Iter.Value(), false );
418 //=================================================================
420 * GEOM_Displayer::Erase
421 * Calls Erase() method for each object in the given list
423 //=================================================================
424 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
426 const bool updateViewer )
428 SALOME_ListIteratorOfListIO Iter( theIOList );
429 for ( ; Iter.More(); Iter.Next() )
430 Erase( Iter.Value(), forced, false );
436 //=================================================================
438 * GEOM_Displayer::Redisplay
439 * Calls Redisplay() method for each object in the given list
441 //=================================================================
442 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
444 SALOME_ListIteratorOfListIO Iter( theIOList );
445 for ( ; Iter.More(); Iter.Next() )
446 Redisplay( Iter.Value(), false );
452 //=================================================================
454 * GEOM_Displayer::Update
455 * Update OCC presentaion
456 * [ Reimplemented from SALOME_Displayer ]
458 //=================================================================
459 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
461 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
465 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
467 TopoDS_Face aFace = TopoDS::Face( myShape );
468 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
469 if ( !aPlane.IsNull() )
471 gp_Ax3 aPos = aPlane->Pln().Position();
472 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
474 Handle(GEOM_AISTrihedron) aTrh;
476 if ( occPrs->IsNull() )
478 aTrh = new GEOM_AISTrihedron( aPlc );
481 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
484 aTrh->SetWidth( GetWidth() );
486 if ( !myIO.IsNull() )
489 aTrh->SetOwner( myIO );
492 occPrs->AddObject( aTrh );
496 AIS_ListOfInteractive aList;
497 occPrs->GetObjects( aList );
498 AIS_ListIteratorOfListOfInteractive anIter( aList );
499 for ( ; anIter.More(); anIter.Next() )
501 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
502 if ( !aTrh.IsNull() )
504 aTrh->SetComponent( aPlc );
510 occPrs->SetToActivate( ToActivate() );
515 // if presentation is empty we try to create new one
516 if ( occPrs->IsNull() )
518 if ( !myShape.IsNull() )
520 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
521 Handle(GEOM_AISShape) AISShape;
522 if (myType == GEOM_VECTOR)
523 AISShape = new GEOM_AISVector (myShape, "");
525 AISShape = new GEOM_AISShape (myShape, "");
526 // Temporary staff: vertex must be infinite for correct visualization
527 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
529 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
530 AISShape->SetDisplayMode( myDisplayMode );
531 AISShape->SetShadingColor( myShadingColor );
533 // Set color and number for iso lines
534 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
535 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
536 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
537 Quantity_Color aColor = SalomeApp_Tools::color( col );
538 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
539 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
541 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
542 anAspect->SetNumber( anUIsoNumber );
543 anAspect->SetColor( aColor );
544 AISShape->Attributes()->SetUIsoAspect( anAspect );
546 anAspect = AISShape->Attributes()->VIsoAspect();
547 anAspect->SetNumber( aVIsoNumber );
548 anAspect->SetColor( aColor );
549 AISShape->Attributes()->SetVIsoAspect( anAspect );
553 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
554 if ( myShape.ShapeType() == TopAbs_VERTEX )
556 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
557 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
558 anAspect->SetScale( myScaleOfMarker );
559 anAspect->SetTypeOfMarker( myTypeOfMarker );
560 AISShape->Attributes()->SetPointAspect( anAspect );
565 if ( myShape.ShapeType() == TopAbs_VERTEX )
567 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
568 aColor = SalomeApp_Tools::color( col );
570 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
571 anAspect->SetColor( aColor );
572 anAspect->SetScale( myScaleOfMarker );
573 anAspect->SetTypeOfMarker( myTypeOfMarker );
574 AISShape->Attributes()->SetPointAspect( anAspect );
579 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
580 aColor = SalomeApp_Tools::color( col );
582 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
583 anAspect->SetColor( aColor );
584 AISShape->Attributes()->SetLineAspect( anAspect );
586 // Set unfree boundaries aspect
587 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
588 anAspect->SetColor( aColor );
589 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
591 // Set free boundaries aspect
592 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
593 aColor = SalomeApp_Tools::color( col );
595 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
596 anAspect->SetColor( aColor );
597 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
600 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
601 aColor = SalomeApp_Tools::color( col );
603 anAspect = AISShape->Attributes()->WireAspect();
604 anAspect->SetColor( aColor );
605 AISShape->Attributes()->SetWireAspect( anAspect );
610 AISShape->SetWidth( GetWidth() );
612 if ( !myIO.IsNull() )
614 AISShape->setIO( myIO );
615 AISShape->SetOwner( myIO );
617 else if ( !myName.empty() )
619 // Workaround to allow selection of temporary objects
620 static int tempId = 0;
622 sprintf( buf, "TEMP_%d", tempId++ );
623 Handle( SALOME_InteractiveObject ) anObj =
624 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
625 AISShape->setIO( anObj );
626 AISShape->SetOwner( anObj );
628 // AISShape->SetName(???); ??? necessary to set name ???
629 occPrs->AddObject( AISShape );
631 // In accordance with ToActivate() value object will be activated/deactivated
632 // when it will be displayed
633 occPrs->SetToActivate( ToActivate() );
636 // if presentation is found -> set again shape for it
639 if ( !myShape.IsNull() )
641 AIS_ListOfInteractive IOList;
642 occPrs->GetObjects( IOList );
643 AIS_ListIteratorOfListOfInteractive Iter( IOList );
644 for ( ; Iter.More(); Iter.Next() )
646 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
647 if ( AISShape.IsNull() )
649 if ( AISShape->Shape() != myShape )
651 AISShape->Set( myShape );
652 AISShape->UpdateSelection();
653 AISShape->SetToUpdate();
655 if ( !myIO.IsNull() )
657 AISShape->setIO( myIO );
658 AISShape->SetOwner( myIO );
666 //=================================================================
668 * GEOM_Displayer::Update
669 * Update VTK presentaion
670 * [ Reimplemented from SALOME_Displayer ]
672 //=================================================================
673 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
675 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
676 if ( !vtkPrs || myShape.IsNull() )
679 vtkActorCollection* theActors = 0;
681 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
683 myToActivate = false;
684 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
688 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
689 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
692 Handle(Geom_Plane) aPlane =
693 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
694 if ( aPlane.IsNull() )
697 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
698 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
700 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
701 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
703 vtkPrs->AddObject( aTrh );
705 theActors = vtkActorCollection::New();
706 theActors->AddItem( aTrh );
710 bool isVector = (myType == GEOM_VECTOR);
711 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
714 theActors->InitTraversal();
716 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
718 vtkProperty* aProp = 0;
720 if ( HasColor() || HasWidth() )
722 aProp = vtkProperty::New();
723 aProp->SetRepresentationToWireframe();
728 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
729 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
734 aProp->SetLineWidth( GetWidth() );
737 while ( anActor != NULL )
739 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
741 GActor->setIO( myIO );
745 GActor->SetProperty( aProp );
746 GActor->SetPreviewProperty( aProp );
748 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
749 if ( aGeomGActor != 0 )
751 aGeomGActor->SetShadingProperty( aProp );
752 aGeomGActor->SetWireframeProperty( aProp );
757 GActor->PickableOn();
759 GActor->PickableOff();
761 vtkPrs->AddObject( GActor );
763 anActor = (vtkActor*)theActors->GetNextActor();
772 //=================================================================
774 * GEOM_Displayer::BuildPrs
775 * Build presentation accordint to the current viewer type
777 //=================================================================
778 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
780 if ( theObj->_is_nil() )
783 myViewFrame = GetActiveView();
784 if ( myViewFrame == 0 )
787 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
792 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
793 myType = theObj->GetType();
795 // Update presentation
801 //=================================================================
803 * GEOM_Displayer::BuildPrs
804 * Build presentation accordint to the current viewer type
806 //=================================================================
807 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
809 myViewFrame = GetActiveView();
810 if ( theShape.IsNull() || myViewFrame == 0 )
813 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
818 setShape( theShape );
826 //=================================================================
828 * GEOM_Displayer::buildPresentation
829 * Builds/finds object's presentation for the current viewer
830 * Calls corresponding Update() method by means of double dispatch
833 //=================================================================
834 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
835 SALOME_View* theViewFrame )
840 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
844 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
847 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
848 theIO->setEntry( entry.toLatin1() );
849 if ( !theIO.IsNull() )
851 // set interactive object
853 // Find SOBject (because shape should be published previously)
854 SUIT_Session* session = SUIT_Session::session();
855 SUIT_Application* app = session->activeApplication();
858 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
861 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
864 // get CORBA reference to data object
865 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
866 if ( !CORBA::is_nil( object ) )
868 // downcast to GEOM object
869 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
870 if ( !GeomObject->_is_nil() )
873 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
874 myType = GeomObject->GetType();
881 UpdatePrs( prs ); // Update presentation by using of the double dispatch
887 //=================================================================
889 * GEOM_Displayer::internalReset
890 * Resets internal data
893 //=================================================================
894 void GEOM_Displayer::internalReset()
900 //=================================================================
902 * GEOM_Displayer::LocalSelection
903 * Activate selection of CAD shapes with activisation of selection
904 * of their sub-shapes (with opened local context for OCC viewer)
906 //=================================================================
907 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
909 SUIT_Session* session = SUIT_Session::session();
910 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
914 LightApp_SelectionMgr* sm = app->selectionMgr();
916 // remove all filters from selection
919 SALOME_View* vf = GetActiveView();
921 if (!theIO.IsNull() && !vf->isVisible(theIO))
923 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
924 vf->LocalSelection( prs, theMode );
925 delete prs; // delete presentation because displayer is its owner
929 //=================================================================
931 * GEOM_Displayer::globalSelection
932 * Activate selection of CAD shapes without activisation of selection
933 * of their sub-shapes (without opened local context for OCC viewer)
935 //=================================================================
936 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
938 TColStd_MapOfInteger aModes;
939 aModes.Add( theMode );
940 GlobalSelection( aModes, update );
943 //=================================================================
945 * GEOM_Displayer::globalSelection
946 * Activate selection of CAD shapes without activisation of selection
947 * of their sub-shapes (without opened local context for OCC viewer)
949 //=================================================================
950 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
953 SUIT_Session* session = SUIT_Session::session();
954 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
958 SALOME_View* vf = GetActiveView();
962 // Close local context
963 vf->GlobalSelection( update );
965 // Set selection filters in accordance with current mode
966 LightApp_SelectionMgr* sm = app->selectionMgr();
970 // Remove from selection temporary objects if necessary
971 if ( !theModes.Contains( GEOM_PREVIEW ) )
972 clearTemporary( sm );
974 //@ aSel->ClearIndex();
978 // Remove filters from AIS_InteractiveContext
979 Handle(AIS_InteractiveContext) ic;
980 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
983 ic = viewer->getAISContext();
988 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
991 SUIT_SelectionFilter* aFilter;
992 if ( theModes.Extent() == 1 )
994 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
995 aFilter = getFilter( aMode );
997 else if ( theModes.Extent() > 1 )
999 TColStd_MapOfInteger aTopAbsModes;
1000 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1001 QList<SUIT_SelectionFilter*> aListOfFilters;
1002 for ( ; anIter.More(); anIter.Next() )
1004 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
1006 aListOfFilters.append( aFilter );
1009 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1016 sm->installFilter( aFilter );
1019 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1020 ic->AddFilter( anOCCFilter );
1025 //=================================================================
1027 * GEOM_Displayer::LocalSelection
1028 * Activate selection of CAD shapes with activisation of selection
1029 * of their sub-shapes (with opened local context for OCC viewer)
1031 //=================================================================
1032 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1034 SALOME_ListIteratorOfListIO Iter( theIOList );
1035 for ( ; Iter.More(); Iter.Next() )
1036 LocalSelection( Iter.Value(), theMode );
1039 //=================================================================
1041 * GEOM_Displayer::BeforeDisplay
1042 * Called before displaying of pars. Close local context
1043 * [ Reimplemented from SALOME_Displayer ]
1045 //=================================================================
1046 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1048 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1051 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1054 if ( ic->HasOpenedContext() )
1055 ic->CloseAllContexts();
1060 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1065 //=================================================================
1067 * GEOM_Displayer::SetColor
1068 * Set color for shape displaying. If it is equal -1 then default color is used.
1069 * Available values are from Quantity_NameOfColor enumeration
1071 //=================================================================
1072 void GEOM_Displayer::SetColor( const int color )
1079 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1083 int GEOM_Displayer::GetColor() const
1088 bool GEOM_Displayer::HasColor() const
1090 return myColor != -1;
1093 void GEOM_Displayer::UnsetColor()
1097 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1098 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1099 myShadingColor = SalomeApp_Tools::color( col );
1102 //=================================================================
1104 * GEOM_Displayer::SetWidth
1105 * Set width of shape displaying. If it is equal -1 then default width is used.
1107 //=================================================================
1108 void GEOM_Displayer::SetWidth( const double width )
1113 double GEOM_Displayer::GetWidth() const
1118 bool GEOM_Displayer::HasWidth() const
1120 return myWidth != -1;
1123 void GEOM_Displayer::UnsetWidth()
1128 //=================================================================
1130 * GEOM_Displayer::SetToActivate
1131 * This method is used for activisation/deactivisation of objects to be displayed
1133 //=================================================================
1134 void GEOM_Displayer::SetToActivate( const bool toActivate )
1136 myToActivate = toActivate;
1138 bool GEOM_Displayer::ToActivate() const
1140 return myToActivate;
1143 //=================================================================
1145 * GEOM_Displayer::clearTemporary
1146 * Removes from selection temporary objects
1148 //=================================================================
1149 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1151 SALOME_ListIO selected, toSelect;
1152 theSelMgr->selectedObjects( selected );
1154 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1155 Handle(SALOME_InteractiveObject) io = it.Value();
1156 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1157 toSelect.Append( it.Value() );
1160 theSelMgr->setSelectedObjects( toSelect, true );
1163 void GEOM_Displayer::SetName( const char* theName )
1168 void GEOM_Displayer::UnsetName()
1173 SalomeApp_Study* GEOM_Displayer::getStudy() const
1175 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1178 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1183 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1188 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1190 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1193 int GEOM_Displayer::SetDisplayMode( const int theMode )
1195 int aPrevMode = myDisplayMode;
1196 if ( theMode != -1 )
1197 myDisplayMode = theMode;
1200 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1201 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1206 int GEOM_Displayer::GetDisplayMode() const
1208 return myDisplayMode;
1211 int GEOM_Displayer::UnsetDisplayMode()
1213 int aPrevMode = myDisplayMode;
1214 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1215 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );