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>
85 #include <TopoDS_Iterator.hxx>
88 #include <vtkActorCollection.h>
89 #include <vtkProperty.h>
95 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
97 #include "GEOMImpl_Types.hxx"
101 //================================================================
102 // Function : getActiveStudy
103 // Purpose : Get active study, returns 0 if no open study frame
104 //================================================================
105 static inline SalomeApp_Study* getActiveStudy()
107 SUIT_Session* session = SUIT_Session::session();
108 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
110 return ( SalomeApp_Study* )app->activeStudy();
114 //================================================================
115 // Function : getTopAbsMode
116 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
117 // one from GEOMImpl_Types.h
118 //================================================================
119 static inline int getTopAbsMode( const int implType )
123 case GEOM_COMPOUND : return TopAbs_COMPOUND;
124 case GEOM_SOLID : return TopAbs_SOLID;
125 case GEOM_SHELL : return TopAbs_SHELL;
126 case GEOM_FACE : return TopAbs_FACE;
127 case GEOM_WIRE : return TopAbs_WIRE;
128 case GEOM_EDGE : return TopAbs_EDGE;
129 case GEOM_POINT : return TopAbs_VERTEX;
134 //================================================================
135 // Function : getFilter
136 // Purpose : Get filter corresponding to the type of object
137 // from GEOMImpl_Types.h
138 //================================================================
139 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
141 SUIT_SelectionFilter* aFilter;
143 int aTopAbsMode = getTopAbsMode( theMode );
144 if ( aTopAbsMode != -1 )
145 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
149 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
150 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
152 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
153 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
154 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
155 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
156 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
157 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
159 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
161 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
162 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
164 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
170 //================================================================
171 // Function : getEntry
173 //================================================================
174 static string getEntry( GEOM::GEOM_Object_ptr object )
176 SUIT_Session* session = SUIT_Session::session();
177 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
180 CORBA::String_var IOR = app->orb()->object_to_string( object );
181 if ( strcmp(IOR.in(), "") != 0 )
183 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
184 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
192 //================================================================
193 // Function : getName
195 //================================================================
196 static string getName( GEOM::GEOM_Object_ptr object )
198 SUIT_Session* session = SUIT_Session::session();
199 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
202 CORBA::String_var IOR = app->orb()->object_to_string( object );
203 if ( strcmp(IOR.in(), "") != 0 )
205 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
206 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
208 _PTR(GenericAttribute) anAttr;
210 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
212 _PTR(AttributeName) aNameAttr( anAttr );
213 return aNameAttr->Value();
221 //=================================================================
223 * GEOM_Displayer::GEOM_Displayer
226 //=================================================================
227 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
230 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
235 SUIT_Session* session = SUIT_Session::session();
236 SUIT_ResourceMgr* resMgr = session->resourceMgr();
238 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
239 myShadingColor = SalomeApp_Tools::color( col );
241 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
242 myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
243 myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
244 if(myScaleOfMarker < 1.0)
245 myScaleOfMarker = 1.0;
246 if(myScaleOfMarker > 7.)
247 myScaleOfMarker = 7.;
251 // This color is used for shape displaying. If it is equal -1 then
252 // default color is used.
258 // This parameter is used for activisation/deactivisation of objects to be displayed
263 //=================================================================
265 * GEOM_Displayer::~GEOM_Displayer
268 //=================================================================
269 GEOM_Displayer::~GEOM_Displayer()
273 //=================================================================
275 * GEOM_Displayer::Display
276 * Display interactive object in the current viewer
278 //=================================================================
279 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
280 const bool updateViewer,
281 SALOME_View* theViewFrame )
283 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
286 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
290 vf->BeforeDisplay( this );
292 vf->AfterDisplay( this );
297 delete prs; // delete presentation because displayer is its owner
302 //=================================================================
304 * GEOM_Displayer::Display
305 * This overloaded Display() method can be useful for operations
306 * not using dialog boxes.
308 //=================================================================
309 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
311 if ( theObj->_is_nil() )
314 string entry = getEntry( theObj );
316 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
321 //=================================================================
323 * GEOM_Displayer::Erase
324 * Erase interactive object in the current viewer
326 //=================================================================
327 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
329 const bool updateViewer,
330 SALOME_View* theViewFrame )
332 if ( theIO.IsNull() )
335 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
338 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
340 vf->Erase( prs, forced );
343 delete prs; // delete presentation because displayer is its owner
348 //=================================================================
350 * GEOM_Displayer::Erase
351 * Erase geometry object in the current viewer
353 //=================================================================
354 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
356 const bool updateViewer )
358 string entry = getEntry( theObj );
361 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
362 forced, updateViewer);
366 //=================================================================
368 * GEOM_Displayer::Redisplay
369 * Redisplay (erase and then display again) interactive object
370 * in the current viewer
372 //=================================================================
373 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
374 const bool updateViewer )
376 // Remove the object permanently (<forced> == true)
377 SUIT_Session* ses = SUIT_Session::session();
378 SUIT_Application* app = ses->activeApplication();
381 SUIT_Desktop* desk = app->desktop();
382 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
383 SUIT_ViewWindow* wnd;
384 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
386 SUIT_ViewManager* vman = wnd->getViewManager();
389 SUIT_ViewModel* vmodel = vman->getViewModel();
392 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
395 if ( view->isVisible( theIO ) || view == GetActiveView() )
397 Erase( theIO, true, false, view );
398 Display( theIO, updateViewer, view );
407 //=================================================================
409 * GEOM_Displayer::Display
410 * Calls Display() method for each object in the given list
412 //=================================================================
413 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
415 SALOME_ListIteratorOfListIO Iter( theIOList );
416 for ( ; Iter.More(); Iter.Next() ) {
417 Display( Iter.Value(), false );
423 //=================================================================
425 * GEOM_Displayer::Erase
426 * Calls Erase() method for each object in the given list
428 //=================================================================
429 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
431 const bool updateViewer )
433 SALOME_ListIteratorOfListIO Iter( theIOList );
434 for ( ; Iter.More(); Iter.Next() )
435 Erase( Iter.Value(), forced, false );
441 //=================================================================
443 * GEOM_Displayer::Redisplay
444 * Calls Redisplay() method for each object in the given list
446 //=================================================================
447 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
449 SALOME_ListIteratorOfListIO Iter( theIOList );
450 for ( ; Iter.More(); Iter.Next() )
451 Redisplay( Iter.Value(), false );
457 //=================================================================
459 * GEOM_Displayer::Update
460 * Update OCC presentaion
461 * [ Reimplemented from SALOME_Displayer ]
463 //=================================================================
464 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
466 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
470 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
472 TopoDS_Face aFace = TopoDS::Face( myShape );
473 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
474 if ( !aPlane.IsNull() )
476 gp_Ax3 aPos = aPlane->Pln().Position();
477 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
479 Handle(GEOM_AISTrihedron) aTrh;
481 if ( occPrs->IsNull() )
483 aTrh = new GEOM_AISTrihedron( aPlc );
486 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
489 aTrh->SetWidth( GetWidth() );
491 if ( !myIO.IsNull() )
494 aTrh->SetOwner( myIO );
497 occPrs->AddObject( aTrh );
501 AIS_ListOfInteractive aList;
502 occPrs->GetObjects( aList );
503 AIS_ListIteratorOfListOfInteractive anIter( aList );
504 for ( ; anIter.More(); anIter.Next() )
506 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
507 if ( !aTrh.IsNull() )
509 aTrh->SetComponent( aPlc );
515 occPrs->SetToActivate( ToActivate() );
520 // if presentation is empty we try to create new one
521 if ( occPrs->IsNull() )
523 if ( !myShape.IsNull() )
525 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
526 Handle(GEOM_AISShape) AISShape;
527 if (myType == GEOM_VECTOR)
528 AISShape = new GEOM_AISVector (myShape, "");
530 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
531 !TopoDS_Iterator(myShape).More())
532 return;// NPAL15983 (Bug when displaying empty groups)
533 AISShape = new GEOM_AISShape (myShape, "");
535 // Temporary staff: vertex must be infinite for correct visualization
536 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
538 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
539 AISShape->SetDisplayMode( myDisplayMode );
540 AISShape->SetShadingColor( myShadingColor );
542 // Set color and number for iso lines
543 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
544 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
545 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
546 Quantity_Color aColor = SalomeApp_Tools::color( col );
547 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
548 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
550 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
551 anAspect->SetNumber( anUIsoNumber );
552 anAspect->SetColor( aColor );
553 AISShape->Attributes()->SetUIsoAspect( anAspect );
555 anAspect = AISShape->Attributes()->VIsoAspect();
556 anAspect->SetNumber( aVIsoNumber );
557 anAspect->SetColor( aColor );
558 AISShape->Attributes()->SetVIsoAspect( anAspect );
562 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
563 if ( myShape.ShapeType() == TopAbs_VERTEX )
565 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
566 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
567 anAspect->SetScale( myScaleOfMarker );
568 anAspect->SetTypeOfMarker( myTypeOfMarker );
569 AISShape->Attributes()->SetPointAspect( anAspect );
574 if ( myShape.ShapeType() == TopAbs_VERTEX )
576 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
577 aColor = SalomeApp_Tools::color( col );
579 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
580 anAspect->SetColor( aColor );
581 anAspect->SetScale( myScaleOfMarker );
582 anAspect->SetTypeOfMarker( myTypeOfMarker );
583 AISShape->Attributes()->SetPointAspect( anAspect );
588 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
589 aColor = SalomeApp_Tools::color( col );
591 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
592 anAspect->SetColor( aColor );
593 AISShape->Attributes()->SetLineAspect( anAspect );
595 // Set unfree boundaries aspect
596 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
597 anAspect->SetColor( aColor );
598 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
600 // Set free boundaries aspect
601 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
602 aColor = SalomeApp_Tools::color( col );
604 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
605 anAspect->SetColor( aColor );
606 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
609 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
610 aColor = SalomeApp_Tools::color( col );
612 anAspect = AISShape->Attributes()->WireAspect();
613 anAspect->SetColor( aColor );
614 AISShape->Attributes()->SetWireAspect( anAspect );
619 AISShape->SetWidth( GetWidth() );
621 if ( !myIO.IsNull() )
623 AISShape->setIO( myIO );
624 AISShape->SetOwner( myIO );
626 else if ( !myName.empty() )
628 // Workaround to allow selection of temporary objects
629 static int tempId = 0;
631 sprintf( buf, "TEMP_%d", tempId++ );
632 Handle( SALOME_InteractiveObject ) anObj =
633 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
634 AISShape->setIO( anObj );
635 AISShape->SetOwner( anObj );
637 // AISShape->SetName(???); ??? necessary to set name ???
638 occPrs->AddObject( AISShape );
640 // In accordance with ToActivate() value object will be activated/deactivated
641 // when it will be displayed
642 occPrs->SetToActivate( ToActivate() );
645 // if presentation is found -> set again shape for it
648 if ( !myShape.IsNull() )
650 AIS_ListOfInteractive IOList;
651 occPrs->GetObjects( IOList );
652 AIS_ListIteratorOfListOfInteractive Iter( IOList );
653 for ( ; Iter.More(); Iter.Next() )
655 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
656 if ( AISShape.IsNull() )
658 if ( AISShape->Shape() != myShape )
660 AISShape->Set( myShape );
661 AISShape->UpdateSelection();
662 AISShape->SetToUpdate();
664 if ( !myIO.IsNull() )
666 AISShape->setIO( myIO );
667 AISShape->SetOwner( myIO );
675 //=================================================================
677 * GEOM_Displayer::Update
678 * Update VTK presentaion
679 * [ Reimplemented from SALOME_Displayer ]
681 //=================================================================
682 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
684 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
685 if ( !vtkPrs || myShape.IsNull() )
688 vtkActorCollection* theActors = 0;
690 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
692 myToActivate = false;
693 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
697 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
698 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
701 Handle(Geom_Plane) aPlane =
702 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
703 if ( aPlane.IsNull() )
706 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
707 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
709 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
710 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
712 vtkPrs->AddObject( aTrh );
714 theActors = vtkActorCollection::New();
715 theActors->AddItem( aTrh );
719 bool isVector = (myType == GEOM_VECTOR);
720 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
723 theActors->InitTraversal();
725 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
727 vtkProperty* aProp = 0;
729 if ( HasColor() || HasWidth() )
731 aProp = vtkProperty::New();
732 aProp->SetRepresentationToWireframe();
737 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
738 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
743 aProp->SetLineWidth( GetWidth() );
746 while ( anActor != NULL )
748 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
750 GActor->setIO( myIO );
754 GActor->SetProperty( aProp );
755 GActor->SetPreviewProperty( aProp );
757 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
758 if ( aGeomGActor != 0 )
760 aGeomGActor->SetShadingProperty( aProp );
761 aGeomGActor->SetWireframeProperty( aProp );
766 GActor->PickableOn();
768 GActor->PickableOff();
770 vtkPrs->AddObject( GActor );
772 anActor = (vtkActor*)theActors->GetNextActor();
781 //=================================================================
783 * GEOM_Displayer::BuildPrs
784 * Build presentation accordint to the current viewer type
786 //=================================================================
787 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
789 if ( theObj->_is_nil() )
792 myViewFrame = GetActiveView();
793 if ( myViewFrame == 0 )
796 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
801 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
802 myType = theObj->GetType();
804 // Update presentation
810 //=================================================================
812 * GEOM_Displayer::BuildPrs
813 * Build presentation accordint to the current viewer type
815 //=================================================================
816 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
818 myViewFrame = GetActiveView();
819 if ( theShape.IsNull() || myViewFrame == 0 )
822 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
827 setShape( theShape );
835 //=================================================================
837 * GEOM_Displayer::buildPresentation
838 * Builds/finds object's presentation for the current viewer
839 * Calls corresponding Update() method by means of double dispatch
842 //=================================================================
843 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
844 SALOME_View* theViewFrame )
849 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
853 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
856 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
857 theIO->setEntry( entry.latin1() );
858 if ( !theIO.IsNull() )
860 // set interactive object
862 // Find SOBject (because shape should be published previously)
863 SUIT_Session* session = SUIT_Session::session();
864 SUIT_Application* app = session->activeApplication();
867 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
870 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
873 // get CORBA reference to data object
874 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
875 if ( !CORBA::is_nil( object ) )
877 // downcast to GEOM object
878 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
879 if ( !GeomObject->_is_nil() )
882 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
883 myType = GeomObject->GetType();
890 UpdatePrs( prs ); // Update presentation by using of the double dispatch
896 //=================================================================
898 * GEOM_Displayer::internalReset
899 * Resets internal data
902 //=================================================================
903 void GEOM_Displayer::internalReset()
909 //=================================================================
911 * GEOM_Displayer::LocalSelection
912 * Activate selection of CAD shapes with activisation of selection
913 * of their sub-shapes (with opened local context for OCC viewer)
915 //=================================================================
916 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
918 SUIT_Session* session = SUIT_Session::session();
919 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
923 LightApp_SelectionMgr* sm = app->selectionMgr();
925 // remove all filters from selection
928 SALOME_View* vf = GetActiveView();
930 if (!theIO.IsNull() && !vf->isVisible(theIO))
932 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
933 vf->LocalSelection( prs, theMode );
934 delete prs; // delete presentation because displayer is its owner
938 //=================================================================
940 * GEOM_Displayer::globalSelection
941 * Activate selection of CAD shapes without activisation of selection
942 * of their sub-shapes (without opened local context for OCC viewer)
944 //=================================================================
945 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
947 TColStd_MapOfInteger aModes;
948 aModes.Add( theMode );
949 GlobalSelection( aModes, update );
952 //=================================================================
954 * GEOM_Displayer::globalSelection
955 * Activate selection of CAD shapes without activisation of selection
956 * of their sub-shapes (without opened local context for OCC viewer)
958 //=================================================================
959 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
962 SUIT_Session* session = SUIT_Session::session();
963 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
967 SALOME_View* vf = GetActiveView();
971 // Close local context
972 vf->GlobalSelection( update );
974 // Set selection filters in accordance with current mode
975 LightApp_SelectionMgr* sm = app->selectionMgr();
979 // Remove from selection temporary objects if necessary
980 if ( !theModes.Contains( GEOM_PREVIEW ) )
981 clearTemporary( sm );
983 //@ aSel->ClearIndex();
987 // Remove filters from AIS_InteractiveContext
988 Handle(AIS_InteractiveContext) ic;
989 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
992 ic = viewer->getAISContext();
997 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1000 SUIT_SelectionFilter* aFilter;
1001 if ( theModes.Extent() == 1 )
1003 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1004 aFilter = getFilter( aMode );
1006 else if ( theModes.Extent() > 1 )
1008 TColStd_MapOfInteger aTopAbsModes;
1009 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1010 QPtrList<SUIT_SelectionFilter> aListOfFilters;
1011 for ( ; anIter.More(); anIter.Next() )
1013 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
1015 aListOfFilters.append( aFilter );
1018 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1025 sm->installFilter( aFilter );
1028 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1029 ic->AddFilter( anOCCFilter );
1034 //=================================================================
1036 * GEOM_Displayer::LocalSelection
1037 * Activate selection of CAD shapes with activisation of selection
1038 * of their sub-shapes (with opened local context for OCC viewer)
1040 //=================================================================
1041 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1043 SALOME_ListIteratorOfListIO Iter( theIOList );
1044 for ( ; Iter.More(); Iter.Next() )
1045 LocalSelection( Iter.Value(), theMode );
1048 //=================================================================
1050 * GEOM_Displayer::BeforeDisplay
1051 * Called before displaying of pars. Close local context
1052 * [ Reimplemented from SALOME_Displayer ]
1054 //=================================================================
1055 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1057 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1060 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1063 if ( ic->HasOpenedContext() )
1064 ic->CloseAllContexts();
1069 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1074 //=================================================================
1076 * GEOM_Displayer::SetColor
1077 * Set color for shape displaying. If it is equal -1 then default color is used.
1078 * Available values are from Quantity_NameOfColor enumeration
1080 //=================================================================
1081 void GEOM_Displayer::SetColor( const int color )
1088 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1092 int GEOM_Displayer::GetColor() const
1097 bool GEOM_Displayer::HasColor() const
1099 return myColor != -1;
1102 void GEOM_Displayer::UnsetColor()
1106 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1107 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1108 myShadingColor = SalomeApp_Tools::color( col );
1111 //=================================================================
1113 * GEOM_Displayer::SetWidth
1114 * Set width of shape displaying. If it is equal -1 then default width is used.
1116 //=================================================================
1117 void GEOM_Displayer::SetWidth( const double width )
1122 double GEOM_Displayer::GetWidth() const
1127 bool GEOM_Displayer::HasWidth() const
1129 return myWidth != -1;
1132 void GEOM_Displayer::UnsetWidth()
1137 //=================================================================
1139 * GEOM_Displayer::SetToActivate
1140 * This method is used for activisation/deactivisation of objects to be displayed
1142 //=================================================================
1143 void GEOM_Displayer::SetToActivate( const bool toActivate )
1145 myToActivate = toActivate;
1147 bool GEOM_Displayer::ToActivate() const
1149 return myToActivate;
1152 //=================================================================
1154 * GEOM_Displayer::clearTemporary
1155 * Removes from selection temporary objects
1157 //=================================================================
1158 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1160 SALOME_ListIO selected, toSelect;
1161 theSelMgr->selectedObjects( selected );
1163 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1164 Handle(SALOME_InteractiveObject) io = it.Value();
1165 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1166 toSelect.Append( it.Value() );
1169 theSelMgr->setSelectedObjects( toSelect, true );
1172 void GEOM_Displayer::SetName( const char* theName )
1177 void GEOM_Displayer::UnsetName()
1182 SalomeApp_Study* GEOM_Displayer::getStudy() const
1184 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1187 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1192 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1197 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1199 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1202 int GEOM_Displayer::SetDisplayMode( const int theMode )
1204 int aPrevMode = myDisplayMode;
1205 if ( theMode != -1 )
1206 myDisplayMode = theMode;
1209 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1210 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1215 int GEOM_Displayer::GetDisplayMode() const
1217 return myDisplayMode;
1220 int GEOM_Displayer::UnsetDisplayMode()
1222 int aPrevMode = myDisplayMode;
1223 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1224 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );