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_CompoundFilter.h>
34 #include <GEOM_PreviewFilter.h>
35 #include <GEOM_LogicalFilter.h>
36 #include <GEOM_OCCFilter.h>
38 #include <GEOM_Actor.h>
39 #include <GEOM_AssemblyBuilder.h>
40 #include <GEOM_AISShape.hxx>
41 #include <GEOM_AISVector.hxx>
42 #include <GEOM_AISTrihedron.hxx>
43 #include <GEOM_VTKTrihedron.hxx>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ViewWindow.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_ViewManager.h>
49 #include <SUIT_ResourceMgr.h>
51 #include <SalomeApp_Study.h>
52 #include <SalomeApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <SalomeApp_TypeFilter.h>
55 #include <SalomeApp_Tools.h>
57 #include <SALOME_ListIteratorOfListIO.hxx>
58 #include <SALOME_ListIO.hxx>
59 #include <SALOME_Prs.h>
62 #include <SOCC_ViewModel.h>
65 #include <SVTK_ViewModel.h>
68 #include <AIS_Drawer.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <Prs3d_IsoAspect.hxx>
71 #include <Prs3d_PointAspect.hxx>
72 #include <StdSelect_TypeOfEdge.hxx>
73 #include <StdSelect_TypeOfFace.hxx>
74 #include <TopoDS_Face.hxx>
75 #include <BRep_Tool.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_Axis2Placement.hxx>
79 #include <TColStd_MapOfInteger.hxx>
80 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
81 #include <TopoDS_Iterator.hxx>
84 #include <vtkActorCollection.h>
85 #include <vtkProperty.h>
88 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
90 #include <GEOMImpl_Types.hxx>
94 //================================================================
95 // Function : getActiveStudy
96 // Purpose : Get active study, returns 0 if no open study frame
97 //================================================================
98 static inline SalomeApp_Study* getActiveStudy()
100 SUIT_Session* session = SUIT_Session::session();
101 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
103 return ( SalomeApp_Study* )app->activeStudy();
107 //================================================================
108 // Function : getTopAbsMode
109 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
110 // one from GEOMImpl_Types.h
111 //================================================================
112 static inline int getTopAbsMode( const int implType )
116 case GEOM_COMPOUND : return TopAbs_COMPOUND;
117 case GEOM_SOLID : return TopAbs_SOLID;
118 case GEOM_SHELL : return TopAbs_SHELL;
119 case GEOM_FACE : return TopAbs_FACE;
120 case GEOM_WIRE : return TopAbs_WIRE;
121 case GEOM_EDGE : return TopAbs_EDGE;
122 case GEOM_POINT : return TopAbs_VERTEX;
127 //================================================================
128 // Function : getFilter
129 // Purpose : Get filter corresponding to the type of object
130 // from GEOMImpl_Types.h
131 //================================================================
132 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
134 SUIT_SelectionFilter* aFilter;
136 int aTopAbsMode = getTopAbsMode( theMode );
137 if ( aTopAbsMode != -1 )
138 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
142 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
143 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
145 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
146 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
147 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
148 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
149 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
150 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
152 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
154 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
155 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
157 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
163 //================================================================
164 // Function : getComplexFilter
165 // Purpose : Get compound filter corresponding to the type of
166 // object from GEOMImpl_Types.h
167 //================================================================
168 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
170 GEOM_CompoundFilter* aFilter;
172 if(aSubShapes != NULL ) {
173 aFilter = new GEOM_CompoundFilter(getStudy());
174 QList<int> aTopAbsTypes;
175 QList<int>::const_iterator it;
176 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
177 int topAbsMode = getTopAbsMode(*it);
178 if(topAbsMode != -1 )
179 aTopAbsTypes.append(topAbsMode);
181 aFilter->addSubTypes(aTopAbsTypes);
187 //================================================================
188 // Function : getEntry
190 //================================================================
191 static string getEntry( GEOM::GEOM_Object_ptr object )
193 SUIT_Session* session = SUIT_Session::session();
194 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
197 CORBA::String_var IOR = app->orb()->object_to_string( object );
198 if ( strcmp(IOR.in(), "") != 0 )
200 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
201 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
209 //================================================================
210 // Function : getName
212 //================================================================
213 static string getName( GEOM::GEOM_Object_ptr object )
215 SUIT_Session* session = SUIT_Session::session();
216 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
219 CORBA::String_var IOR = app->orb()->object_to_string( object );
220 if ( strcmp(IOR.in(), "") != 0 )
222 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
223 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
225 _PTR(GenericAttribute) anAttr;
227 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
229 _PTR(AttributeName) aNameAttr( anAttr );
230 return aNameAttr->Value();
238 //=================================================================
240 * GEOM_Displayer::GEOM_Displayer
243 //=================================================================
244 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
247 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
252 SUIT_Session* session = SUIT_Session::session();
253 SUIT_ResourceMgr* resMgr = session->resourceMgr();
255 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
256 myShadingColor = SalomeApp_Tools::color( col );
258 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
259 myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
260 myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
261 if(myScaleOfMarker < 1.0)
262 myScaleOfMarker = 1.0;
263 if(myScaleOfMarker > 7.)
264 myScaleOfMarker = 7.;
268 // This color is used for shape displaying. If it is equal -1 then
269 // default color is used.
275 // This parameter is used for activisation/deactivisation of objects to be displayed
280 //=================================================================
282 * GEOM_Displayer::~GEOM_Displayer
285 //=================================================================
286 GEOM_Displayer::~GEOM_Displayer()
290 //=================================================================
292 * GEOM_Displayer::Display
293 * Display interactive object in the current viewer
295 //=================================================================
296 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
297 const bool updateViewer,
298 SALOME_View* theViewFrame )
300 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
303 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
307 vf->BeforeDisplay( this );
309 vf->AfterDisplay( this );
314 delete prs; // delete presentation because displayer is its owner
319 //=================================================================
321 * GEOM_Displayer::Display
322 * This overloaded Display() method can be useful for operations
323 * not using dialog boxes.
325 //=================================================================
326 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
328 if ( theObj->_is_nil() )
331 string entry = getEntry( theObj );
333 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
338 //=================================================================
340 * GEOM_Displayer::Erase
341 * Erase interactive object in the current viewer
343 //=================================================================
344 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
346 const bool updateViewer,
347 SALOME_View* theViewFrame )
349 if ( theIO.IsNull() )
352 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
355 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
357 vf->Erase( prs, forced );
360 delete prs; // delete presentation because displayer is its owner
365 //=================================================================
367 * GEOM_Displayer::Erase
368 * Erase geometry object in the current viewer
370 //=================================================================
371 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
373 const bool updateViewer )
375 string entry = getEntry( theObj );
378 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
379 forced, updateViewer);
383 //=================================================================
385 * GEOM_Displayer::Redisplay
386 * Redisplay (erase and then display again) interactive object
387 * in the current viewer
389 //=================================================================
390 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
391 const bool updateViewer )
393 // Remove the object permanently (<forced> == true)
394 SUIT_Session* ses = SUIT_Session::session();
395 SUIT_Application* app = ses->activeApplication();
398 SUIT_Desktop* desk = app->desktop();
399 QList<SUIT_ViewWindow*> wnds = desk->windows();
400 SUIT_ViewWindow* wnd;
401 QListIterator<SUIT_ViewWindow*> it( wnds );
402 while ( it.hasNext() && (wnd = it.next()) )
404 SUIT_ViewManager* vman = wnd->getViewManager();
407 SUIT_ViewModel* vmodel = vman->getViewModel();
410 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
413 if ( view->isVisible( theIO ) || view == GetActiveView() )
415 Erase( theIO, true, false, view );
416 Display( theIO, updateViewer, view );
425 //=================================================================
427 * GEOM_Displayer::Display
428 * Calls Display() method for each object in the given list
430 //=================================================================
431 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
433 SALOME_ListIteratorOfListIO Iter( theIOList );
434 for ( ; Iter.More(); Iter.Next() ) {
435 Display( Iter.Value(), false );
441 //=================================================================
443 * GEOM_Displayer::Erase
444 * Calls Erase() method for each object in the given list
446 //=================================================================
447 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
449 const bool updateViewer )
451 SALOME_ListIteratorOfListIO Iter( theIOList );
452 for ( ; Iter.More(); Iter.Next() )
453 Erase( Iter.Value(), forced, false );
459 //=================================================================
461 * GEOM_Displayer::Redisplay
462 * Calls Redisplay() method for each object in the given list
464 //=================================================================
465 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
467 SALOME_ListIteratorOfListIO Iter( theIOList );
468 for ( ; Iter.More(); Iter.Next() )
469 Redisplay( Iter.Value(), false );
475 //=================================================================
477 * GEOM_Displayer::Update
478 * Update OCC presentaion
479 * [ Reimplemented from SALOME_Displayer ]
481 //=================================================================
482 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
484 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
488 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
490 TopoDS_Face aFace = TopoDS::Face( myShape );
491 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
492 if ( !aPlane.IsNull() )
494 gp_Ax3 aPos = aPlane->Pln().Position();
495 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
497 Handle(GEOM_AISTrihedron) aTrh;
499 if ( occPrs->IsNull() )
501 aTrh = new GEOM_AISTrihedron( aPlc );
504 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
507 aTrh->SetWidth( GetWidth() );
509 if ( !myIO.IsNull() )
512 aTrh->SetOwner( myIO );
515 occPrs->AddObject( aTrh );
519 AIS_ListOfInteractive aList;
520 occPrs->GetObjects( aList );
521 AIS_ListIteratorOfListOfInteractive anIter( aList );
522 for ( ; anIter.More(); anIter.Next() )
524 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
525 if ( !aTrh.IsNull() )
527 aTrh->SetComponent( aPlc );
533 occPrs->SetToActivate( ToActivate() );
538 // if presentation is empty we try to create new one
539 if ( occPrs->IsNull() )
541 if ( !myShape.IsNull() )
543 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
544 Handle(GEOM_AISShape) AISShape;
545 if (myType == GEOM_VECTOR)
546 AISShape = new GEOM_AISVector (myShape, "");
548 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
549 !TopoDS_Iterator(myShape).More())
550 return;// NPAL15983 (Bug when displaying empty groups)
551 AISShape = new GEOM_AISShape (myShape, "");
553 // Temporary staff: vertex must be infinite for correct visualization
554 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
556 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
557 AISShape->SetDisplayMode( myDisplayMode );
558 AISShape->SetShadingColor( myShadingColor );
560 // Set color and number for iso lines
561 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
562 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
563 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
564 Quantity_Color aColor = SalomeApp_Tools::color( col );
565 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
566 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
568 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
569 anAspect->SetNumber( anUIsoNumber );
570 anAspect->SetColor( aColor );
571 AISShape->Attributes()->SetUIsoAspect( anAspect );
573 anAspect = AISShape->Attributes()->VIsoAspect();
574 anAspect->SetNumber( aVIsoNumber );
575 anAspect->SetColor( aColor );
576 AISShape->Attributes()->SetVIsoAspect( anAspect );
580 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
581 if ( myShape.ShapeType() == TopAbs_VERTEX )
583 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
584 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
585 anAspect->SetScale( myScaleOfMarker );
586 anAspect->SetTypeOfMarker( myTypeOfMarker );
587 AISShape->Attributes()->SetPointAspect( anAspect );
592 if ( myShape.ShapeType() == TopAbs_VERTEX )
594 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
595 aColor = SalomeApp_Tools::color( col );
597 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
598 anAspect->SetColor( aColor );
599 anAspect->SetScale( myScaleOfMarker );
600 anAspect->SetTypeOfMarker( myTypeOfMarker );
601 AISShape->Attributes()->SetPointAspect( anAspect );
606 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
607 aColor = SalomeApp_Tools::color( col );
609 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
610 anAspect->SetColor( aColor );
611 AISShape->Attributes()->SetLineAspect( anAspect );
613 // Set unfree boundaries aspect
614 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
615 anAspect->SetColor( aColor );
616 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
618 // Set free boundaries aspect
619 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
620 aColor = SalomeApp_Tools::color( col );
622 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
623 anAspect->SetColor( aColor );
624 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
627 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
628 aColor = SalomeApp_Tools::color( col );
630 anAspect = AISShape->Attributes()->WireAspect();
631 anAspect->SetColor( aColor );
632 AISShape->Attributes()->SetWireAspect( anAspect );
634 // bug [SALOME platform 0019868]
635 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
636 AISShape->SetOwnDeviationAngle( 10*PI/180 );
641 AISShape->SetWidth( GetWidth() );
643 if ( !myIO.IsNull() )
645 AISShape->setIO( myIO );
646 AISShape->SetOwner( myIO );
648 else if ( !myName.empty() )
650 // Workaround to allow selection of temporary objects
651 static int tempId = 0;
653 sprintf( buf, "TEMP_%d", tempId++ );
654 Handle( SALOME_InteractiveObject ) anObj =
655 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
656 AISShape->setIO( anObj );
657 AISShape->SetOwner( anObj );
660 // Get color from GEOM_Object
661 SUIT_Session* session = SUIT_Session::session();
662 SUIT_Application* app = session->activeApplication();
665 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
668 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
669 if ( !anIO.IsNull() )
671 _PTR(SObject) SO ( study->studyDS()->FindObjectID( anIO->getEntry() ) );
674 // get CORBA reference to data object
675 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
676 if ( !CORBA::is_nil( object ) )
678 // downcast to GEOM object
679 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
680 if ( !aGeomObject->_is_nil() )
682 SALOMEDS::Color aSColor = aGeomObject->GetColor();
683 bool hasColor = aSColor.R > 0 || aSColor.G > 0 || aSColor.B > 0;
684 if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group
686 GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
687 GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() );
688 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject );
689 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
691 QList<SALOMEDS::Color> aReservedColors;
693 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
694 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
695 if ( strcmp(IOR.in(), "") != 0 )
697 _PTR(Study) aStudy = study->studyDS();
698 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( string(IOR) ) );
699 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
700 for( ; it->More(); it->Next() )
702 _PTR(SObject) aChildSObject( it->Value() );
703 GEOM::GEOM_Object_var aChildObject =
704 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
705 if( CORBA::is_nil( aChildObject ) )
708 if( aChildObject->GetType() != GEOM_GROUP )
711 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
712 aReservedColors.append( aReservedColor );
716 aSColor = getUniqueColor( aReservedColors );
723 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
724 AISShape->SetColor( aQuanColor );
725 AISShape->SetShadingColor( aQuanColor );
734 // AISShape->SetName(???); ??? necessary to set name ???
735 occPrs->AddObject( AISShape );
737 // In accordance with ToActivate() value object will be activated/deactivated
738 // when it will be displayed
739 occPrs->SetToActivate( ToActivate() );
742 // if presentation is found -> set again shape for it
745 if ( !myShape.IsNull() )
747 AIS_ListOfInteractive IOList;
748 occPrs->GetObjects( IOList );
749 AIS_ListIteratorOfListOfInteractive Iter( IOList );
750 for ( ; Iter.More(); Iter.Next() )
752 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
753 if ( AISShape.IsNull() )
755 if ( AISShape->Shape() != myShape )
757 AISShape->Set( myShape );
758 AISShape->UpdateSelection();
759 AISShape->SetToUpdate();
761 if ( !myIO.IsNull() )
763 AISShape->setIO( myIO );
764 AISShape->SetOwner( myIO );
772 //=================================================================
774 * GEOM_Displayer::Update
775 * Update VTK presentaion
776 * [ Reimplemented from SALOME_Displayer ]
778 //=================================================================
779 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
781 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
782 if ( !vtkPrs || myShape.IsNull() )
785 vtkActorCollection* theActors = 0;
787 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
789 myToActivate = false;
790 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
794 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
795 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
798 Handle(Geom_Plane) aPlane =
799 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
800 if ( aPlane.IsNull() )
803 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
804 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
806 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
807 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
809 vtkPrs->AddObject( aTrh );
811 theActors = vtkActorCollection::New();
812 theActors->AddItem( aTrh );
816 bool isVector = (myType == GEOM_VECTOR);
817 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
820 theActors->InitTraversal();
822 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
824 vtkProperty* aProp = 0;
826 if ( HasColor() || HasWidth() )
828 aProp = vtkProperty::New();
829 aProp->SetRepresentationToWireframe();
834 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
835 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
840 aProp->SetLineWidth( GetWidth() );
843 while ( anActor != NULL )
845 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
847 GActor->setIO( myIO );
851 GActor->SetProperty( aProp );
852 GActor->SetPreviewProperty( aProp );
854 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
855 if ( aGeomGActor != 0 )
857 aGeomGActor->SetShadingProperty( aProp );
858 aGeomGActor->SetWireframeProperty( aProp );
863 GActor->PickableOn();
865 GActor->PickableOff();
867 vtkPrs->AddObject( GActor );
869 anActor = (vtkActor*)theActors->GetNextActor();
878 //=================================================================
880 * GEOM_Displayer::BuildPrs
881 * Build presentation accordint to the current viewer type
883 //=================================================================
884 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
886 if ( theObj->_is_nil() )
889 myViewFrame = GetActiveView();
890 if ( myViewFrame == 0 )
893 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
898 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
899 myType = theObj->GetType();
901 // Update presentation
907 //=================================================================
909 * GEOM_Displayer::BuildPrs
910 * Build presentation accordint to the current viewer type
912 //=================================================================
913 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
915 myViewFrame = GetActiveView();
916 if ( theShape.IsNull() || myViewFrame == 0 )
919 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
924 setShape( theShape );
932 //=================================================================
934 * GEOM_Displayer::buildPresentation
935 * Builds/finds object's presentation for the current viewer
936 * Calls corresponding Update() method by means of double dispatch
939 //=================================================================
940 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
941 SALOME_View* theViewFrame )
946 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
950 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
953 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
954 theIO->setEntry( entry.toLatin1().constData() );
955 if ( !theIO.IsNull() )
957 // set interactive object
959 // Find SOBject (because shape should be published previously)
960 SUIT_Session* session = SUIT_Session::session();
961 SUIT_Application* app = session->activeApplication();
964 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
967 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
970 // get CORBA reference to data object
971 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
972 if ( !CORBA::is_nil( object ) )
974 // downcast to GEOM object
975 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
976 if ( !GeomObject->_is_nil() )
979 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
980 myType = GeomObject->GetType();
987 UpdatePrs( prs ); // Update presentation by using of the double dispatch
993 //=================================================================
995 * GEOM_Displayer::internalReset
996 * Resets internal data
999 //=================================================================
1000 void GEOM_Displayer::internalReset()
1006 //=================================================================
1008 * GEOM_Displayer::LocalSelection
1009 * Activate selection of CAD shapes with activisation of selection
1010 * of their sub-shapes (with opened local context for OCC viewer)
1012 //=================================================================
1013 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1015 SUIT_Session* session = SUIT_Session::session();
1016 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1020 LightApp_SelectionMgr* sm = app->selectionMgr();
1022 // remove all filters from selection
1025 SALOME_View* vf = GetActiveView();
1027 if (!theIO.IsNull() && !vf->isVisible(theIO))
1029 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1030 vf->LocalSelection( prs, theMode );
1031 delete prs; // delete presentation because displayer is its owner
1035 //=================================================================
1037 * GEOM_Displayer::globalSelection
1038 * Activate selection of CAD shapes without activisation of selection
1039 * of their sub-shapes (without opened local context for OCC viewer)
1041 //=================================================================
1042 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1044 TColStd_MapOfInteger aModes;
1045 aModes.Add( theMode );
1046 GlobalSelection( aModes, update );
1049 //=================================================================
1051 * GEOM_Displayer::globalSelection
1052 * Activate selection of CAD shapes without activisation of selection
1053 * of their sub-shapes (without opened local context for OCC viewer)
1055 //=================================================================
1056 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1057 const bool update, const QList<int>* theSubShapes )
1059 SUIT_Session* session = SUIT_Session::session();
1060 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1064 SALOME_View* vf = GetActiveView();
1068 // Close local context
1069 vf->GlobalSelection( update );
1071 // Set selection filters in accordance with current mode
1072 LightApp_SelectionMgr* sm = app->selectionMgr();
1076 // Remove from selection temporary objects if necessary
1077 if ( !theModes.Contains( GEOM_PREVIEW ) )
1078 clearTemporary( sm );
1080 //@ aSel->ClearIndex();
1084 // Remove filters from AIS_InteractiveContext
1085 Handle(AIS_InteractiveContext) ic;
1086 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1089 ic = viewer->getAISContext();
1091 ic->RemoveFilters();
1094 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1097 SUIT_SelectionFilter* aFilter;
1098 if ( theModes.Extent() == 1 )
1100 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1102 if ( aMode == GEOM_COMPOUNDFILTER )
1103 aFilter = getComplexFilter( theSubShapes );
1105 aFilter = getFilter( aMode );
1107 else if ( theModes.Extent() > 1 )
1109 TColStd_MapOfInteger aTopAbsModes;
1110 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1111 QList<SUIT_SelectionFilter*> aListOfFilters;
1112 for ( ; anIter.More(); anIter.Next() )
1114 SUIT_SelectionFilter* aFilter;
1115 int aMode = anIter.Key();
1116 if ( aMode == GEOM_COMPOUNDFILTER )
1117 aFilter = getComplexFilter( theSubShapes );
1119 aFilter = getFilter( aMode );
1122 aListOfFilters.append( aFilter );
1125 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1132 sm->installFilter( aFilter );
1135 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1136 ic->AddFilter( anOCCFilter );
1141 //=================================================================
1143 * GEOM_Displayer::LocalSelection
1144 * Activate selection of CAD shapes with activisation of selection
1145 * of their sub-shapes (with opened local context for OCC viewer)
1147 //=================================================================
1148 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1150 SALOME_ListIteratorOfListIO Iter( theIOList );
1151 for ( ; Iter.More(); Iter.Next() )
1152 LocalSelection( Iter.Value(), theMode );
1155 //=================================================================
1157 * GEOM_Displayer::BeforeDisplay
1158 * Called before displaying of pars. Close local context
1159 * [ Reimplemented from SALOME_Displayer ]
1161 //=================================================================
1162 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1164 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1167 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1170 if ( ic->HasOpenedContext() )
1171 ic->CloseAllContexts();
1176 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1181 //=================================================================
1183 * GEOM_Displayer::SetColor
1184 * Set color for shape displaying. If it is equal -1 then default color is used.
1185 * Available values are from Quantity_NameOfColor enumeration
1187 //=================================================================
1188 void GEOM_Displayer::SetColor( const int color )
1195 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1199 int GEOM_Displayer::GetColor() const
1204 bool GEOM_Displayer::HasColor() const
1206 return myColor != -1;
1209 void GEOM_Displayer::UnsetColor()
1213 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1214 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1215 myShadingColor = SalomeApp_Tools::color( col );
1218 //=================================================================
1220 * GEOM_Displayer::SetWidth
1221 * Set width of shape displaying. If it is equal -1 then default width is used.
1223 //=================================================================
1224 void GEOM_Displayer::SetWidth( const double width )
1229 double GEOM_Displayer::GetWidth() const
1234 bool GEOM_Displayer::HasWidth() const
1236 return myWidth != -1;
1239 void GEOM_Displayer::UnsetWidth()
1244 //=================================================================
1246 * GEOM_Displayer::SetToActivate
1247 * This method is used for activisation/deactivisation of objects to be displayed
1249 //=================================================================
1250 void GEOM_Displayer::SetToActivate( const bool toActivate )
1252 myToActivate = toActivate;
1254 bool GEOM_Displayer::ToActivate() const
1256 return myToActivate;
1259 //=================================================================
1261 * GEOM_Displayer::clearTemporary
1262 * Removes from selection temporary objects
1264 //=================================================================
1265 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1267 SALOME_ListIO selected, toSelect;
1268 theSelMgr->selectedObjects( selected );
1270 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1271 Handle(SALOME_InteractiveObject) io = it.Value();
1272 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1273 toSelect.Append( it.Value() );
1276 theSelMgr->setSelectedObjects( toSelect, true );
1279 void GEOM_Displayer::SetName( const char* theName )
1284 void GEOM_Displayer::UnsetName()
1289 SalomeApp_Study* GEOM_Displayer::getStudy() const
1291 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1294 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1299 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1304 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1306 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1309 int GEOM_Displayer::SetDisplayMode( const int theMode )
1311 int aPrevMode = myDisplayMode;
1312 if ( theMode != -1 )
1313 myDisplayMode = theMode;
1316 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1317 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1322 int GEOM_Displayer::GetDisplayMode() const
1324 return myDisplayMode;
1327 int GEOM_Displayer::UnsetDisplayMode()
1329 int aPrevMode = myDisplayMode;
1330 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1331 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1335 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1338 int aTolerance = 64;
1339 int anIterations = 0;
1345 if( anIterations % aPeriod == 0 )
1348 if( aTolerance < 1 )
1351 //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
1353 aHue = (int)( 360.0 * rand() / RAND_MAX );
1354 //cout << "Hue = " << aHue << endl;
1356 //cout << "Auto colors : ";
1358 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1359 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1360 for( ; it != itEnd; ++it )
1362 SALOMEDS::Color anAutoColor = *it;
1363 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1366 aQColor.getHsv( &h, &s, &v );
1368 if( abs( h - aHue ) < aTolerance )
1371 //cout << "break (diff = " << abs( h - aHue ) << ")";
1381 //cout << "Hue of the returned color = " << aHue << endl;
1383 aColor.setHsv( aHue, 255, 255 );
1385 SALOMEDS::Color aSColor;
1386 aSColor.R = (double)aColor.red() / 255.0;
1387 aSColor.G = (double)aColor.green() / 255.0;
1388 aSColor.B = (double)aColor.blue() / 255.0;