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_Tools.h>
51 #include <SUIT_ViewManager.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>
62 #include <SOCC_ViewModel.h>
65 #include <SVTK_ViewModel.h>
67 #include <SALOMEDSClient.hxx>
68 #include <SALOMEDSClient_SObject.hxx>
71 #include <AIS_Drawer.hxx>
72 #include <AIS_ListIteratorOfListOfInteractive.hxx>
73 #include <Prs3d_IsoAspect.hxx>
74 #include <Prs3d_PointAspect.hxx>
75 #include <Graphic3d_AspectMarker3d.hxx>
76 #include <StdSelect_TypeOfEdge.hxx>
77 #include <StdSelect_TypeOfFace.hxx>
78 #include <TopoDS_Face.hxx>
79 #include <BRep_Tool.hxx>
80 #include <Geom_Plane.hxx>
81 #include <Geom_Axis2Placement.hxx>
83 #include <TColStd_MapOfInteger.hxx>
84 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
87 #include <vtkActorCollection.h>
88 #include <vtkProperty.h>
94 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
96 #include "GEOMImpl_Types.hxx"
100 //================================================================
101 // Function : getActiveStudy
102 // Purpose : Get active study, returns 0 if no open study frame
103 //================================================================
104 static inline SalomeApp_Study* getActiveStudy()
106 SUIT_Session* session = SUIT_Session::session();
107 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
109 return ( SalomeApp_Study* )app->activeStudy();
113 //================================================================
114 // Function : getTopAbsMode
115 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
116 // one from GEOMImpl_Types.h
117 //================================================================
118 static inline int getTopAbsMode( const int implType )
122 case GEOM_COMPOUND : return TopAbs_COMPOUND;
123 case GEOM_SOLID : return TopAbs_SOLID;
124 case GEOM_SHELL : return TopAbs_SHELL;
125 case GEOM_FACE : return TopAbs_FACE;
126 case GEOM_WIRE : return TopAbs_WIRE;
127 case GEOM_EDGE : return TopAbs_EDGE;
128 case GEOM_POINT : return TopAbs_VERTEX;
133 //================================================================
134 // Function : getFilter
135 // Purpose : Get filter corresponding to the type of object
136 // from GEOMImpl_Types.h
137 //================================================================
138 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
140 SUIT_SelectionFilter* aFilter;
142 int aTopAbsMode = getTopAbsMode( theMode );
143 if ( aTopAbsMode != -1 )
144 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
148 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
149 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
151 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
152 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
153 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
154 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
155 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
156 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
158 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
160 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
161 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
163 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
169 //================================================================
170 // Function : getEntry
172 //================================================================
173 static string getEntry( GEOM::GEOM_Object_ptr object )
175 SUIT_Session* session = SUIT_Session::session();
176 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
179 CORBA::String_var IOR = app->orb()->object_to_string( object );
180 if ( strcmp(IOR.in(), "") != 0 )
182 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
183 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
191 //================================================================
192 // Function : getName
194 //================================================================
195 static string getName( GEOM::GEOM_Object_ptr object )
197 SUIT_Session* session = SUIT_Session::session();
198 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
201 CORBA::String_var IOR = app->orb()->object_to_string( object );
202 if ( strcmp(IOR.in(), "") != 0 )
204 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
205 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
207 _PTR(GenericAttribute) anAttr;
209 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
211 _PTR(AttributeName) aNameAttr( anAttr );
212 return aNameAttr->Value();
220 //=================================================================
222 * GEOM_Displayer::GEOM_Displayer
225 //=================================================================
226 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
229 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
234 SUIT_Session* session = SUIT_Session::session();
235 SUIT_ResourceMgr* resMgr = session->resourceMgr();
237 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
238 myShadingColor = SalomeApp_Tools::color( col );
240 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
241 myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
242 myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
243 if(myScaleOfMarker < 1.0)
244 myScaleOfMarker = 1.0;
245 if(myScaleOfMarker > 7.)
246 myScaleOfMarker = 7.;
250 // This color is used for shape displaying. If it is equal -1 then
251 // default color is used.
257 // This parameter is used for activisation/deactivisation of objects to be displayed
262 //=================================================================
264 * GEOM_Displayer::~GEOM_Displayer
267 //=================================================================
268 GEOM_Displayer::~GEOM_Displayer()
272 //=================================================================
274 * GEOM_Displayer::Display
275 * Display interactive object in the current viewer
277 //=================================================================
278 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
279 const bool updateViewer,
280 SALOME_View* theViewFrame )
282 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
285 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
289 vf->BeforeDisplay( this );
291 vf->AfterDisplay( this );
296 delete prs; // delete presentation because displayer is its owner
301 //=================================================================
303 * GEOM_Displayer::Display
304 * This overloaded Display() method can be useful for operations
305 * not using dialog boxes.
307 //=================================================================
308 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
310 if ( theObj->_is_nil() )
313 string entry = getEntry( theObj );
315 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
320 //=================================================================
322 * GEOM_Displayer::Erase
323 * Erase interactive object in the current viewer
325 //=================================================================
326 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
328 const bool updateViewer,
329 SALOME_View* theViewFrame )
331 if ( theIO.IsNull() )
334 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
337 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
339 vf->Erase( prs, forced );
342 delete prs; // delete presentation because displayer is its owner
347 //=================================================================
349 * GEOM_Displayer::Erase
350 * Erase geometry object in the current viewer
352 //=================================================================
353 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
355 const bool updateViewer )
357 string entry = getEntry( theObj );
360 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
361 forced, updateViewer);
365 //=================================================================
367 * GEOM_Displayer::Redisplay
368 * Redisplay (erase and then display again) interactive object
369 * in the current viewer
371 //=================================================================
372 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
373 const bool updateViewer )
375 // Remove the object permanently (<forced> == true)
376 SUIT_Session* ses = SUIT_Session::session();
377 SUIT_Application* app = ses->activeApplication();
380 SUIT_Desktop* desk = app->desktop();
381 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
382 SUIT_ViewWindow* wnd;
383 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
385 SUIT_ViewManager* vman = wnd->getViewManager();
388 SUIT_ViewModel* vmodel = vman->getViewModel();
391 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
394 if ( view->isVisible( theIO ) || view == GetActiveView() )
396 Erase( theIO, true, false, view );
397 Display( theIO, updateViewer, view );
406 //=================================================================
408 * GEOM_Displayer::Display
409 * Calls Display() method for each object in the given list
411 //=================================================================
412 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
414 SALOME_ListIteratorOfListIO Iter( theIOList );
415 for ( ; Iter.More(); Iter.Next() ) {
416 Display( Iter.Value(), false );
422 //=================================================================
424 * GEOM_Displayer::Erase
425 * Calls Erase() method for each object in the given list
427 //=================================================================
428 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
430 const bool updateViewer )
432 SALOME_ListIteratorOfListIO Iter( theIOList );
433 for ( ; Iter.More(); Iter.Next() )
434 Erase( Iter.Value(), forced, false );
440 //=================================================================
442 * GEOM_Displayer::Redisplay
443 * Calls Redisplay() method for each object in the given list
445 //=================================================================
446 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
448 SALOME_ListIteratorOfListIO Iter( theIOList );
449 for ( ; Iter.More(); Iter.Next() )
450 Redisplay( Iter.Value(), false );
456 //=================================================================
458 * GEOM_Displayer::Update
459 * Update OCC presentaion
460 * [ Reimplemented from SALOME_Displayer ]
462 //=================================================================
463 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
465 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
469 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
471 TopoDS_Face aFace = TopoDS::Face( myShape );
472 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
473 if ( !aPlane.IsNull() )
475 gp_Ax3 aPos = aPlane->Pln().Position();
476 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
478 Handle(GEOM_AISTrihedron) aTrh;
480 if ( occPrs->IsNull() )
482 aTrh = new GEOM_AISTrihedron( aPlc );
485 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
488 aTrh->SetWidth( GetWidth() );
490 if ( !myIO.IsNull() )
493 aTrh->SetOwner( myIO );
496 occPrs->AddObject( aTrh );
500 AIS_ListOfInteractive aList;
501 occPrs->GetObjects( aList );
502 AIS_ListIteratorOfListOfInteractive anIter( aList );
503 for ( ; anIter.More(); anIter.Next() )
505 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
506 if ( !aTrh.IsNull() )
508 aTrh->SetComponent( aPlc );
514 occPrs->SetToActivate( ToActivate() );
519 // if presentation is empty we try to create new one
520 if ( occPrs->IsNull() )
522 if ( !myShape.IsNull() )
524 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
525 Handle(GEOM_AISShape) AISShape;
526 if (myType == GEOM_VECTOR)
527 AISShape = new GEOM_AISVector (myShape, "");
529 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->SetDisplayMode( myDisplayMode );
535 AISShape->SetShadingColor( myShadingColor );
537 // Set color and number for iso lines
538 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
539 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
540 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
541 Quantity_Color aColor = SalomeApp_Tools::color( col );
542 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
543 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
545 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
546 anAspect->SetNumber( anUIsoNumber );
547 anAspect->SetColor( aColor );
548 AISShape->Attributes()->SetUIsoAspect( anAspect );
550 anAspect = AISShape->Attributes()->VIsoAspect();
551 anAspect->SetNumber( aVIsoNumber );
552 anAspect->SetColor( aColor );
553 AISShape->Attributes()->SetVIsoAspect( anAspect );
557 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
558 if ( myShape.ShapeType() == TopAbs_VERTEX )
560 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
561 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
562 anAspect->SetScale( myScaleOfMarker );
563 anAspect->SetTypeOfMarker( myTypeOfMarker );
564 AISShape->Attributes()->SetPointAspect( anAspect );
569 if ( myShape.ShapeType() == TopAbs_VERTEX )
571 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
572 aColor = SalomeApp_Tools::color( col );
574 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
575 anAspect->SetColor( aColor );
576 anAspect->SetScale( myScaleOfMarker );
577 anAspect->SetTypeOfMarker( myTypeOfMarker );
578 AISShape->Attributes()->SetPointAspect( anAspect );
583 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
584 aColor = SalomeApp_Tools::color( col );
586 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
587 anAspect->SetColor( aColor );
588 AISShape->Attributes()->SetLineAspect( anAspect );
590 // Set unfree boundaries aspect
591 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
592 anAspect->SetColor( aColor );
593 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
595 // Set free boundaries aspect
596 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
597 aColor = SalomeApp_Tools::color( col );
599 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
600 anAspect->SetColor( aColor );
601 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
604 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
605 aColor = SalomeApp_Tools::color( col );
607 anAspect = AISShape->Attributes()->WireAspect();
608 anAspect->SetColor( aColor );
609 AISShape->Attributes()->SetWireAspect( anAspect );
614 AISShape->SetWidth( GetWidth() );
616 if ( !myIO.IsNull() )
618 AISShape->setIO( myIO );
619 AISShape->SetOwner( myIO );
621 else if ( !myName.empty() )
623 // Workaround to allow selection of temporary objects
624 static int tempId = 0;
626 sprintf( buf, "TEMP_%d", tempId++ );
627 Handle( SALOME_InteractiveObject ) anObj =
628 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
629 AISShape->setIO( anObj );
630 AISShape->SetOwner( anObj );
632 // AISShape->SetName(???); ??? necessary to set name ???
633 occPrs->AddObject( AISShape );
635 // In accordance with ToActivate() value object will be activated/deactivated
636 // when it will be displayed
637 occPrs->SetToActivate( ToActivate() );
640 // if presentation is found -> set again shape for it
643 if ( !myShape.IsNull() )
645 AIS_ListOfInteractive IOList;
646 occPrs->GetObjects( IOList );
647 AIS_ListIteratorOfListOfInteractive Iter( IOList );
648 for ( ; Iter.More(); Iter.Next() )
650 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
651 if ( AISShape.IsNull() )
653 if ( AISShape->Shape() != myShape )
655 AISShape->Set( myShape );
656 AISShape->UpdateSelection();
657 AISShape->SetToUpdate();
659 if ( !myIO.IsNull() )
661 AISShape->setIO( myIO );
662 AISShape->SetOwner( myIO );
670 //=================================================================
672 * GEOM_Displayer::Update
673 * Update VTK presentaion
674 * [ Reimplemented from SALOME_Displayer ]
676 //=================================================================
677 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
679 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
680 if ( !vtkPrs || myShape.IsNull() )
683 vtkActorCollection* theActors = 0;
685 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
687 myToActivate = false;
688 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
692 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
693 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
696 Handle(Geom_Plane) aPlane =
697 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
698 if ( aPlane.IsNull() )
701 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
702 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
704 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
705 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
707 vtkPrs->AddObject( aTrh );
709 theActors = vtkActorCollection::New();
710 theActors->AddItem( aTrh );
714 bool isVector = (myType == GEOM_VECTOR);
715 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
718 theActors->InitTraversal();
720 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
722 vtkProperty* aProp = 0;
724 if ( HasColor() || HasWidth() )
726 aProp = vtkProperty::New();
727 aProp->SetRepresentationToWireframe();
732 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
733 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
738 aProp->SetLineWidth( GetWidth() );
741 while ( anActor != NULL )
743 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
745 GActor->setIO( myIO );
749 GActor->SetProperty( aProp );
750 GActor->SetPreviewProperty( aProp );
752 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
753 if ( aGeomGActor != 0 )
755 aGeomGActor->SetShadingProperty( aProp );
756 aGeomGActor->SetWireframeProperty( aProp );
761 GActor->PickableOn();
763 GActor->PickableOff();
765 vtkPrs->AddObject( GActor );
767 anActor = (vtkActor*)theActors->GetNextActor();
776 //=================================================================
778 * GEOM_Displayer::BuildPrs
779 * Build presentation accordint to the current viewer type
781 //=================================================================
782 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
784 if ( theObj->_is_nil() )
787 myViewFrame = GetActiveView();
788 if ( myViewFrame == 0 )
791 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
796 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
797 myType = theObj->GetType();
799 // Update presentation
805 //=================================================================
807 * GEOM_Displayer::BuildPrs
808 * Build presentation accordint to the current viewer type
810 //=================================================================
811 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
813 myViewFrame = GetActiveView();
814 if ( theShape.IsNull() || myViewFrame == 0 )
817 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
822 setShape( theShape );
830 //=================================================================
832 * GEOM_Displayer::buildPresentation
833 * Builds/finds object's presentation for the current viewer
834 * Calls corresponding Update() method by means of double dispatch
837 //=================================================================
838 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
839 SALOME_View* theViewFrame )
844 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
848 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
851 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
852 theIO->setEntry( entry.latin1() );
853 if ( !theIO.IsNull() )
855 // set interactive object
857 // Find SOBject (because shape should be published previously)
858 SUIT_Session* session = SUIT_Session::session();
859 SUIT_Application* app = session->activeApplication();
862 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
865 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
868 // get CORBA reference to data object
869 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
870 if ( !CORBA::is_nil( object ) )
872 // downcast to GEOM object
873 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
874 if ( !GeomObject->_is_nil() )
877 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
878 myType = GeomObject->GetType();
885 UpdatePrs( prs ); // Update presentation by using of the double dispatch
891 //=================================================================
893 * GEOM_Displayer::internalReset
894 * Resets internal data
897 //=================================================================
898 void GEOM_Displayer::internalReset()
904 //=================================================================
906 * GEOM_Displayer::LocalSelection
907 * Activate selection of CAD shapes with activisation of selection
908 * of their sub-shapes (with opened local context for OCC viewer)
910 //=================================================================
911 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
913 SUIT_Session* session = SUIT_Session::session();
914 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
918 LightApp_SelectionMgr* sm = app->selectionMgr();
920 // remove all filters from selection
923 SALOME_View* vf = GetActiveView();
925 if (!theIO.IsNull() && !vf->isVisible(theIO))
927 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
928 vf->LocalSelection( prs, theMode );
929 delete prs; // delete presentation because displayer is its owner
933 //=================================================================
935 * GEOM_Displayer::globalSelection
936 * Activate selection of CAD shapes without activisation of selection
937 * of their sub-shapes (without opened local context for OCC viewer)
939 //=================================================================
940 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
942 TColStd_MapOfInteger aModes;
943 aModes.Add( theMode );
944 GlobalSelection( aModes, update );
947 //=================================================================
949 * GEOM_Displayer::globalSelection
950 * Activate selection of CAD shapes without activisation of selection
951 * of their sub-shapes (without opened local context for OCC viewer)
953 //=================================================================
954 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
957 SUIT_Session* session = SUIT_Session::session();
958 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
962 SALOME_View* vf = GetActiveView();
966 // Close local context
967 vf->GlobalSelection( update );
969 // Set selection filters in accordance with current mode
970 LightApp_SelectionMgr* sm = app->selectionMgr();
974 // Remove from selection temporary objects if necessary
975 if ( !theModes.Contains( GEOM_PREVIEW ) )
976 clearTemporary( sm );
978 //@ aSel->ClearIndex();
982 // Remove filters from AIS_InteractiveContext
983 Handle(AIS_InteractiveContext) ic;
984 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
987 ic = viewer->getAISContext();
992 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
995 SUIT_SelectionFilter* aFilter;
996 if ( theModes.Extent() == 1 )
998 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
999 aFilter = getFilter( aMode );
1001 else if ( theModes.Extent() > 1 )
1003 TColStd_MapOfInteger aTopAbsModes;
1004 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1005 QPtrList<SUIT_SelectionFilter> aListOfFilters;
1006 for ( ; anIter.More(); anIter.Next() )
1008 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
1010 aListOfFilters.append( aFilter );
1013 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1020 sm->installFilter( aFilter );
1023 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1024 ic->AddFilter( anOCCFilter );
1029 //=================================================================
1031 * GEOM_Displayer::LocalSelection
1032 * Activate selection of CAD shapes with activisation of selection
1033 * of their sub-shapes (with opened local context for OCC viewer)
1035 //=================================================================
1036 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1038 SALOME_ListIteratorOfListIO Iter( theIOList );
1039 for ( ; Iter.More(); Iter.Next() )
1040 LocalSelection( Iter.Value(), theMode );
1043 //=================================================================
1045 * GEOM_Displayer::BeforeDisplay
1046 * Called before displaying of pars. Close local context
1047 * [ Reimplemented from SALOME_Displayer ]
1049 //=================================================================
1050 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1052 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1055 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1058 if ( ic->HasOpenedContext() )
1059 ic->CloseAllContexts();
1064 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1069 //=================================================================
1071 * GEOM_Displayer::SetColor
1072 * Set color for shape displaying. If it is equal -1 then default color is used.
1073 * Available values are from Quantity_NameOfColor enumeration
1075 //=================================================================
1076 void GEOM_Displayer::SetColor( const int color )
1083 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1087 int GEOM_Displayer::GetColor() const
1092 bool GEOM_Displayer::HasColor() const
1094 return myColor != -1;
1097 void GEOM_Displayer::UnsetColor()
1101 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1102 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1103 myShadingColor = SalomeApp_Tools::color( col );
1106 //=================================================================
1108 * GEOM_Displayer::SetWidth
1109 * Set width of shape displaying. If it is equal -1 then default width is used.
1111 //=================================================================
1112 void GEOM_Displayer::SetWidth( const double width )
1117 double GEOM_Displayer::GetWidth() const
1122 bool GEOM_Displayer::HasWidth() const
1124 return myWidth != -1;
1127 void GEOM_Displayer::UnsetWidth()
1132 //=================================================================
1134 * GEOM_Displayer::SetToActivate
1135 * This method is used for activisation/deactivisation of objects to be displayed
1137 //=================================================================
1138 void GEOM_Displayer::SetToActivate( const bool toActivate )
1140 myToActivate = toActivate;
1142 bool GEOM_Displayer::ToActivate() const
1144 return myToActivate;
1147 //=================================================================
1149 * GEOM_Displayer::clearTemporary
1150 * Removes from selection temporary objects
1152 //=================================================================
1153 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1155 SALOME_ListIO selected, toSelect;
1156 theSelMgr->selectedObjects( selected );
1158 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1159 Handle(SALOME_InteractiveObject) io = it.Value();
1160 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1161 toSelect.Append( it.Value() );
1164 theSelMgr->setSelectedObjects( toSelect, true );
1167 void GEOM_Displayer::SetName( const char* theName )
1172 void GEOM_Displayer::UnsetName()
1177 SalomeApp_Study* GEOM_Displayer::getStudy() const
1179 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1182 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1187 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1192 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1194 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1197 int GEOM_Displayer::SetDisplayMode( const int theMode )
1199 int aPrevMode = myDisplayMode;
1200 if ( theMode != -1 )
1201 myDisplayMode = theMode;
1204 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1205 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1210 int GEOM_Displayer::GetDisplayMode() const
1212 return myDisplayMode;
1215 int GEOM_Displayer::UnsetDisplayMode()
1217 int aPrevMode = myDisplayMode;
1218 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1219 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );