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>
82 #include <Graphic3d_AspectMarker3d.hxx>
85 #include <vtkActorCollection.h>
86 #include <vtkProperty.h>
89 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
91 #include <GEOMImpl_Types.hxx>
92 #include <Graphic3d_HArray1OfBytes.hxx>
96 //================================================================
97 // Function : getActiveStudy
98 // Purpose : Get active study, returns 0 if no open study frame
99 //================================================================
100 static inline SalomeApp_Study* getActiveStudy()
102 SUIT_Session* session = SUIT_Session::session();
103 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
105 return ( SalomeApp_Study* )app->activeStudy();
109 //================================================================
110 // Function : getTopAbsMode
111 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
112 // one from GEOMImpl_Types.h
113 //================================================================
114 static inline int getTopAbsMode( const int implType )
118 case GEOM_COMPOUND : return TopAbs_COMPOUND;
119 case GEOM_SOLID : return TopAbs_SOLID;
120 case GEOM_SHELL : return TopAbs_SHELL;
121 case GEOM_FACE : return TopAbs_FACE;
122 case GEOM_WIRE : return TopAbs_WIRE;
123 case GEOM_EDGE : return TopAbs_EDGE;
124 case GEOM_POINT : return TopAbs_VERTEX;
129 //================================================================
130 // Function : getFilter
131 // Purpose : Get filter corresponding to the type of object
132 // from GEOMImpl_Types.h
133 //================================================================
134 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
136 SUIT_SelectionFilter* aFilter;
138 int aTopAbsMode = getTopAbsMode( theMode );
139 if ( aTopAbsMode != -1 )
140 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
144 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
145 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
147 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
148 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
149 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
150 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
151 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
152 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
154 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
156 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
157 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
159 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
165 //================================================================
166 // Function : getComplexFilter
167 // Purpose : Get compound filter corresponding to the type of
168 // object from GEOMImpl_Types.h
169 //================================================================
170 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
172 GEOM_CompoundFilter* aFilter;
174 if(aSubShapes != NULL ) {
175 aFilter = new GEOM_CompoundFilter(getStudy());
176 QList<int> aTopAbsTypes;
177 QList<int>::const_iterator it;
178 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
179 int topAbsMode = getTopAbsMode(*it);
180 if(topAbsMode != -1 )
181 aTopAbsTypes.append(topAbsMode);
183 aFilter->addSubTypes(aTopAbsTypes);
189 //================================================================
190 // Function : getEntry
192 //================================================================
193 static string getEntry( GEOM::GEOM_Object_ptr object )
195 SUIT_Session* session = SUIT_Session::session();
196 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
199 CORBA::String_var IOR = app->orb()->object_to_string( object );
200 if ( strcmp(IOR.in(), "") != 0 )
202 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
203 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
211 //================================================================
212 // Function : getName
214 //================================================================
215 static string getName( GEOM::GEOM_Object_ptr object )
217 SUIT_Session* session = SUIT_Session::session();
218 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
221 CORBA::String_var IOR = app->orb()->object_to_string( object );
222 if ( strcmp(IOR.in(), "") != 0 )
224 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
225 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
227 _PTR(GenericAttribute) anAttr;
229 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
231 _PTR(AttributeName) aNameAttr( anAttr );
232 return aNameAttr->Value();
240 //=================================================================
242 * GEOM_Displayer::GEOM_Displayer
245 //=================================================================
246 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
249 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
254 SUIT_Session* session = SUIT_Session::session();
255 SUIT_ResourceMgr* resMgr = session->resourceMgr();
257 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
258 myShadingColor = SalomeApp_Tools::color( col );
260 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
261 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
262 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
263 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
264 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
267 // This color is used for shape displaying. If it is equal -1 then
268 // default color is used.
274 // This parameter is used for activisation/deactivisation of objects to be displayed
279 //=================================================================
281 * GEOM_Displayer::~GEOM_Displayer
284 //=================================================================
285 GEOM_Displayer::~GEOM_Displayer()
289 //=================================================================
291 * GEOM_Displayer::Display
292 * Display interactive object in the current viewer
294 //=================================================================
295 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
296 const bool updateViewer,
297 SALOME_View* theViewFrame )
299 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
302 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
306 vf->BeforeDisplay( this );
308 vf->AfterDisplay( this );
313 delete prs; // delete presentation because displayer is its owner
318 //=================================================================
320 * GEOM_Displayer::Display
321 * This overloaded Display() method can be useful for operations
322 * not using dialog boxes.
324 //=================================================================
325 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
327 if ( theObj->_is_nil() )
330 string entry = getEntry( theObj );
332 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
337 //=================================================================
339 * GEOM_Displayer::Erase
340 * Erase interactive object in the current viewer
342 //=================================================================
343 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
345 const bool updateViewer,
346 SALOME_View* theViewFrame )
348 if ( theIO.IsNull() )
351 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
354 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
356 vf->Erase( prs, forced );
359 delete prs; // delete presentation because displayer is its owner
364 //=================================================================
366 * GEOM_Displayer::Erase
367 * Erase geometry object in the current viewer
369 //=================================================================
370 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
372 const bool updateViewer )
374 string entry = getEntry( theObj );
377 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
378 forced, updateViewer);
382 //=================================================================
384 * GEOM_Displayer::Redisplay
385 * Redisplay (erase and then display again) interactive object
386 * in the current viewer
388 //=================================================================
389 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
390 const bool updateViewer )
392 // Remove the object permanently (<forced> == true)
393 SUIT_Session* ses = SUIT_Session::session();
394 SUIT_Application* app = ses->activeApplication();
397 SUIT_Desktop* desk = app->desktop();
398 QList<SUIT_ViewWindow*> wnds = desk->windows();
399 SUIT_ViewWindow* wnd;
400 QListIterator<SUIT_ViewWindow*> it( wnds );
401 while ( it.hasNext() && (wnd = it.next()) )
403 SUIT_ViewManager* vman = wnd->getViewManager();
406 SUIT_ViewModel* vmodel = vman->getViewModel();
409 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
412 if ( view->isVisible( theIO ) || view == GetActiveView() )
414 Erase( theIO, true, false, view );
415 Display( theIO, updateViewer, view );
424 //=================================================================
426 * GEOM_Displayer::Display
427 * Calls Display() method for each object in the given list
429 //=================================================================
430 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
432 SALOME_ListIteratorOfListIO Iter( theIOList );
433 for ( ; Iter.More(); Iter.Next() ) {
434 Display( Iter.Value(), false );
440 //=================================================================
442 * GEOM_Displayer::Erase
443 * Calls Erase() method for each object in the given list
445 //=================================================================
446 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
448 const bool updateViewer )
450 SALOME_ListIteratorOfListIO Iter( theIOList );
451 for ( ; Iter.More(); Iter.Next() )
452 Erase( Iter.Value(), forced, false );
458 //=================================================================
460 * GEOM_Displayer::Redisplay
461 * Calls Redisplay() method for each object in the given list
463 //=================================================================
464 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
466 SALOME_ListIteratorOfListIO Iter( theIOList );
467 for ( ; Iter.More(); Iter.Next() )
468 Redisplay( Iter.Value(), false );
474 //=================================================================
476 * GEOM_Displayer::Update
477 * Update OCC presentaion
478 * [ Reimplemented from SALOME_Displayer ]
480 //=================================================================
481 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
483 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
487 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
489 TopoDS_Face aFace = TopoDS::Face( myShape );
490 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
491 if ( !aPlane.IsNull() )
493 gp_Ax3 aPos = aPlane->Pln().Position();
494 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
496 Handle(GEOM_AISTrihedron) aTrh;
498 if ( occPrs->IsNull() )
500 aTrh = new GEOM_AISTrihedron( aPlc );
503 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
506 aTrh->SetWidth( GetWidth() );
508 if ( !myIO.IsNull() )
511 aTrh->SetOwner( myIO );
514 occPrs->AddObject( aTrh );
518 AIS_ListOfInteractive aList;
519 occPrs->GetObjects( aList );
520 AIS_ListIteratorOfListOfInteractive anIter( aList );
521 for ( ; anIter.More(); anIter.Next() )
523 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
524 if ( !aTrh.IsNull() )
526 aTrh->SetComponent( aPlc );
532 occPrs->SetToActivate( ToActivate() );
537 // if presentation is empty we try to create new one
538 if ( occPrs->IsNull() )
540 if ( !myShape.IsNull() )
542 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
543 Handle(GEOM_AISShape) AISShape;
544 if (myType == GEOM_VECTOR)
545 AISShape = new GEOM_AISVector (myShape, "");
547 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
548 !TopoDS_Iterator(myShape).More())
549 return;// NPAL15983 (Bug when displaying empty groups)
550 AISShape = new GEOM_AISShape (myShape, "");
552 // Temporary staff: vertex must be infinite for correct visualization
553 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
555 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
556 AISShape->SetDisplayMode( myDisplayMode );
557 AISShape->SetShadingColor( myShadingColor );
559 // Set color and number for iso lines
560 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
561 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
562 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
563 Quantity_Color aColor = SalomeApp_Tools::color( col );
564 int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
565 int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
567 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
568 anAspect->SetNumber( anUIsoNumber );
569 anAspect->SetColor( aColor );
570 AISShape->Attributes()->SetUIsoAspect( anAspect );
572 anAspect = AISShape->Attributes()->VIsoAspect();
573 anAspect->SetNumber( aVIsoNumber );
574 anAspect->SetColor( aColor );
575 AISShape->Attributes()->SetVIsoAspect( anAspect );
579 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
580 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
581 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
582 if ( myShape.ShapeType() == TopAbs_VERTEX )
584 anAspect->SetScale( myScaleOfMarker );
585 anAspect->SetTypeOfMarker( myTypeOfMarker );
587 AISShape->Attributes()->SetPointAspect( anAspect );
591 if ( myShape.ShapeType() == TopAbs_VERTEX )
593 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
594 aColor = SalomeApp_Tools::color( col );
596 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
597 anAspect->SetColor( aColor );
598 anAspect->SetScale( myScaleOfMarker );
599 anAspect->SetTypeOfMarker( myTypeOfMarker );
600 AISShape->Attributes()->SetPointAspect( anAspect );
605 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
606 aColor = SalomeApp_Tools::color( col );
608 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
609 anAspect->SetColor( aColor );
610 AISShape->Attributes()->SetLineAspect( anAspect );
612 // Set unfree boundaries aspect
613 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
614 anAspect->SetColor( aColor );
615 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
617 // Set free boundaries aspect
618 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
619 aColor = SalomeApp_Tools::color( col );
621 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
622 anAspect->SetColor( aColor );
623 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
626 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
627 aColor = SalomeApp_Tools::color( col );
629 anAspect = AISShape->Attributes()->WireAspect();
630 anAspect->SetColor( aColor );
631 AISShape->Attributes()->SetWireAspect( anAspect );
633 // bug [SALOME platform 0019868]
634 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
635 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
638 double aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
639 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
640 AISShape->SetOwnDeviationCoefficient(aDC);
645 AISShape->SetWidth( GetWidth() );
647 if ( !myIO.IsNull() )
649 AISShape->setIO( myIO );
650 AISShape->SetOwner( myIO );
652 else if ( !myName.empty() )
654 // Workaround to allow selection of temporary objects
655 static int tempId = 0;
657 sprintf( buf, "TEMP_%d", tempId++ );
658 Handle( SALOME_InteractiveObject ) anObj =
659 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
660 AISShape->setIO( anObj );
661 AISShape->SetOwner( anObj );
664 // Get color and other properties from GEOM_Object
665 SUIT_Session* session = SUIT_Session::session();
666 SUIT_Application* app = session->activeApplication();
669 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
672 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
673 if ( !anIO.IsNull() )
675 _PTR(SObject) SO ( study->studyDS()->FindObjectID( anIO->getEntry() ) );
678 // get CORBA reference to data object
679 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
680 if ( !CORBA::is_nil( object ) )
682 // downcast to GEOM object
683 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
684 if ( !aGeomObject->_is_nil() )
686 SALOMEDS::Color aSColor = aGeomObject->GetColor();
687 bool hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
688 if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group
690 GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
691 GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() );
692 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject );
693 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
695 QList<SALOMEDS::Color> aReservedColors;
697 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
698 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
699 if ( strcmp(IOR.in(), "") != 0 )
701 _PTR(Study) aStudy = study->studyDS();
702 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( string(IOR) ) );
703 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
704 for( ; it->More(); it->Next() )
706 _PTR(SObject) aChildSObject( it->Value() );
707 GEOM::GEOM_Object_var aChildObject =
708 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
709 if( CORBA::is_nil( aChildObject ) )
712 if( aChildObject->GetType() != GEOM_GROUP )
715 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
716 aReservedColors.append( aReservedColor );
720 aSColor = getUniqueColor( aReservedColors );
727 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
728 AISShape->SetColor( aQuanColor );
729 AISShape->SetShadingColor( aQuanColor );
730 if ( myShape.ShapeType() == TopAbs_VERTEX ) {
731 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
732 anAspect->SetColor( aQuanColor );
733 anAspect->SetScale( myScaleOfMarker );
734 anAspect->SetTypeOfMarker( myTypeOfMarker );
735 AISShape->Attributes()->SetPointAspect( anAspect );
739 GEOM::marker_type aType = aGeomObject->GetMarkerType();
740 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
741 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
742 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
743 double aMSize = ((int)aSize+1)*0.5;
744 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
745 anAspect->SetScale( aMSize );
746 anAspect->SetTypeOfMarker( aMType );
747 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
749 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
750 anAspect->SetColor( aQuanColor );
751 AISShape->Attributes()->SetPointAspect( anAspect );
753 else if ( aType == GEOM::MT_USER ) {
754 int aTextureId = aGeomObject->GetMarkerTexture();
755 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
756 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
757 Standard_Integer aWidth, aHeight;
758 Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( getStudy(), aTextureId, aWidth, aHeight );
759 if ( !aTexture.IsNull() ) {
760 static int TextureId = 0;
761 Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor,
765 AISShape->Attributes()->SetPointAspect( aTextureAspect );
775 // AISShape->SetName(???); ??? necessary to set name ???
776 occPrs->AddObject( AISShape );
778 // In accordance with ToActivate() value object will be activated/deactivated
779 // when it will be displayed
780 occPrs->SetToActivate( ToActivate() );
783 // if presentation is found -> set again shape for it
786 if ( !myShape.IsNull() )
788 AIS_ListOfInteractive IOList;
789 occPrs->GetObjects( IOList );
790 AIS_ListIteratorOfListOfInteractive Iter( IOList );
791 for ( ; Iter.More(); Iter.Next() )
793 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
794 if ( AISShape.IsNull() )
796 if ( AISShape->Shape() != myShape )
798 AISShape->Set( myShape );
799 AISShape->UpdateSelection();
800 AISShape->SetToUpdate();
802 if ( !myIO.IsNull() )
804 AISShape->setIO( myIO );
805 AISShape->SetOwner( myIO );
813 //=================================================================
815 * GEOM_Displayer::Update
816 * Update VTK presentaion
817 * [ Reimplemented from SALOME_Displayer ]
819 //=================================================================
820 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
822 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
823 if ( !vtkPrs || myShape.IsNull() )
826 vtkActorCollection* theActors = 0;
828 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
830 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
831 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
835 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
836 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
839 Handle(Geom_Plane) aPlane =
840 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
841 if ( aPlane.IsNull() )
844 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
845 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
847 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
848 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
850 vtkPrs->AddObject( aTrh );
852 theActors = vtkActorCollection::New();
853 theActors->AddItem( aTrh );
857 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, myType == GEOM_VECTOR );
860 theActors->InitTraversal();
862 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
864 vtkProperty* aProp = 0;
866 if ( HasColor() || HasWidth() )
868 aProp = vtkProperty::New();
869 aProp->SetRepresentationToWireframe();
874 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
875 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
880 aProp->SetLineWidth( GetWidth() );
883 while ( anActor != NULL )
885 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
887 GActor->setIO( myIO );
891 GActor->SetProperty( aProp );
892 GActor->SetPreviewProperty( aProp );
894 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
895 if ( aGeomGActor != 0 )
897 aGeomGActor->SetShadingProperty( aProp );
898 aGeomGActor->SetWireframeProperty( aProp );
903 GActor->PickableOn();
905 GActor->PickableOff();
907 vtkPrs->AddObject( GActor );
909 anActor = (vtkActor*)theActors->GetNextActor();
918 //=================================================================
920 * GEOM_Displayer::BuildPrs
921 * Build presentation accordint to the current viewer type
923 //=================================================================
924 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
926 if ( theObj->_is_nil() )
929 myViewFrame = GetActiveView();
930 if ( myViewFrame == 0 )
933 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
938 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
939 myType = theObj->GetType();
941 // Update presentation
947 //=================================================================
949 * GEOM_Displayer::BuildPrs
950 * Build presentation accordint to the current viewer type
952 //=================================================================
953 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
955 myViewFrame = GetActiveView();
956 if ( theShape.IsNull() || myViewFrame == 0 )
959 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
964 setShape( theShape );
972 //=================================================================
974 * GEOM_Displayer::buildPresentation
975 * Builds/finds object's presentation for the current viewer
976 * Calls corresponding Update() method by means of double dispatch
979 //=================================================================
980 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
981 SALOME_View* theViewFrame )
986 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
990 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
993 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
994 theIO->setEntry( entry.toLatin1().constData() );
995 if ( !theIO.IsNull() )
997 // set interactive object
999 // Find SOBject (because shape should be published previously)
1000 SUIT_Session* session = SUIT_Session::session();
1001 SUIT_Application* app = session->activeApplication();
1004 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1007 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1010 // get CORBA reference to data object
1011 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1012 if ( !CORBA::is_nil( object ) )
1014 // downcast to GEOM object
1015 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1016 if ( !GeomObject->_is_nil() )
1018 // finally set shape
1019 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1020 myType = GeomObject->GetType();
1027 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1033 //=================================================================
1035 * GEOM_Displayer::buildSubshapePresentation
1036 * Builds/finds object's presentation for the current viewer
1037 * Calls corresponding Update() method by means of double dispatch
1038 * For not published objects (for Mantis issue 0020435)
1040 //=================================================================
1041 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1042 const QString& entry,
1043 SALOME_View* theViewFrame)
1045 SALOME_Prs* prs = 0;
1048 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1052 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1055 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1056 theIO->setEntry(entry.toLatin1().constData());
1057 if (!theIO.IsNull())
1059 // set interactive object
1061 // finally set shape
1063 myType = GEOM_SUBSHAPE;
1065 UpdatePrs(prs); // Update presentation by using of the double dispatch
1071 //=================================================================
1073 * GEOM_Displayer::internalReset
1074 * Resets internal data
1077 //=================================================================
1078 void GEOM_Displayer::internalReset()
1084 //=================================================================
1086 * GEOM_Displayer::LocalSelection
1087 * Activate selection of CAD shapes with activisation of selection
1088 * of their sub-shapes (with opened local context for OCC viewer)
1090 //=================================================================
1091 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1093 SUIT_Session* session = SUIT_Session::session();
1094 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1098 LightApp_SelectionMgr* sm = app->selectionMgr();
1100 // remove all filters from selection
1103 SALOME_View* vf = GetActiveView();
1105 if (!theIO.IsNull() && !vf->isVisible(theIO))
1107 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1108 vf->LocalSelection( prs, theMode );
1109 delete prs; // delete presentation because displayer is its owner
1113 //=================================================================
1115 * GEOM_Displayer::globalSelection
1116 * Activate selection of CAD shapes without activisation of selection
1117 * of their sub-shapes (without opened local context for OCC viewer)
1119 //=================================================================
1120 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1122 TColStd_MapOfInteger aModes;
1123 aModes.Add( theMode );
1124 GlobalSelection( aModes, update );
1127 //=================================================================
1129 * GEOM_Displayer::globalSelection
1130 * Activate selection of CAD shapes without activisation of selection
1131 * of their sub-shapes (without opened local context for OCC viewer)
1133 //=================================================================
1134 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1135 const bool update, const QList<int>* theSubShapes )
1137 SUIT_Session* session = SUIT_Session::session();
1138 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1142 SALOME_View* vf = GetActiveView();
1146 // Close local context
1147 vf->GlobalSelection( update );
1149 // Set selection filters in accordance with current mode
1150 LightApp_SelectionMgr* sm = app->selectionMgr();
1154 // Remove from selection temporary objects if necessary
1155 if ( !theModes.Contains( GEOM_PREVIEW ) )
1156 clearTemporary( sm );
1158 //@ aSel->ClearIndex();
1162 // Remove filters from AIS_InteractiveContext
1163 Handle(AIS_InteractiveContext) ic;
1164 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1167 ic = viewer->getAISContext();
1169 ic->RemoveFilters();
1172 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1175 SUIT_SelectionFilter* aFilter;
1176 if ( theModes.Extent() == 1 )
1178 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1180 if ( aMode == GEOM_COMPOUNDFILTER )
1181 aFilter = getComplexFilter( theSubShapes );
1183 aFilter = getFilter( aMode );
1185 else if ( theModes.Extent() > 1 )
1187 TColStd_MapOfInteger aTopAbsModes;
1188 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1189 QList<SUIT_SelectionFilter*> aListOfFilters;
1190 for ( ; anIter.More(); anIter.Next() )
1192 SUIT_SelectionFilter* aFilter;
1193 int aMode = anIter.Key();
1194 if ( aMode == GEOM_COMPOUNDFILTER )
1195 aFilter = getComplexFilter( theSubShapes );
1197 aFilter = getFilter( aMode );
1200 aListOfFilters.append( aFilter );
1203 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1210 sm->installFilter( aFilter );
1213 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1214 ic->AddFilter( anOCCFilter );
1219 //=================================================================
1221 * GEOM_Displayer::LocalSelection
1222 * Activate selection of CAD shapes with activisation of selection
1223 * of their sub-shapes (with opened local context for OCC viewer)
1225 //=================================================================
1226 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1228 SALOME_ListIteratorOfListIO Iter( theIOList );
1229 for ( ; Iter.More(); Iter.Next() )
1230 LocalSelection( Iter.Value(), theMode );
1233 //=================================================================
1235 * GEOM_Displayer::BeforeDisplay
1236 * Called before displaying of pars. Close local context
1237 * [ Reimplemented from SALOME_Displayer ]
1239 //=================================================================
1240 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1242 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1245 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1248 if ( ic->HasOpenedContext() )
1249 ic->CloseAllContexts();
1254 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1259 //=================================================================
1261 * GEOM_Displayer::SetColor
1262 * Set color for shape displaying. If it is equal -1 then default color is used.
1263 * Available values are from Quantity_NameOfColor enumeration
1265 //=================================================================
1266 void GEOM_Displayer::SetColor( const int color )
1273 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1277 int GEOM_Displayer::GetColor() const
1282 bool GEOM_Displayer::HasColor() const
1284 return myColor != -1;
1287 void GEOM_Displayer::UnsetColor()
1291 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1292 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1293 myShadingColor = SalomeApp_Tools::color( col );
1296 //=================================================================
1298 * GEOM_Displayer::SetWidth
1299 * Set width of shape displaying. If it is equal -1 then default width is used.
1301 //=================================================================
1302 void GEOM_Displayer::SetWidth( const double width )
1307 double GEOM_Displayer::GetWidth() const
1312 bool GEOM_Displayer::HasWidth() const
1314 return myWidth != -1;
1317 void GEOM_Displayer::UnsetWidth()
1322 //=================================================================
1324 * GEOM_Displayer::SetToActivate
1325 * This method is used for activisation/deactivisation of objects to be displayed
1327 //=================================================================
1328 void GEOM_Displayer::SetToActivate( const bool toActivate )
1330 myToActivate = toActivate;
1332 bool GEOM_Displayer::ToActivate() const
1334 return myToActivate;
1337 //=================================================================
1339 * GEOM_Displayer::clearTemporary
1340 * Removes from selection temporary objects
1342 //=================================================================
1343 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1345 SALOME_ListIO selected, toSelect;
1346 theSelMgr->selectedObjects( selected );
1348 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1349 Handle(SALOME_InteractiveObject) io = it.Value();
1350 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1351 toSelect.Append( it.Value() );
1354 theSelMgr->setSelectedObjects( toSelect, true );
1357 void GEOM_Displayer::SetName( const char* theName )
1362 void GEOM_Displayer::UnsetName()
1367 SalomeApp_Study* GEOM_Displayer::getStudy() const
1369 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1372 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1377 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1382 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1384 return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1387 int GEOM_Displayer::SetDisplayMode( const int theMode )
1389 int aPrevMode = myDisplayMode;
1390 if ( theMode != -1 )
1391 myDisplayMode = theMode;
1394 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1395 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1400 int GEOM_Displayer::GetDisplayMode() const
1402 return myDisplayMode;
1405 int GEOM_Displayer::UnsetDisplayMode()
1407 int aPrevMode = myDisplayMode;
1408 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1409 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1413 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1416 int aTolerance = 64;
1417 int anIterations = 0;
1423 if( anIterations % aPeriod == 0 )
1426 if( aTolerance < 1 )
1429 //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
1431 aHue = (int)( 360.0 * rand() / RAND_MAX );
1432 //cout << "Hue = " << aHue << endl;
1434 //cout << "Auto colors : ";
1436 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1437 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1438 for( ; it != itEnd; ++it )
1440 SALOMEDS::Color anAutoColor = *it;
1441 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1444 aQColor.getHsv( &h, &s, &v );
1446 if( abs( h - aHue ) < aTolerance )
1449 //cout << "break (diff = " << abs( h - aHue ) << ")";
1459 //cout << "Hue of the returned color = " << aHue << endl;
1461 aColor.setHsv( aHue, 255, 255 );
1463 SALOMEDS::Color aSColor;
1464 aSColor.R = (double)aColor.red() / 255.0;
1465 aSColor.G = (double)aColor.green() / 255.0;
1466 aSColor.B = (double)aColor.blue() / 255.0;