1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOM_Displayer.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "GEOM_Displayer.h"
28 #include "GeometryGUI.h"
30 #include <GEOM_TypeFilter.h>
31 #include <GEOM_EdgeFilter.h>
32 #include <GEOM_FaceFilter.h>
33 #include <GEOM_PreviewFilter.h>
34 #include <GEOM_LogicalFilter.h>
35 #include <GEOM_OCCFilter.h>
37 #include <GEOM_Actor.h>
38 #include <GEOM_AssemblyBuilder.h>
39 #include <GEOM_AISShape.hxx>
40 #include <GEOM_AISVector.hxx>
41 #include <GEOM_AISTrihedron.hxx>
42 #include <GEOM_VTKTrihedron.hxx>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ViewWindow.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_ResourceMgr.h>
50 #include <SalomeApp_Study.h>
51 #include <SalomeApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <SalomeApp_TypeFilter.h>
54 #include <SalomeApp_Tools.h>
56 #include <SALOME_ListIteratorOfListIO.hxx>
57 #include <SALOME_ListIO.hxx>
58 #include <SALOME_Prs.h>
61 #include <SOCC_ViewModel.h>
64 #include <SVTK_ViewModel.h>
67 #include <AIS_Drawer.hxx>
68 #include <AIS_ListIteratorOfListOfInteractive.hxx>
69 #include <Prs3d_IsoAspect.hxx>
70 #include <Prs3d_PointAspect.hxx>
71 #include <StdSelect_TypeOfEdge.hxx>
72 #include <StdSelect_TypeOfFace.hxx>
73 #include <TopoDS_Face.hxx>
74 #include <BRep_Tool.hxx>
75 #include <Geom_Plane.hxx>
76 #include <Geom_Axis2Placement.hxx>
78 #include <TColStd_MapOfInteger.hxx>
79 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
80 #include <TopoDS_Iterator.hxx>
83 #include <vtkActorCollection.h>
84 #include <vtkProperty.h>
87 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
89 #include <GEOMImpl_Types.hxx>
93 //================================================================
94 // Function : getActiveStudy
95 // Purpose : Get active study, returns 0 if no open study frame
96 //================================================================
97 static inline SalomeApp_Study* getActiveStudy()
99 SUIT_Session* session = SUIT_Session::session();
100 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
102 return ( SalomeApp_Study* )app->activeStudy();
106 //================================================================
107 // Function : getTopAbsMode
108 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
109 // one from GEOMImpl_Types.h
110 //================================================================
111 static inline int getTopAbsMode( const int implType )
115 case GEOM_COMPOUND : return TopAbs_COMPOUND;
116 case GEOM_SOLID : return TopAbs_SOLID;
117 case GEOM_SHELL : return TopAbs_SHELL;
118 case GEOM_FACE : return TopAbs_FACE;
119 case GEOM_WIRE : return TopAbs_WIRE;
120 case GEOM_EDGE : return TopAbs_EDGE;
121 case GEOM_POINT : return TopAbs_VERTEX;
126 //================================================================
127 // Function : getFilter
128 // Purpose : Get filter corresponding to the type of object
129 // from GEOMImpl_Types.h
130 //================================================================
131 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
133 SUIT_SelectionFilter* aFilter;
135 int aTopAbsMode = getTopAbsMode( theMode );
136 if ( aTopAbsMode != -1 )
137 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
141 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
142 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
144 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
145 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
146 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
147 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
148 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
149 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
151 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
153 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
154 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
156 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
162 //================================================================
163 // Function : getEntry
165 //================================================================
166 static string getEntry( GEOM::GEOM_Object_ptr object )
168 SUIT_Session* session = SUIT_Session::session();
169 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
172 CORBA::String_var IOR = app->orb()->object_to_string( object );
173 if ( strcmp(IOR.in(), "") != 0 )
175 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
176 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
184 //================================================================
185 // Function : getName
187 //================================================================
188 static string getName( GEOM::GEOM_Object_ptr object )
190 SUIT_Session* session = SUIT_Session::session();
191 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
194 CORBA::String_var IOR = app->orb()->object_to_string( object );
195 if ( strcmp(IOR.in(), "") != 0 )
197 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
198 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
200 _PTR(GenericAttribute) anAttr;
202 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
204 _PTR(AttributeName) aNameAttr( anAttr );
205 return aNameAttr->Value();
213 //=================================================================
215 * GEOM_Displayer::GEOM_Displayer
218 //=================================================================
219 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
222 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
227 SUIT_Session* session = SUIT_Session::session();
228 SUIT_ResourceMgr* resMgr = session->resourceMgr();
230 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
231 myShadingColor = SalomeApp_Tools::color( col );
233 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
234 myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
235 myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
236 if(myScaleOfMarker < 1.0)
237 myScaleOfMarker = 1.0;
238 if(myScaleOfMarker > 7.)
239 myScaleOfMarker = 7.;
243 // This color is used for shape displaying. If it is equal -1 then
244 // default color is used.
250 // This parameter is used for activisation/deactivisation of objects to be displayed
255 //=================================================================
257 * GEOM_Displayer::~GEOM_Displayer
260 //=================================================================
261 GEOM_Displayer::~GEOM_Displayer()
265 //=================================================================
267 * GEOM_Displayer::Display
268 * Display interactive object in the current viewer
270 //=================================================================
271 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
272 const bool updateViewer,
273 SALOME_View* theViewFrame )
275 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
278 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
282 vf->BeforeDisplay( this );
284 vf->AfterDisplay( this );
289 delete prs; // delete presentation because displayer is its owner
294 //=================================================================
296 * GEOM_Displayer::Display
297 * This overloaded Display() method can be useful for operations
298 * not using dialog boxes.
300 //=================================================================
301 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
303 if ( theObj->_is_nil() )
306 string entry = getEntry( theObj );
308 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
313 //=================================================================
315 * GEOM_Displayer::Erase
316 * Erase interactive object in the current viewer
318 //=================================================================
319 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
321 const bool updateViewer,
322 SALOME_View* theViewFrame )
324 if ( theIO.IsNull() )
327 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
330 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
332 vf->Erase( prs, forced );
335 delete prs; // delete presentation because displayer is its owner
340 //=================================================================
342 * GEOM_Displayer::Erase
343 * Erase geometry object in the current viewer
345 //=================================================================
346 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
348 const bool updateViewer )
350 string entry = getEntry( theObj );
353 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
354 forced, updateViewer);
358 //=================================================================
360 * GEOM_Displayer::Redisplay
361 * Redisplay (erase and then display again) interactive object
362 * in the current viewer
364 //=================================================================
365 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
366 const bool updateViewer )
368 // Remove the object permanently (<forced> == true)
369 SUIT_Session* ses = SUIT_Session::session();
370 SUIT_Application* app = ses->activeApplication();
373 SUIT_Desktop* desk = app->desktop();
374 QList<SUIT_ViewWindow*> wnds = desk->windows();
375 SUIT_ViewWindow* wnd;
376 QListIterator<SUIT_ViewWindow*> it( wnds );
377 while ( it.hasNext() && (wnd = it.next()) )
379 SUIT_ViewManager* vman = wnd->getViewManager();
382 SUIT_ViewModel* vmodel = vman->getViewModel();
385 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
388 if ( view->isVisible( theIO ) || view == GetActiveView() )
390 Erase( theIO, true, false, view );
391 Display( theIO, updateViewer, view );
400 //=================================================================
402 * GEOM_Displayer::Display
403 * Calls Display() method for each object in the given list
405 //=================================================================
406 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
408 SALOME_ListIteratorOfListIO Iter( theIOList );
409 for ( ; Iter.More(); Iter.Next() ) {
410 Display( Iter.Value(), false );
416 //=================================================================
418 * GEOM_Displayer::Erase
419 * Calls Erase() method for each object in the given list
421 //=================================================================
422 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
424 const bool updateViewer )
426 SALOME_ListIteratorOfListIO Iter( theIOList );
427 for ( ; Iter.More(); Iter.Next() )
428 Erase( Iter.Value(), forced, false );
434 //=================================================================
436 * GEOM_Displayer::Redisplay
437 * Calls Redisplay() method for each object in the given list
439 //=================================================================
440 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
442 SALOME_ListIteratorOfListIO Iter( theIOList );
443 for ( ; Iter.More(); Iter.Next() )
444 Redisplay( Iter.Value(), false );
450 //=================================================================
452 * GEOM_Displayer::Update
453 * Update OCC presentaion
454 * [ Reimplemented from SALOME_Displayer ]
456 //=================================================================
457 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
459 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
463 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
465 TopoDS_Face aFace = TopoDS::Face( myShape );
466 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
467 if ( !aPlane.IsNull() )
469 gp_Ax3 aPos = aPlane->Pln().Position();
470 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
472 Handle(GEOM_AISTrihedron) aTrh;
474 if ( occPrs->IsNull() )
476 aTrh = new GEOM_AISTrihedron( aPlc );
479 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
482 aTrh->SetWidth( GetWidth() );
484 if ( !myIO.IsNull() )
487 aTrh->SetOwner( myIO );
490 occPrs->AddObject( aTrh );
494 AIS_ListOfInteractive aList;
495 occPrs->GetObjects( aList );
496 AIS_ListIteratorOfListOfInteractive anIter( aList );
497 for ( ; anIter.More(); anIter.Next() )
499 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
500 if ( !aTrh.IsNull() )
502 aTrh->SetComponent( aPlc );
508 occPrs->SetToActivate( ToActivate() );
513 // if presentation is empty we try to create new one
514 if ( occPrs->IsNull() )
516 if ( !myShape.IsNull() )
518 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
519 Handle(GEOM_AISShape) AISShape;
520 if (myType == GEOM_VECTOR)
521 AISShape = new GEOM_AISVector (myShape, "");
523 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
524 !TopoDS_Iterator(myShape).More())
525 return;// NPAL15983 (Bug when displaying empty groups)
526 AISShape = new GEOM_AISShape (myShape, "");
528 // Temporary staff: vertex must be infinite for correct visualization
529 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
531 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
532 AISShape->SetDisplayMode( myDisplayMode );
533 AISShape->SetShadingColor( myShadingColor );
535 // Set color and number for iso lines
536 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
537 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
538 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
539 Quantity_Color aColor = SalomeApp_Tools::color( col );
540 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
541 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
543 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
544 anAspect->SetNumber( anUIsoNumber );
545 anAspect->SetColor( aColor );
546 AISShape->Attributes()->SetUIsoAspect( anAspect );
548 anAspect = AISShape->Attributes()->VIsoAspect();
549 anAspect->SetNumber( aVIsoNumber );
550 anAspect->SetColor( aColor );
551 AISShape->Attributes()->SetVIsoAspect( anAspect );
555 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
556 if ( myShape.ShapeType() == TopAbs_VERTEX )
558 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
559 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
560 anAspect->SetScale( myScaleOfMarker );
561 anAspect->SetTypeOfMarker( myTypeOfMarker );
562 AISShape->Attributes()->SetPointAspect( anAspect );
567 if ( myShape.ShapeType() == TopAbs_VERTEX )
569 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
570 aColor = SalomeApp_Tools::color( col );
572 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
573 anAspect->SetColor( aColor );
574 anAspect->SetScale( myScaleOfMarker );
575 anAspect->SetTypeOfMarker( myTypeOfMarker );
576 AISShape->Attributes()->SetPointAspect( anAspect );
581 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
582 aColor = SalomeApp_Tools::color( col );
584 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
585 anAspect->SetColor( aColor );
586 AISShape->Attributes()->SetLineAspect( anAspect );
588 // Set unfree boundaries aspect
589 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
590 anAspect->SetColor( aColor );
591 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
593 // Set free boundaries aspect
594 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
595 aColor = SalomeApp_Tools::color( col );
597 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
598 anAspect->SetColor( aColor );
599 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
602 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
603 aColor = SalomeApp_Tools::color( col );
605 anAspect = AISShape->Attributes()->WireAspect();
606 anAspect->SetColor( aColor );
607 AISShape->Attributes()->SetWireAspect( anAspect );
612 AISShape->SetWidth( GetWidth() );
614 if ( !myIO.IsNull() )
616 AISShape->setIO( myIO );
617 AISShape->SetOwner( myIO );
619 else if ( !myName.empty() )
621 // Workaround to allow selection of temporary objects
622 static int tempId = 0;
624 sprintf( buf, "TEMP_%d", tempId++ );
625 Handle( SALOME_InteractiveObject ) anObj =
626 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
627 AISShape->setIO( anObj );
628 AISShape->SetOwner( anObj );
631 // Get color from GEOM_Object
632 SUIT_Session* session = SUIT_Session::session();
633 SUIT_Application* app = session->activeApplication();
636 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
639 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
640 if ( !anIO.IsNull() )
642 _PTR(SObject) SO ( study->studyDS()->FindObjectID( anIO->getEntry() ) );
645 // get CORBA reference to data object
646 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
647 if ( !CORBA::is_nil( object ) )
649 // downcast to GEOM object
650 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
651 if ( !aGeomObject->_is_nil() )
653 SALOMEDS::Color aSColor = aGeomObject->GetColor();
654 bool hasColor = aSColor.R > 0 || aSColor.G > 0 || aSColor.B > 0;
655 if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group
657 GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
658 GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() );
659 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject );
660 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
662 QList<SALOMEDS::Color> aReservedColors;
664 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
665 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
666 if ( strcmp(IOR.in(), "") != 0 )
668 _PTR(Study) aStudy = study->studyDS();
669 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( string(IOR) ) );
670 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
671 for( ; it->More(); it->Next() )
673 _PTR(SObject) aChildSObject( it->Value() );
674 GEOM::GEOM_Object_var aChildObject =
675 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
676 if( CORBA::is_nil( aChildObject ) )
679 if( aChildObject->GetType() != GEOM_GROUP )
682 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
683 aReservedColors.append( aReservedColor );
687 aSColor = getUniqueColor( aReservedColors );
694 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
695 AISShape->SetColor( aQuanColor );
696 AISShape->SetShadingColor( aQuanColor );
705 // AISShape->SetName(???); ??? necessary to set name ???
706 occPrs->AddObject( AISShape );
708 // In accordance with ToActivate() value object will be activated/deactivated
709 // when it will be displayed
710 occPrs->SetToActivate( ToActivate() );
713 // if presentation is found -> set again shape for it
716 if ( !myShape.IsNull() )
718 AIS_ListOfInteractive IOList;
719 occPrs->GetObjects( IOList );
720 AIS_ListIteratorOfListOfInteractive Iter( IOList );
721 for ( ; Iter.More(); Iter.Next() )
723 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
724 if ( AISShape.IsNull() )
726 if ( AISShape->Shape() != myShape )
728 AISShape->Set( myShape );
729 AISShape->UpdateSelection();
730 AISShape->SetToUpdate();
732 if ( !myIO.IsNull() )
734 AISShape->setIO( myIO );
735 AISShape->SetOwner( myIO );
743 //=================================================================
745 * GEOM_Displayer::Update
746 * Update VTK presentaion
747 * [ Reimplemented from SALOME_Displayer ]
749 //=================================================================
750 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
752 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
753 if ( !vtkPrs || myShape.IsNull() )
756 vtkActorCollection* theActors = 0;
758 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
760 myToActivate = false;
761 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
765 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
766 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
769 Handle(Geom_Plane) aPlane =
770 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
771 if ( aPlane.IsNull() )
774 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
775 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
777 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
778 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
780 vtkPrs->AddObject( aTrh );
782 theActors = vtkActorCollection::New();
783 theActors->AddItem( aTrh );
787 bool isVector = (myType == GEOM_VECTOR);
788 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
791 theActors->InitTraversal();
793 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
795 vtkProperty* aProp = 0;
797 if ( HasColor() || HasWidth() )
799 aProp = vtkProperty::New();
800 aProp->SetRepresentationToWireframe();
805 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
806 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
811 aProp->SetLineWidth( GetWidth() );
814 while ( anActor != NULL )
816 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
818 GActor->setIO( myIO );
822 GActor->SetProperty( aProp );
823 GActor->SetPreviewProperty( aProp );
825 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
826 if ( aGeomGActor != 0 )
828 aGeomGActor->SetShadingProperty( aProp );
829 aGeomGActor->SetWireframeProperty( aProp );
834 GActor->PickableOn();
836 GActor->PickableOff();
838 vtkPrs->AddObject( GActor );
840 anActor = (vtkActor*)theActors->GetNextActor();
849 //=================================================================
851 * GEOM_Displayer::BuildPrs
852 * Build presentation accordint to the current viewer type
854 //=================================================================
855 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
857 if ( theObj->_is_nil() )
860 myViewFrame = GetActiveView();
861 if ( myViewFrame == 0 )
864 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
869 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
870 myType = theObj->GetType();
872 // Update presentation
878 //=================================================================
880 * GEOM_Displayer::BuildPrs
881 * Build presentation accordint to the current viewer type
883 //=================================================================
884 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
886 myViewFrame = GetActiveView();
887 if ( theShape.IsNull() || myViewFrame == 0 )
890 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
895 setShape( theShape );
903 //=================================================================
905 * GEOM_Displayer::buildPresentation
906 * Builds/finds object's presentation for the current viewer
907 * Calls corresponding Update() method by means of double dispatch
910 //=================================================================
911 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
912 SALOME_View* theViewFrame )
917 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
921 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
924 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
925 theIO->setEntry( entry.toLatin1().constData() );
926 if ( !theIO.IsNull() )
928 // set interactive object
930 // Find SOBject (because shape should be published previously)
931 SUIT_Session* session = SUIT_Session::session();
932 SUIT_Application* app = session->activeApplication();
935 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
938 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
941 // get CORBA reference to data object
942 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
943 if ( !CORBA::is_nil( object ) )
945 // downcast to GEOM object
946 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
947 if ( !GeomObject->_is_nil() )
950 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
951 myType = GeomObject->GetType();
958 UpdatePrs( prs ); // Update presentation by using of the double dispatch
964 //=================================================================
966 * GEOM_Displayer::internalReset
967 * Resets internal data
970 //=================================================================
971 void GEOM_Displayer::internalReset()
977 //=================================================================
979 * GEOM_Displayer::LocalSelection
980 * Activate selection of CAD shapes with activisation of selection
981 * of their sub-shapes (with opened local context for OCC viewer)
983 //=================================================================
984 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
986 SUIT_Session* session = SUIT_Session::session();
987 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
991 LightApp_SelectionMgr* sm = app->selectionMgr();
993 // remove all filters from selection
996 SALOME_View* vf = GetActiveView();
998 if (!theIO.IsNull() && !vf->isVisible(theIO))
1000 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1001 vf->LocalSelection( prs, theMode );
1002 delete prs; // delete presentation because displayer is its owner
1006 //=================================================================
1008 * GEOM_Displayer::globalSelection
1009 * Activate selection of CAD shapes without activisation of selection
1010 * of their sub-shapes (without opened local context for OCC viewer)
1012 //=================================================================
1013 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1015 TColStd_MapOfInteger aModes;
1016 aModes.Add( theMode );
1017 GlobalSelection( aModes, update );
1020 //=================================================================
1022 * GEOM_Displayer::globalSelection
1023 * Activate selection of CAD shapes without activisation of selection
1024 * of their sub-shapes (without opened local context for OCC viewer)
1026 //=================================================================
1027 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1030 SUIT_Session* session = SUIT_Session::session();
1031 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1035 SALOME_View* vf = GetActiveView();
1039 // Close local context
1040 vf->GlobalSelection( update );
1042 // Set selection filters in accordance with current mode
1043 LightApp_SelectionMgr* sm = app->selectionMgr();
1047 // Remove from selection temporary objects if necessary
1048 if ( !theModes.Contains( GEOM_PREVIEW ) )
1049 clearTemporary( sm );
1051 //@ aSel->ClearIndex();
1055 // Remove filters from AIS_InteractiveContext
1056 Handle(AIS_InteractiveContext) ic;
1057 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1060 ic = viewer->getAISContext();
1062 ic->RemoveFilters();
1065 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1068 SUIT_SelectionFilter* aFilter;
1069 if ( theModes.Extent() == 1 )
1071 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1072 aFilter = getFilter( aMode );
1074 else if ( theModes.Extent() > 1 )
1076 TColStd_MapOfInteger aTopAbsModes;
1077 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1078 QList<SUIT_SelectionFilter*> aListOfFilters;
1079 for ( ; anIter.More(); anIter.Next() )
1081 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
1083 aListOfFilters.append( aFilter );
1086 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1093 sm->installFilter( aFilter );
1096 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1097 ic->AddFilter( anOCCFilter );
1102 //=================================================================
1104 * GEOM_Displayer::LocalSelection
1105 * Activate selection of CAD shapes with activisation of selection
1106 * of their sub-shapes (with opened local context for OCC viewer)
1108 //=================================================================
1109 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1111 SALOME_ListIteratorOfListIO Iter( theIOList );
1112 for ( ; Iter.More(); Iter.Next() )
1113 LocalSelection( Iter.Value(), theMode );
1116 //=================================================================
1118 * GEOM_Displayer::BeforeDisplay
1119 * Called before displaying of pars. Close local context
1120 * [ Reimplemented from SALOME_Displayer ]
1122 //=================================================================
1123 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1125 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1128 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1131 if ( ic->HasOpenedContext() )
1132 ic->CloseAllContexts();
1137 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1142 //=================================================================
1144 * GEOM_Displayer::SetColor
1145 * Set color for shape displaying. If it is equal -1 then default color is used.
1146 * Available values are from Quantity_NameOfColor enumeration
1148 //=================================================================
1149 void GEOM_Displayer::SetColor( const int color )
1156 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1160 int GEOM_Displayer::GetColor() const
1165 bool GEOM_Displayer::HasColor() const
1167 return myColor != -1;
1170 void GEOM_Displayer::UnsetColor()
1174 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1175 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1176 myShadingColor = SalomeApp_Tools::color( col );
1179 //=================================================================
1181 * GEOM_Displayer::SetWidth
1182 * Set width of shape displaying. If it is equal -1 then default width is used.
1184 //=================================================================
1185 void GEOM_Displayer::SetWidth( const double width )
1190 double GEOM_Displayer::GetWidth() const
1195 bool GEOM_Displayer::HasWidth() const
1197 return myWidth != -1;
1200 void GEOM_Displayer::UnsetWidth()
1205 //=================================================================
1207 * GEOM_Displayer::SetToActivate
1208 * This method is used for activisation/deactivisation of objects to be displayed
1210 //=================================================================
1211 void GEOM_Displayer::SetToActivate( const bool toActivate )
1213 myToActivate = toActivate;
1215 bool GEOM_Displayer::ToActivate() const
1217 return myToActivate;
1220 //=================================================================
1222 * GEOM_Displayer::clearTemporary
1223 * Removes from selection temporary objects
1225 //=================================================================
1226 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1228 SALOME_ListIO selected, toSelect;
1229 theSelMgr->selectedObjects( selected );
1231 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1232 Handle(SALOME_InteractiveObject) io = it.Value();
1233 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1234 toSelect.Append( it.Value() );
1237 theSelMgr->setSelectedObjects( toSelect, true );
1240 void GEOM_Displayer::SetName( const char* theName )
1245 void GEOM_Displayer::UnsetName()
1250 SalomeApp_Study* GEOM_Displayer::getStudy() const
1252 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1255 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1260 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1265 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1267 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1270 int GEOM_Displayer::SetDisplayMode( const int theMode )
1272 int aPrevMode = myDisplayMode;
1273 if ( theMode != -1 )
1274 myDisplayMode = theMode;
1277 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1278 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1283 int GEOM_Displayer::GetDisplayMode() const
1285 return myDisplayMode;
1288 int GEOM_Displayer::UnsetDisplayMode()
1290 int aPrevMode = myDisplayMode;
1291 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1292 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1296 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1299 int aTolerance = 64;
1300 int anIterations = 0;
1306 if( anIterations % aPeriod == 0 )
1309 if( aTolerance < 1 )
1312 //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
1314 aHue = (int)( 360.0 * rand() / RAND_MAX );
1315 //cout << "Hue = " << aHue << endl;
1317 //cout << "Auto colors : ";
1319 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1320 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1321 for( ; it != itEnd; ++it )
1323 SALOMEDS::Color anAutoColor = *it;
1324 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1327 aQColor.getHsv( &h, &s, &v );
1329 if( abs( h - aHue ) < aTolerance )
1332 //cout << "break (diff = " << abs( h - aHue ) << ")";
1342 //cout << "Hue of the returned color = " << aHue << endl;
1344 aColor.setHsv( aHue, 255, 255 );
1346 SALOMEDS::Color aSColor;
1347 aSColor.R = (double)aColor.red() / 255.0;
1348 aSColor.G = (double)aColor.green() / 255.0;
1349 aSColor.B = (double)aColor.blue() / 255.0;