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_CompoundFilter.h"
37 #include "GEOM_PreviewFilter.h"
38 #include "GEOM_LogicalFilter.h"
39 #include "GEOM_OCCFilter.h"
41 #include "GEOM_Actor.h"
42 #include "GEOM_AssemblyBuilder.h"
43 #include "GEOM_AISShape.hxx"
44 #include "GEOM_AISVector.hxx"
45 #include "GEOM_AISTrihedron.hxx"
46 #include "GEOM_VTKTrihedron.hxx"
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ViewWindow.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_Tools.h>
52 #include <SUIT_ViewManager.h>
54 #include <SalomeApp_Study.h>
55 #include <SalomeApp_Application.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <SalomeApp_TypeFilter.h>
58 #include <SalomeApp_Tools.h>
60 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <SOCC_ViewModel.h>
66 #include <SVTK_ViewModel.h>
68 #include <SALOMEDSClient.hxx>
69 #include <SALOMEDSClient_SObject.hxx>
72 #include <AIS_Drawer.hxx>
73 #include <AIS_ListIteratorOfListOfInteractive.hxx>
74 #include <Prs3d_IsoAspect.hxx>
75 #include <Prs3d_PointAspect.hxx>
76 #include <Graphic3d_AspectMarker3d.hxx>
77 #include <StdSelect_TypeOfEdge.hxx>
78 #include <StdSelect_TypeOfFace.hxx>
79 #include <TopoDS_Face.hxx>
80 #include <BRep_Tool.hxx>
81 #include <Geom_Plane.hxx>
82 #include <Geom_Axis2Placement.hxx>
84 #include <TColStd_MapOfInteger.hxx>
85 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
86 #include <TopoDS_Iterator.hxx>
89 #include <vtkActorCollection.h>
90 #include <vtkProperty.h>
96 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
98 #include "GEOMImpl_Types.hxx"
102 //================================================================
103 // Function : getActiveStudy
104 // Purpose : Get active study, returns 0 if no open study frame
105 //================================================================
106 static inline SalomeApp_Study* getActiveStudy()
108 SUIT_Session* session = SUIT_Session::session();
109 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
111 return ( SalomeApp_Study* )app->activeStudy();
115 //================================================================
116 // Function : getTopAbsMode
117 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
118 // one from GEOMImpl_Types.h
119 //================================================================
120 static inline int getTopAbsMode( const int implType )
124 case GEOM_COMPOUND : return TopAbs_COMPOUND;
125 case GEOM_SOLID : return TopAbs_SOLID;
126 case GEOM_SHELL : return TopAbs_SHELL;
127 case GEOM_FACE : return TopAbs_FACE;
128 case GEOM_WIRE : return TopAbs_WIRE;
129 case GEOM_EDGE : return TopAbs_EDGE;
130 case GEOM_POINT : return TopAbs_VERTEX;
135 //================================================================
136 // Function : getFilter
137 // Purpose : Get filter corresponding to the type of object
138 // from GEOMImpl_Types.h
139 //================================================================
140 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
142 SUIT_SelectionFilter* aFilter;
144 int aTopAbsMode = getTopAbsMode( theMode );
145 if ( aTopAbsMode != -1 )
146 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
150 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
151 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
153 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
154 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
155 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
156 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
157 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
158 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
160 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
162 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
163 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
165 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
171 //================================================================
172 // Function : getComplexFilter
173 // Purpose : Get compound filter corresponding to the type of
174 // object from GEOMImpl_Types.h
175 //================================================================
176 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QValueList<int>* aSubShapes)
178 GEOM_CompoundFilter* aFilter;
180 if(aSubShapes != NULL ) {
181 aFilter = new GEOM_CompoundFilter(getStudy());
182 QValueList<int> aTopAbsTypes;
183 QValueList<int>::const_iterator it;
184 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
185 int topAbsMode = getTopAbsMode(*it);
186 if(topAbsMode != -1 )
187 aTopAbsTypes.append(topAbsMode);
189 aFilter->addSubTypes(aTopAbsTypes);
195 //================================================================
196 // Function : getEntry
198 //================================================================
199 static string getEntry( GEOM::GEOM_Object_ptr object )
201 SUIT_Session* session = SUIT_Session::session();
202 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
205 CORBA::String_var IOR = app->orb()->object_to_string( object );
206 if ( strcmp(IOR.in(), "") != 0 )
208 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
209 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
217 //================================================================
218 // Function : getName
220 //================================================================
221 static string getName( GEOM::GEOM_Object_ptr object )
223 SUIT_Session* session = SUIT_Session::session();
224 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
227 CORBA::String_var IOR = app->orb()->object_to_string( object );
228 if ( strcmp(IOR.in(), "") != 0 )
230 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
231 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
233 _PTR(GenericAttribute) anAttr;
235 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
237 _PTR(AttributeName) aNameAttr( anAttr );
238 return aNameAttr->Value();
246 //=================================================================
248 * GEOM_Displayer::GEOM_Displayer
251 //=================================================================
252 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
255 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
260 SUIT_Session* session = SUIT_Session::session();
261 SUIT_ResourceMgr* resMgr = session->resourceMgr();
263 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
264 myShadingColor = SalomeApp_Tools::color( col );
266 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
267 myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
268 myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
269 if(myScaleOfMarker < 1.0)
270 myScaleOfMarker = 1.0;
271 if(myScaleOfMarker > 7.)
272 myScaleOfMarker = 7.;
276 // This color is used for shape displaying. If it is equal -1 then
277 // default color is used.
283 // This parameter is used for activisation/deactivisation of objects to be displayed
288 //=================================================================
290 * GEOM_Displayer::~GEOM_Displayer
293 //=================================================================
294 GEOM_Displayer::~GEOM_Displayer()
298 //=================================================================
300 * GEOM_Displayer::Display
301 * Display interactive object in the current viewer
303 //=================================================================
304 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
305 const bool updateViewer,
306 SALOME_View* theViewFrame )
308 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
311 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
315 vf->BeforeDisplay( this );
317 vf->AfterDisplay( this );
322 delete prs; // delete presentation because displayer is its owner
327 //=================================================================
329 * GEOM_Displayer::Display
330 * This overloaded Display() method can be useful for operations
331 * not using dialog boxes.
333 //=================================================================
334 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
336 if ( theObj->_is_nil() )
339 string entry = getEntry( theObj );
341 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
346 //=================================================================
348 * GEOM_Displayer::Erase
349 * Erase interactive object in the current viewer
351 //=================================================================
352 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
354 const bool updateViewer,
355 SALOME_View* theViewFrame )
357 if ( theIO.IsNull() )
360 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
363 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
365 vf->Erase( prs, forced );
368 delete prs; // delete presentation because displayer is its owner
373 //=================================================================
375 * GEOM_Displayer::Erase
376 * Erase geometry object in the current viewer
378 //=================================================================
379 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
381 const bool updateViewer )
383 string entry = getEntry( theObj );
386 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
387 forced, updateViewer);
391 //=================================================================
393 * GEOM_Displayer::Redisplay
394 * Redisplay (erase and then display again) interactive object
395 * in the current viewer
397 //=================================================================
398 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
399 const bool updateViewer )
401 // Remove the object permanently (<forced> == true)
402 SUIT_Session* ses = SUIT_Session::session();
403 SUIT_Application* app = ses->activeApplication();
406 SUIT_Desktop* desk = app->desktop();
407 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
408 SUIT_ViewWindow* wnd;
409 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
411 SUIT_ViewManager* vman = wnd->getViewManager();
414 SUIT_ViewModel* vmodel = vman->getViewModel();
417 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
420 if ( view->isVisible( theIO ) || view == GetActiveView() )
422 Erase( theIO, true, false, view );
423 Display( theIO, updateViewer, view );
432 //=================================================================
434 * GEOM_Displayer::Display
435 * Calls Display() method for each object in the given list
437 //=================================================================
438 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
440 SALOME_ListIteratorOfListIO Iter( theIOList );
441 for ( ; Iter.More(); Iter.Next() ) {
442 Display( Iter.Value(), false );
448 //=================================================================
450 * GEOM_Displayer::Erase
451 * Calls Erase() method for each object in the given list
453 //=================================================================
454 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
456 const bool updateViewer )
458 SALOME_ListIteratorOfListIO Iter( theIOList );
459 for ( ; Iter.More(); Iter.Next() )
460 Erase( Iter.Value(), forced, false );
466 //=================================================================
468 * GEOM_Displayer::Redisplay
469 * Calls Redisplay() method for each object in the given list
471 //=================================================================
472 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
474 SALOME_ListIteratorOfListIO Iter( theIOList );
475 for ( ; Iter.More(); Iter.Next() )
476 Redisplay( Iter.Value(), false );
482 //=================================================================
484 * GEOM_Displayer::Update
485 * Update OCC presentaion
486 * [ Reimplemented from SALOME_Displayer ]
488 //=================================================================
489 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
491 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
495 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
497 TopoDS_Face aFace = TopoDS::Face( myShape );
498 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
499 if ( !aPlane.IsNull() )
501 gp_Ax3 aPos = aPlane->Pln().Position();
502 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
504 Handle(GEOM_AISTrihedron) aTrh;
506 if ( occPrs->IsNull() )
508 aTrh = new GEOM_AISTrihedron( aPlc );
511 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
514 aTrh->SetWidth( GetWidth() );
516 if ( !myIO.IsNull() )
519 aTrh->SetOwner( myIO );
522 occPrs->AddObject( aTrh );
526 AIS_ListOfInteractive aList;
527 occPrs->GetObjects( aList );
528 AIS_ListIteratorOfListOfInteractive anIter( aList );
529 for ( ; anIter.More(); anIter.Next() )
531 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
532 if ( !aTrh.IsNull() )
534 aTrh->SetComponent( aPlc );
540 occPrs->SetToActivate( ToActivate() );
545 // if presentation is empty we try to create new one
546 if ( occPrs->IsNull() )
548 if ( !myShape.IsNull() )
550 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
551 Handle(GEOM_AISShape) AISShape;
552 if (myType == GEOM_VECTOR)
553 AISShape = new GEOM_AISVector (myShape, "");
555 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
556 !TopoDS_Iterator(myShape).More())
557 return;// NPAL15983 (Bug when displaying empty groups)
558 AISShape = new GEOM_AISShape (myShape, "");
560 // Temporary staff: vertex must be infinite for correct visualization
561 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
563 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
564 AISShape->SetDisplayMode( myDisplayMode );
565 AISShape->SetShadingColor( myShadingColor );
567 // Set color and number for iso lines
568 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
569 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
570 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
571 Quantity_Color aColor = SalomeApp_Tools::color( col );
572 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
573 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
575 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
576 anAspect->SetNumber( anUIsoNumber );
577 anAspect->SetColor( aColor );
578 AISShape->Attributes()->SetUIsoAspect( anAspect );
580 anAspect = AISShape->Attributes()->VIsoAspect();
581 anAspect->SetNumber( aVIsoNumber );
582 anAspect->SetColor( aColor );
583 AISShape->Attributes()->SetVIsoAspect( anAspect );
587 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
588 if ( myShape.ShapeType() == TopAbs_VERTEX )
590 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
591 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
592 anAspect->SetScale( myScaleOfMarker );
593 anAspect->SetTypeOfMarker( myTypeOfMarker );
594 AISShape->Attributes()->SetPointAspect( anAspect );
599 if ( myShape.ShapeType() == TopAbs_VERTEX )
601 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
602 aColor = SalomeApp_Tools::color( col );
604 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
605 anAspect->SetColor( aColor );
606 anAspect->SetScale( myScaleOfMarker );
607 anAspect->SetTypeOfMarker( myTypeOfMarker );
608 AISShape->Attributes()->SetPointAspect( anAspect );
613 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
614 aColor = SalomeApp_Tools::color( col );
616 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
617 anAspect->SetColor( aColor );
618 AISShape->Attributes()->SetLineAspect( anAspect );
620 // Set unfree boundaries aspect
621 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
622 anAspect->SetColor( aColor );
623 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
625 // Set free boundaries aspect
626 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
627 aColor = SalomeApp_Tools::color( col );
629 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
630 anAspect->SetColor( aColor );
631 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
634 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
635 aColor = SalomeApp_Tools::color( col );
637 anAspect = AISShape->Attributes()->WireAspect();
638 anAspect->SetColor( aColor );
639 AISShape->Attributes()->SetWireAspect( anAspect );
641 // bug [SALOME platform 0019868]
642 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
643 AISShape->SetOwnDeviationAngle( 10*PI/180 );
648 AISShape->SetWidth( GetWidth() );
650 if ( !myIO.IsNull() )
652 AISShape->setIO( myIO );
653 AISShape->SetOwner( myIO );
655 else if ( !myName.empty() )
657 // Workaround to allow selection of temporary objects
658 static int tempId = 0;
660 sprintf( buf, "TEMP_%d", tempId++ );
661 Handle( SALOME_InteractiveObject ) anObj =
662 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
663 AISShape->setIO( anObj );
664 AISShape->SetOwner( anObj );
667 // Get color from GEOM_Object
668 SUIT_Session* session = SUIT_Session::session();
669 SUIT_Application* app = session->activeApplication();
672 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
675 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
676 if ( !anIO.IsNull() )
678 _PTR(SObject) SO ( study->studyDS()->FindObjectID( anIO->getEntry() ) );
681 // get CORBA reference to data object
682 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
683 if ( !CORBA::is_nil( object ) )
685 // downcast to GEOM object
686 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
687 if ( !aGeomObject->_is_nil() )
689 SALOMEDS::Color aSColor = aGeomObject->GetColor();
690 bool hasColor = aSColor.R > 0 || aSColor.G > 0 || aSColor.B > 0;
691 if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group
693 GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
694 GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() );
695 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject );
696 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
698 QValueList<SALOMEDS::Color> aReservedColors;
700 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
701 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
702 if ( strcmp(IOR.in(), "") != 0 )
704 _PTR(Study) aStudy = study->studyDS();
705 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( string(IOR) ) );
706 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
707 for( ; it->More(); it->Next() )
709 _PTR(SObject) aChildSObject( it->Value() );
710 GEOM::GEOM_Object_var aChildObject =
711 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
712 if( CORBA::is_nil( aChildObject ) )
715 if( aChildObject->GetType() != GEOM_GROUP )
718 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
719 aReservedColors.append( aReservedColor );
723 aSColor = getUniqueColor( aReservedColors );
730 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
731 AISShape->SetColor( aQuanColor );
732 AISShape->SetShadingColor( aQuanColor );
741 // AISShape->SetName(???); ??? necessary to set name ???
742 occPrs->AddObject( AISShape );
744 // In accordance with ToActivate() value object will be activated/deactivated
745 // when it will be displayed
746 occPrs->SetToActivate( ToActivate() );
749 // if presentation is found -> set again shape for it
752 if ( !myShape.IsNull() )
754 AIS_ListOfInteractive IOList;
755 occPrs->GetObjects( IOList );
756 AIS_ListIteratorOfListOfInteractive Iter( IOList );
757 for ( ; Iter.More(); Iter.Next() )
759 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
760 if ( AISShape.IsNull() )
762 if ( AISShape->Shape() != myShape )
764 AISShape->Set( myShape );
765 AISShape->UpdateSelection();
766 AISShape->SetToUpdate();
768 if ( !myIO.IsNull() )
770 AISShape->setIO( myIO );
771 AISShape->SetOwner( myIO );
779 //=================================================================
781 * GEOM_Displayer::Update
782 * Update VTK presentaion
783 * [ Reimplemented from SALOME_Displayer ]
785 //=================================================================
786 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
788 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
789 if ( !vtkPrs || myShape.IsNull() )
792 vtkActorCollection* theActors = 0;
794 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
796 myToActivate = false;
797 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
801 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
802 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
805 Handle(Geom_Plane) aPlane =
806 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
807 if ( aPlane.IsNull() )
810 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
811 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
813 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
814 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
816 vtkPrs->AddObject( aTrh );
818 theActors = vtkActorCollection::New();
819 theActors->AddItem( aTrh );
823 bool isVector = (myType == GEOM_VECTOR);
824 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
827 theActors->InitTraversal();
829 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
831 vtkProperty* aProp = 0;
833 if ( HasColor() || HasWidth() )
835 aProp = vtkProperty::New();
836 aProp->SetRepresentationToWireframe();
841 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
842 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
847 aProp->SetLineWidth( GetWidth() );
850 while ( anActor != NULL )
852 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
854 GActor->setIO( myIO );
858 GActor->SetProperty( aProp );
859 GActor->SetPreviewProperty( aProp );
861 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
862 if ( aGeomGActor != 0 )
864 aGeomGActor->SetShadingProperty( aProp );
865 aGeomGActor->SetWireframeProperty( aProp );
870 GActor->PickableOn();
872 GActor->PickableOff();
874 vtkPrs->AddObject( GActor );
876 anActor = (vtkActor*)theActors->GetNextActor();
885 //=================================================================
887 * GEOM_Displayer::BuildPrs
888 * Build presentation accordint to the current viewer type
890 //=================================================================
891 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
893 if ( theObj->_is_nil() )
896 myViewFrame = GetActiveView();
897 if ( myViewFrame == 0 )
900 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
905 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
906 myType = theObj->GetType();
908 // Update presentation
914 //=================================================================
916 * GEOM_Displayer::BuildPrs
917 * Build presentation accordint to the current viewer type
919 //=================================================================
920 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
922 myViewFrame = GetActiveView();
923 if ( theShape.IsNull() || myViewFrame == 0 )
926 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
931 setShape( theShape );
939 //=================================================================
941 * GEOM_Displayer::buildPresentation
942 * Builds/finds object's presentation for the current viewer
943 * Calls corresponding Update() method by means of double dispatch
946 //=================================================================
947 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
948 SALOME_View* theViewFrame )
953 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
957 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
960 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
961 theIO->setEntry( entry.latin1() );
962 if ( !theIO.IsNull() )
964 // set interactive object
966 // Find SOBject (because shape should be published previously)
967 SUIT_Session* session = SUIT_Session::session();
968 SUIT_Application* app = session->activeApplication();
971 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
974 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
977 // get CORBA reference to data object
978 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
979 if ( !CORBA::is_nil( object ) )
981 // downcast to GEOM object
982 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
983 if ( !GeomObject->_is_nil() )
986 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
987 myType = GeomObject->GetType();
994 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1000 //=================================================================
1002 * GEOM_Displayer::internalReset
1003 * Resets internal data
1006 //=================================================================
1007 void GEOM_Displayer::internalReset()
1013 //=================================================================
1015 * GEOM_Displayer::LocalSelection
1016 * Activate selection of CAD shapes with activisation of selection
1017 * of their sub-shapes (with opened local context for OCC viewer)
1019 //=================================================================
1020 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1022 SUIT_Session* session = SUIT_Session::session();
1023 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1027 LightApp_SelectionMgr* sm = app->selectionMgr();
1029 // remove all filters from selection
1032 SALOME_View* vf = GetActiveView();
1034 if (!theIO.IsNull() && !vf->isVisible(theIO))
1036 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1037 vf->LocalSelection( prs, theMode );
1038 delete prs; // delete presentation because displayer is its owner
1042 //=================================================================
1044 * GEOM_Displayer::globalSelection
1045 * Activate selection of CAD shapes without activisation of selection
1046 * of their sub-shapes (without opened local context for OCC viewer)
1048 //=================================================================
1049 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1051 TColStd_MapOfInteger aModes;
1052 aModes.Add( theMode );
1053 GlobalSelection( aModes, update );
1056 //=================================================================
1058 * GEOM_Displayer::globalSelection
1059 * Activate selection of CAD shapes without activisation of selection
1060 * of their sub-shapes (without opened local context for OCC viewer)
1062 //=================================================================
1063 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1064 const bool update, const QValueList<int>* theSubShapes)
1066 SUIT_Session* session = SUIT_Session::session();
1067 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1071 SALOME_View* vf = GetActiveView();
1075 // Close local context
1076 vf->GlobalSelection( update );
1078 // Set selection filters in accordance with current mode
1079 LightApp_SelectionMgr* sm = app->selectionMgr();
1083 // Remove from selection temporary objects if necessary
1084 if ( !theModes.Contains( GEOM_PREVIEW ) )
1085 clearTemporary( sm );
1087 //@ aSel->ClearIndex();
1091 // Remove filters from AIS_InteractiveContext
1092 Handle(AIS_InteractiveContext) ic;
1093 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1096 ic = viewer->getAISContext();
1098 ic->RemoveFilters();
1101 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1104 SUIT_SelectionFilter* aFilter;
1105 if ( theModes.Extent() == 1 )
1107 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1109 if(aMode == GEOM_COMPOUNDFILTER)
1110 aFilter = getComplexFilter(theSubShapes);
1112 aFilter = getFilter( aMode );
1114 else if ( theModes.Extent() > 1 )
1116 TColStd_MapOfInteger aTopAbsModes;
1117 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1118 QPtrList<SUIT_SelectionFilter> aListOfFilters;
1119 for ( ; anIter.More(); anIter.Next() )
1121 SUIT_SelectionFilter* aFilter;
1122 int aMode = anIter.Key();
1123 if(aMode == GEOM_COMPOUNDFILTER)
1124 aFilter = getComplexFilter(theSubShapes);
1126 aFilter = getFilter( aMode );
1129 aListOfFilters.append( aFilter );
1132 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1139 sm->installFilter( aFilter );
1142 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1143 ic->AddFilter( anOCCFilter );
1148 //=================================================================
1150 * GEOM_Displayer::LocalSelection
1151 * Activate selection of CAD shapes with activisation of selection
1152 * of their sub-shapes (with opened local context for OCC viewer)
1154 //=================================================================
1155 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1157 SALOME_ListIteratorOfListIO Iter( theIOList );
1158 for ( ; Iter.More(); Iter.Next() )
1159 LocalSelection( Iter.Value(), theMode );
1162 //=================================================================
1164 * GEOM_Displayer::BeforeDisplay
1165 * Called before displaying of pars. Close local context
1166 * [ Reimplemented from SALOME_Displayer ]
1168 //=================================================================
1169 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1171 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1174 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1177 if ( ic->HasOpenedContext() )
1178 ic->CloseAllContexts();
1183 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1188 //=================================================================
1190 * GEOM_Displayer::SetColor
1191 * Set color for shape displaying. If it is equal -1 then default color is used.
1192 * Available values are from Quantity_NameOfColor enumeration
1194 //=================================================================
1195 void GEOM_Displayer::SetColor( const int color )
1202 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1206 int GEOM_Displayer::GetColor() const
1211 bool GEOM_Displayer::HasColor() const
1213 return myColor != -1;
1216 void GEOM_Displayer::UnsetColor()
1220 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1221 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1222 myShadingColor = SalomeApp_Tools::color( col );
1225 //=================================================================
1227 * GEOM_Displayer::SetWidth
1228 * Set width of shape displaying. If it is equal -1 then default width is used.
1230 //=================================================================
1231 void GEOM_Displayer::SetWidth( const double width )
1236 double GEOM_Displayer::GetWidth() const
1241 bool GEOM_Displayer::HasWidth() const
1243 return myWidth != -1;
1246 void GEOM_Displayer::UnsetWidth()
1251 //=================================================================
1253 * GEOM_Displayer::SetToActivate
1254 * This method is used for activisation/deactivisation of objects to be displayed
1256 //=================================================================
1257 void GEOM_Displayer::SetToActivate( const bool toActivate )
1259 myToActivate = toActivate;
1261 bool GEOM_Displayer::ToActivate() const
1263 return myToActivate;
1266 //=================================================================
1268 * GEOM_Displayer::clearTemporary
1269 * Removes from selection temporary objects
1271 //=================================================================
1272 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1274 SALOME_ListIO selected, toSelect;
1275 theSelMgr->selectedObjects( selected );
1277 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1278 Handle(SALOME_InteractiveObject) io = it.Value();
1279 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1280 toSelect.Append( it.Value() );
1283 theSelMgr->setSelectedObjects( toSelect, true );
1286 void GEOM_Displayer::SetName( const char* theName )
1291 void GEOM_Displayer::UnsetName()
1296 SalomeApp_Study* GEOM_Displayer::getStudy() const
1298 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1301 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1306 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1311 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1313 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1316 int GEOM_Displayer::SetDisplayMode( const int theMode )
1318 int aPrevMode = myDisplayMode;
1319 if ( theMode != -1 )
1320 myDisplayMode = theMode;
1323 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1324 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1329 int GEOM_Displayer::GetDisplayMode() const
1331 return myDisplayMode;
1334 int GEOM_Displayer::UnsetDisplayMode()
1336 int aPrevMode = myDisplayMode;
1337 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1338 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1342 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
1345 int aTolerance = 64;
1346 int anIterations = 0;
1352 if( anIterations % aPeriod == 0 )
1355 if( aTolerance < 1 )
1358 //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
1360 aHue = (int)( 360.0 * rand() / RAND_MAX );
1361 //cout << "Hue = " << aHue << endl;
1363 //cout << "Auto colors : ";
1365 QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1366 QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1367 for( ; it != itEnd; ++it )
1369 SALOMEDS::Color anAutoColor = *it;
1370 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1373 aQColor.getHsv( &h, &s, &v );
1375 if( abs( h - aHue ) < aTolerance )
1378 //cout << "break (diff = " << abs( h - aHue ) << ")";
1388 //cout << "Hue of the returned color = " << aHue << endl;
1390 aColor.setHsv( aHue, 255, 255 );
1392 SALOMEDS::Color aSColor;
1393 aSColor.R = (double)aColor.red() / 255.0;
1394 aSColor.G = (double)aColor.green() / 255.0;
1395 aSColor.B = (double)aColor.blue() / 255.0;