1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOM_Displayer.cxx
24 // 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 );
726 if ( myShape.ShapeType() == TopAbs_VERTEX ) {
727 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
728 anAspect->SetColor( aQuanColor );
729 anAspect->SetScale( myScaleOfMarker );
730 anAspect->SetTypeOfMarker( myTypeOfMarker );
731 AISShape->Attributes()->SetPointAspect( anAspect );
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 = false;
824 if (myType == GEOM_VECTOR) isVector = true;
825 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
828 theActors->InitTraversal();
830 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
832 vtkProperty* aProp = 0;
834 if ( HasColor() || HasWidth() )
836 aProp = vtkProperty::New();
837 aProp->SetRepresentationToWireframe();
842 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
843 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
848 aProp->SetLineWidth( GetWidth() );
851 while ( anActor != NULL )
853 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
855 GActor->setIO( myIO );
859 GActor->SetProperty( aProp );
860 GActor->SetPreviewProperty( aProp );
862 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
863 if ( aGeomGActor != 0 )
865 aGeomGActor->SetShadingProperty( aProp );
866 aGeomGActor->SetWireframeProperty( aProp );
871 GActor->PickableOn();
873 GActor->PickableOff();
875 vtkPrs->AddObject( GActor );
877 anActor = (vtkActor*)theActors->GetNextActor();
886 //=================================================================
888 * GEOM_Displayer::BuildPrs
889 * Build presentation accordint to the current viewer type
891 //=================================================================
892 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
894 if ( theObj->_is_nil() )
897 myViewFrame = GetActiveView();
898 if ( myViewFrame == 0 )
901 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
906 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
907 myType = theObj->GetType();
909 // Update presentation
915 //=================================================================
917 * GEOM_Displayer::BuildPrs
918 * Build presentation accordint to the current viewer type
920 //=================================================================
921 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
923 myViewFrame = GetActiveView();
924 if ( theShape.IsNull() || myViewFrame == 0 )
927 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
932 setShape( theShape );
940 //=================================================================
942 * GEOM_Displayer::buildPresentation
943 * Builds/finds object's presentation for the current viewer
944 * Calls corresponding Update() method by means of double dispatch
947 //=================================================================
948 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
949 SALOME_View* theViewFrame )
954 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
958 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
961 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
962 theIO->setEntry( entry.toLatin1().constData() );
963 if ( !theIO.IsNull() )
965 // set interactive object
967 // Find SOBject (because shape should be published previously)
968 SUIT_Session* session = SUIT_Session::session();
969 SUIT_Application* app = session->activeApplication();
972 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
975 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
978 // get CORBA reference to data object
979 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
980 if ( !CORBA::is_nil( object ) )
982 // downcast to GEOM object
983 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
984 if ( !GeomObject->_is_nil() )
987 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
988 myType = GeomObject->GetType();
995 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1001 //=================================================================
1003 * GEOM_Displayer::internalReset
1004 * Resets internal data
1007 //=================================================================
1008 void GEOM_Displayer::internalReset()
1014 //=================================================================
1016 * GEOM_Displayer::LocalSelection
1017 * Activate selection of CAD shapes with activisation of selection
1018 * of their sub-shapes (with opened local context for OCC viewer)
1020 //=================================================================
1021 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1023 SUIT_Session* session = SUIT_Session::session();
1024 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1028 LightApp_SelectionMgr* sm = app->selectionMgr();
1030 // remove all filters from selection
1033 SALOME_View* vf = GetActiveView();
1035 if (!theIO.IsNull() && !vf->isVisible(theIO))
1037 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1038 vf->LocalSelection( prs, theMode );
1039 delete prs; // delete presentation because displayer is its owner
1043 //=================================================================
1045 * GEOM_Displayer::globalSelection
1046 * Activate selection of CAD shapes without activisation of selection
1047 * of their sub-shapes (without opened local context for OCC viewer)
1049 //=================================================================
1050 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1052 TColStd_MapOfInteger aModes;
1053 aModes.Add( theMode );
1054 GlobalSelection( aModes, update );
1057 //=================================================================
1059 * GEOM_Displayer::globalSelection
1060 * Activate selection of CAD shapes without activisation of selection
1061 * of their sub-shapes (without opened local context for OCC viewer)
1063 //=================================================================
1064 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1065 const bool update, const QList<int>* theSubShapes )
1067 SUIT_Session* session = SUIT_Session::session();
1068 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1072 SALOME_View* vf = GetActiveView();
1076 // Close local context
1077 vf->GlobalSelection( update );
1079 // Set selection filters in accordance with current mode
1080 LightApp_SelectionMgr* sm = app->selectionMgr();
1084 // Remove from selection temporary objects if necessary
1085 if ( !theModes.Contains( GEOM_PREVIEW ) )
1086 clearTemporary( sm );
1088 //@ aSel->ClearIndex();
1092 // Remove filters from AIS_InteractiveContext
1093 Handle(AIS_InteractiveContext) ic;
1094 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1097 ic = viewer->getAISContext();
1099 ic->RemoveFilters();
1102 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1105 SUIT_SelectionFilter* aFilter;
1106 if ( theModes.Extent() == 1 )
1108 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1110 if ( aMode == GEOM_COMPOUNDFILTER )
1111 aFilter = getComplexFilter( theSubShapes );
1113 aFilter = getFilter( aMode );
1115 else if ( theModes.Extent() > 1 )
1117 TColStd_MapOfInteger aTopAbsModes;
1118 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1119 QList<SUIT_SelectionFilter*> aListOfFilters;
1120 for ( ; anIter.More(); anIter.Next() )
1122 SUIT_SelectionFilter* aFilter;
1123 int aMode = anIter.Key();
1124 if ( aMode == GEOM_COMPOUNDFILTER )
1125 aFilter = getComplexFilter( theSubShapes );
1127 aFilter = getFilter( aMode );
1130 aListOfFilters.append( aFilter );
1133 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1140 sm->installFilter( aFilter );
1143 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1144 ic->AddFilter( anOCCFilter );
1149 //=================================================================
1151 * GEOM_Displayer::LocalSelection
1152 * Activate selection of CAD shapes with activisation of selection
1153 * of their sub-shapes (with opened local context for OCC viewer)
1155 //=================================================================
1156 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1158 SALOME_ListIteratorOfListIO Iter( theIOList );
1159 for ( ; Iter.More(); Iter.Next() )
1160 LocalSelection( Iter.Value(), theMode );
1163 //=================================================================
1165 * GEOM_Displayer::BeforeDisplay
1166 * Called before displaying of pars. Close local context
1167 * [ Reimplemented from SALOME_Displayer ]
1169 //=================================================================
1170 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1172 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1175 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1178 if ( ic->HasOpenedContext() )
1179 ic->CloseAllContexts();
1184 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1189 //=================================================================
1191 * GEOM_Displayer::SetColor
1192 * Set color for shape displaying. If it is equal -1 then default color is used.
1193 * Available values are from Quantity_NameOfColor enumeration
1195 //=================================================================
1196 void GEOM_Displayer::SetColor( const int color )
1203 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1207 int GEOM_Displayer::GetColor() const
1212 bool GEOM_Displayer::HasColor() const
1214 return myColor != -1;
1217 void GEOM_Displayer::UnsetColor()
1221 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1222 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1223 myShadingColor = SalomeApp_Tools::color( col );
1226 //=================================================================
1228 * GEOM_Displayer::SetWidth
1229 * Set width of shape displaying. If it is equal -1 then default width is used.
1231 //=================================================================
1232 void GEOM_Displayer::SetWidth( const double width )
1237 double GEOM_Displayer::GetWidth() const
1242 bool GEOM_Displayer::HasWidth() const
1244 return myWidth != -1;
1247 void GEOM_Displayer::UnsetWidth()
1252 //=================================================================
1254 * GEOM_Displayer::SetToActivate
1255 * This method is used for activisation/deactivisation of objects to be displayed
1257 //=================================================================
1258 void GEOM_Displayer::SetToActivate( const bool toActivate )
1260 myToActivate = toActivate;
1262 bool GEOM_Displayer::ToActivate() const
1264 return myToActivate;
1267 //=================================================================
1269 * GEOM_Displayer::clearTemporary
1270 * Removes from selection temporary objects
1272 //=================================================================
1273 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1275 SALOME_ListIO selected, toSelect;
1276 theSelMgr->selectedObjects( selected );
1278 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1279 Handle(SALOME_InteractiveObject) io = it.Value();
1280 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1281 toSelect.Append( it.Value() );
1284 theSelMgr->setSelectedObjects( toSelect, true );
1287 void GEOM_Displayer::SetName( const char* theName )
1292 void GEOM_Displayer::UnsetName()
1297 SalomeApp_Study* GEOM_Displayer::getStudy() const
1299 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1302 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1307 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1312 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1314 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1317 int GEOM_Displayer::SetDisplayMode( const int theMode )
1319 int aPrevMode = myDisplayMode;
1320 if ( theMode != -1 )
1321 myDisplayMode = theMode;
1324 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1325 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1330 int GEOM_Displayer::GetDisplayMode() const
1332 return myDisplayMode;
1335 int GEOM_Displayer::UnsetDisplayMode()
1337 int aPrevMode = myDisplayMode;
1338 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1339 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1343 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1346 int aTolerance = 64;
1347 int anIterations = 0;
1353 if( anIterations % aPeriod == 0 )
1356 if( aTolerance < 1 )
1359 //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
1361 aHue = (int)( 360.0 * rand() / RAND_MAX );
1362 //cout << "Hue = " << aHue << endl;
1364 //cout << "Auto colors : ";
1366 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1367 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1368 for( ; it != itEnd; ++it )
1370 SALOMEDS::Color anAutoColor = *it;
1371 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1374 aQColor.getHsv( &h, &s, &v );
1376 if( abs( h - aHue ) < aTolerance )
1379 //cout << "break (diff = " << abs( h - aHue ) << ")";
1389 //cout << "Hue of the returned color = " << aHue << endl;
1391 aColor.setHsv( aHue, 255, 255 );
1393 SALOMEDS::Color aSColor;
1394 aSColor.R = (double)aColor.red() / 255.0;
1395 aSColor.G = (double)aColor.green() / 255.0;
1396 aSColor.B = (double)aColor.blue() / 255.0;