1 // Copyright (C) 2007-2013 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_TopWireframeShape.hxx>
43 #include <GEOM_AISVector.hxx>
44 #include <GEOM_AISTrihedron.hxx>
45 #include <GEOM_VTKTrihedron.hxx>
46 #include <GEOM_VTKPropertyMaterial.hxx>
48 #include <Material_Model.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ViewWindow.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_ResourceMgr.h>
56 #include <Basics_OCCTVersion.hxx>
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_Application.h>
60 #include <LightApp_SelectionMgr.h>
61 #include <LightApp_DataObject.h>
62 #include <SalomeApp_TypeFilter.h>
63 #include <SalomeApp_Tools.h>
65 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SALOME_ListIO.hxx>
67 #include <SALOME_Prs.h>
70 #include <SOCC_ViewModel.h>
73 #include <SVTK_ViewModel.h>
76 #include <AIS_Drawer.hxx>
77 #include <AIS_ListIteratorOfListOfInteractive.hxx>
78 #include <Prs3d_IsoAspect.hxx>
79 #include <Prs3d_PointAspect.hxx>
80 #include <StdSelect_TypeOfEdge.hxx>
81 #include <StdSelect_TypeOfFace.hxx>
82 #include <StdSelect_DisplayMode.hxx>
83 #include <TopoDS_Face.hxx>
84 #include <BRep_Tool.hxx>
85 #include <Geom_Plane.hxx>
86 #include <Geom_Axis2Placement.hxx>
87 #include <Graphic3d_AspectFillArea3d.hxx>
89 #include <TColStd_MapOfInteger.hxx>
90 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
91 #include <TopoDS_Iterator.hxx>
92 #include <Graphic3d_AspectMarker3d.hxx>
93 #include <TopTools_MapOfShape.hxx>
94 #include <TopTools_ListOfShape.hxx>
95 #include <TopTools_ListIteratorOfListOfShape.hxx>
98 #include <Prs3d_ShadingAspect.hxx>
100 #include <BRepMesh_IncrementalMesh.hxx>
103 #include <vtkActorCollection.h>
104 #include <vtkProperty.h>
107 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
109 #include <GEOMImpl_Types.hxx>
111 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
112 #include <TColStd_HArray1OfByte.hxx>
114 #include <Graphic3d_HArray1OfBytes.hxx>
117 // If the next macro is defined, autocolor feature works for all sub-shapes;
118 // if it is undefined, autocolor feature works for groups only
119 #define GENERAL_AUTOCOLOR
120 // Below macro, when uncommented, switches on simplified (more performant) algorithm
121 // of auto-color picking up
122 #define SIMPLE_AUTOCOLOR
124 // Hard-coded value of shape deflection coefficient for VTK viewer
125 const double VTK_MIN_DEFLECTION = 0.001;
127 //================================================================
128 // Function : getActiveStudy
129 // Purpose : Get active study, returns 0 if no open study frame
130 //================================================================
131 static inline SalomeApp_Study* getActiveStudy()
133 SUIT_Session* session = SUIT_Session::session();
134 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
136 return ( SalomeApp_Study* )app->activeStudy();
140 static inline int getViewManagerId( SALOME_View* theViewFrame) {
141 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
142 SUIT_ViewManager* aViewMgr = 0;
144 aViewMgr = aModel->getViewManager();
145 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
148 //================================================================
149 // Function : getTopAbsMode
150 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
151 // one from GEOMImpl_Types.h
152 //================================================================
153 static inline int getTopAbsMode( const int implType )
157 case GEOM_COMPOUND : return TopAbs_COMPOUND;
158 case GEOM_SOLID : return TopAbs_SOLID;
159 case GEOM_SHELL : return TopAbs_SHELL;
160 case GEOM_FACE : return TopAbs_FACE;
161 case GEOM_WIRE : return TopAbs_WIRE;
162 case GEOM_EDGE : return TopAbs_EDGE;
163 case GEOM_POINT : return TopAbs_VERTEX;
168 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
170 if ( shape.IsNull() )
173 int ret = shape.ShapeType();
175 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
176 TopoDS_Iterator it(shape, Standard_True, Standard_False);
177 for (; it.More(); it.Next()) {
178 TopoDS_Shape sub_shape = it.Value();
179 if ( sub_shape.IsNull() ) continue;
180 int stype = getMinMaxShapeType( sub_shape, ismin );
181 if ( stype == TopAbs_SHAPE ) continue;
182 if ( ismin && stype > ret )
184 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
192 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
194 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
197 //================================================================
198 // Function : getFilter
199 // Purpose : Get filter corresponding to the type of object
200 // from GEOMImpl_Types.h
201 //================================================================
202 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
204 SUIT_SelectionFilter* aFilter;
206 int aTopAbsMode = getTopAbsMode( theMode );
207 if ( aTopAbsMode != -1 )
208 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
212 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
213 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
215 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
216 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
217 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
218 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
219 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
220 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
222 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
224 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
225 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
227 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
233 //================================================================
234 // Function : getComplexFilter
235 // Purpose : Get compound filter corresponding to the type of
236 // object from GEOMImpl_Types.h
237 //================================================================
238 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
240 GEOM_CompoundFilter* aFilter;
242 if(aSubShapes != NULL ) {
243 aFilter = new GEOM_CompoundFilter(getStudy());
244 QList<int> aTopAbsTypes;
245 QList<int>::const_iterator it;
246 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
247 int topAbsMode = getTopAbsMode(*it);
248 if(topAbsMode != -1 )
249 aTopAbsTypes.append(topAbsMode);
251 aFilter->addSubTypes(aTopAbsTypes);
257 //================================================================
258 // Function : getEntry
260 //================================================================
261 static std::string getEntry( GEOM::GEOM_Object_ptr object )
263 SUIT_Session* session = SUIT_Session::session();
264 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
267 CORBA::String_var IOR = app->orb()->object_to_string( object );
268 if ( strcmp(IOR.in(), "") != 0 )
270 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
271 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
279 //================================================================
280 // Function : getName
282 //================================================================
283 static std::string getName( GEOM::GEOM_Object_ptr object )
285 SUIT_Session* session = SUIT_Session::session();
286 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
289 CORBA::String_var IOR = app->orb()->object_to_string( object );
290 if ( strcmp(IOR.in(), "") != 0 )
292 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
293 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
295 _PTR(GenericAttribute) anAttr;
297 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
299 _PTR(AttributeName) aNameAttr( anAttr );
300 return aNameAttr->Value();
308 //=================================================================
310 * GEOM_Displayer::GEOM_Displayer
313 //=================================================================
314 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
317 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
322 SUIT_Session* session = SUIT_Session::session();
323 SUIT_ResourceMgr* resMgr = session->resourceMgr();
325 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
326 myShadingColor = SalomeApp_Tools::color( col );
328 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
329 myHasDisplayMode = false;
331 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
332 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
333 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
335 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
336 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
337 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
340 // This color is used for shape displaying. If it is equal -1 then
341 // default color is used.
348 // This parameter is used for activisation/deactivisation of objects to be displayed
350 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
351 // Activate parallel vizualisation only for testing purpose
352 // and if the corresponding env variable is set to 1
353 char* parallel_visu = getenv("PARALLEL_VISU");
354 if (parallel_visu && atoi(parallel_visu))
356 MESSAGE("Parallel visualisation on");
357 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
364 //=================================================================
366 * GEOM_Displayer::~GEOM_Displayer
369 //=================================================================
370 GEOM_Displayer::~GEOM_Displayer()
374 //=================================================================
376 * GEOM_Displayer::Display
377 * Display interactive object in the current viewer
379 //=================================================================
380 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
381 const bool updateViewer,
382 SALOME_View* theViewFrame )
384 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
387 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
391 vf->BeforeDisplay( this, prs );
393 vf->AfterDisplay( this, prs );
398 int aMgrId = getViewManagerId(vf);
399 SalomeApp_Study* aStudy = getStudy();
400 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
402 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
404 delete prs; // delete presentation because displayer is its owner
409 //=================================================================
411 * GEOM_Displayer::Display
412 * This overloaded Display() method can be useful for operations
413 * not using dialog boxes.
415 //=================================================================
416 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
418 if ( theObj->_is_nil() )
421 std::string entry = getEntry( theObj );
423 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
428 //=================================================================
430 * GEOM_Displayer::Erase
431 * Erase interactive object in the current viewer
433 //=================================================================
434 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
436 const bool updateViewer,
437 SALOME_View* theViewFrame )
439 if ( theIO.IsNull() )
442 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
445 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
447 vf->BeforeErase( this, prs );
448 vf->Erase( prs, forced );
449 vf->AfterErase( this, prs );
452 delete prs; // delete presentation because displayer is its owner
454 int aMgrId = getViewManagerId(vf);
455 SalomeApp_Study* aStudy = getStudy();
456 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
458 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
463 //=================================================================
465 * GEOM_Displayer::Erase
466 * Erase geometry object in the current viewer
468 //=================================================================
469 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
471 const bool updateViewer )
473 std::string entry = getEntry( theObj );
476 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
477 forced, updateViewer);
481 //=================================================================
483 * GEOM_Displayer::Redisplay
484 * Redisplay (erase and then display again) interactive object
485 * in the current viewer
487 //=================================================================
488 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
489 const bool updateViewer )
491 // Remove the object permanently (<forced> == true)
492 SUIT_Session* ses = SUIT_Session::session();
493 SUIT_Application* app = ses->activeApplication();
496 SUIT_Desktop* desk = app->desktop();
497 QList<SUIT_ViewWindow*> wnds = desk->windows();
498 SUIT_ViewWindow* wnd;
499 QListIterator<SUIT_ViewWindow*> it( wnds );
500 while ( it.hasNext() && (wnd = it.next()) )
502 SUIT_ViewManager* vman = wnd->getViewManager();
505 SUIT_ViewModel* vmodel = vman->getViewModel();
508 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
511 if ( view->isVisible( theIO ) || view == GetActiveView() )
513 Erase( theIO, true, false, view );
514 Display( theIO, updateViewer, view );
523 //=================================================================
525 * GEOM_Displayer::Display
526 * Calls Display() method for each object in the given list
528 //=================================================================
529 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
531 SALOME_ListIteratorOfListIO Iter( theIOList );
532 for ( ; Iter.More(); Iter.Next() ) {
533 Display( Iter.Value(), false );
539 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
541 // VSR: this method can be improved in future:
542 // to improve performance, the default values from resource manager should be cached in the displayer
543 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
546 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
548 // VSR: this method can be improved in future:
549 // to improve performance, the default values from resource manager should be cached in the displayer
550 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
553 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
555 // check that shape is not null
556 if ( AISShape.IsNull() ) return;
558 // check that study is active
559 SalomeApp_Study* study = getStudy();
560 if ( !study ) return;
562 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
563 !TopoDS_Iterator(myShape).More() )
564 return; // NPAL15983 (Bug when displaying empty groups)
566 // set interactive object
568 Handle( SALOME_InteractiveObject ) anIO;
570 if ( !myIO.IsNull() ) {
571 AISShape->setIO( myIO );
572 AISShape->SetOwner( myIO );
575 else if ( !myName.empty() ) {
576 // workaround to allow selection of temporary objects
577 static int tempId = 0;
578 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
579 AISShape->setIO( anIO );
580 AISShape->SetOwner( anIO );
583 // flag: only vertex or compound of vertices is processed (specific handling)
584 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
585 // presentation study entry (empty for temporary objects like preview)
586 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
587 // flag: temporary object
588 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
589 // currently active view window's ID (-1 if no active view)
590 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
592 // get presentation properties
593 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
595 // Temporary staff: vertex must be infinite for correct visualization
596 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
599 Material_Model material;
600 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
602 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
603 // - set front material properties
604 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
605 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
606 // - set back material properties
607 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
608 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
609 // - switch to default (both sides) facing mode
610 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
616 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
617 // we set it to the shape not taking into account material properties
618 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
620 else if ( !material.isPhysical() ) {
621 // shading color from properties is used only for non-physical materials
622 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
626 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
627 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
628 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
629 AISShape->Attributes()->SetLineAspect( anAspect );
631 // - unfree boundaries color
632 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
633 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
634 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
635 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
637 // - free boundaries color
638 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
639 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
640 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
641 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
643 // - standalone edges color
644 anAspect = AISShape->Attributes()->WireAspect();
645 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
646 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
647 AISShape->Attributes()->SetWireAspect( anAspect );
649 // - color for edges in shading+edges mode
650 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
653 AISShape->storeBoundaryColors();
656 AISShape->SetDisplayMode( HasDisplayMode() ?
657 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
659 // display mode from properties
660 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
662 // set display vectors flag
663 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
666 // VSR: ??? next line is commented: transparency property is set in the AfterDisplay() function
667 //AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
669 // set iso properties
670 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
671 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
672 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
673 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
674 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
675 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
676 uIsoAspect->SetColor( isosColor );
677 uIsoAspect->SetWidth( isosWidth );
678 uIsoAspect->SetNumber( uIsos );
679 vIsoAspect->SetColor( isosColor );
680 vIsoAspect->SetWidth( isosWidth );
681 vIsoAspect->SetNumber( vIsos );
682 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
683 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
685 // set deflection coefficient
686 // ... to avoid to small values of the coefficient, its lower value is limited
687 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
690 if ( HasTexture() ) {
691 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
692 AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
693 AISShape->SetTextureMapOn();
694 AISShape->DisableTextureModulate();
695 AISShape->SetDisplayMode( 3 );
699 AISShape->SetWidth( HasWidth() ?
700 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
702 // libe width from properties
703 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
705 // set top-level flag
706 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
708 // set point marker (for vertex / compound of vertices only)
710 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
711 if ( aList.size() == 2 ) {
712 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
713 int aTypeOfMarker = aList[0].toInt();
714 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
715 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
716 anAspect->SetScale( aScaleOfMarker );
717 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
718 anAspect->SetColor( HasColor() ?
719 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
720 (Quantity_NameOfColor)GetColor() :
721 // color from properties
722 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
723 AISShape->Attributes()->SetPointAspect( anAspect );
725 else if ( aList.size() == 1 ) {
726 // custom marker string contains "IdOfTexture"
727 int textureId = aList[0].toInt();
728 Standard_Integer aWidth, aHeight;
729 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
730 Handle(TColStd_HArray1OfByte) aTexture =
732 Handle(Graphic3d_HArray1OfBytes) aTexture =
734 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
735 if ( !aTexture.IsNull() ) {
736 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
737 Handle(Prs3d_PointAspect) aTextureAspect =
738 new Prs3d_PointAspect( HasColor() ?
739 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
740 (Quantity_NameOfColor)GetColor() :
741 // color from properties
742 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
747 Handle(Prs3d_PointAspect) aTextureAspect =
748 new Prs3d_PointAspect( HasColor() ?
749 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
750 (Quantity_NameOfColor)GetColor() :
751 // color from properties
752 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
757 AISShape->Attributes()->SetPointAspect( aTextureAspect );
762 if ( create && !isTemporary && aMgrId != -1 ) {
763 // set properties to the study
764 study->setObjectPropMap( aMgrId, entry, propMap );
767 // AISShape->SetName(???); ??? necessary to set name ???
770 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
772 // check that actor is not null
773 if ( !actor ) return;
775 // check that study is active
776 SalomeApp_Study* study = getStudy();
777 if ( !study ) return;
779 // set interactive object
781 Handle( SALOME_InteractiveObject ) anIO;
783 if ( !myIO.IsNull() ) {
784 actor->setIO( myIO );
787 else if ( !myName.empty() ) {
788 // workaround to allow selection of temporary objects
789 static int tempId = 0;
790 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
791 actor->setIO( anIO );
794 // presentation study entry (empty for temporary objects like preview)
795 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
796 // flag: temporary object
797 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
798 // currently active view window's ID (-1 if no active view)
799 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
801 // get presentation properties
802 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
805 /////////////////////////////////////////////////////////////////////////
806 // VSR: for VTK viewer currently deflection coefficient is hardcoded
807 // due to performance problem
808 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
809 /////////////////////////////////////////////////////////////////////////
810 if ( !actor->getTopo().IsSame( myShape ) )
811 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
814 Material_Model material;
815 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
816 std::vector<vtkProperty*> mprops;
817 mprops.push_back( material.getMaterialVTKProperty( true ) );
818 mprops.push_back( material.getMaterialVTKProperty( false) );
819 actor->SetMaterial( mprops );
821 // set iso-lines properties
823 // - set number of iso-lines
824 int nbIsos[2]= { 1, 1 };
825 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
826 nbIsos[0] = isos[0].toInt();
827 nbIsos[1] = isos[1].toInt();
828 actor->SetNbIsos( nbIsos );
830 // - set iso-lines width
831 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
833 // - set iso-lines color
834 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
835 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
840 // - same color for all sub-actors
841 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
842 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
845 // shading color (for non-physical materials)
846 if ( !material.isPhysical() ) {
847 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
848 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
849 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
852 // - standalone edge color
853 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
854 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
856 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
857 // - shared edges color ???
858 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
860 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
861 // - free edges color ???
862 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
865 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
866 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
869 // - color for edges in shading+edges mode
870 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
871 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
874 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
877 actor->SetWidth( HasWidth() ?
878 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
880 // libe width from properties
881 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
883 // set display vectors flag
884 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
887 int displayMode = HasDisplayMode() ?
888 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
890 // display mode from properties
891 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
893 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
894 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
895 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
896 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
898 if ( displayMode == 2 )
899 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
900 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
902 actor->setDisplayMode( displayMode );
907 actor->PickableOff();
909 if ( create && !isTemporary && aMgrId != -1 ) {
910 // set properties to the study
911 study->setObjectPropMap( aMgrId, entry, propMap );
915 //=================================================================
917 * GEOM_Displayer::Erase
918 * Calls Erase() method for each object in the given list
920 //=================================================================
921 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
923 const bool updateViewer )
925 SALOME_ListIteratorOfListIO Iter( theIOList );
926 for ( ; Iter.More(); Iter.Next() )
927 Erase( Iter.Value(), forced, false );
933 //=================================================================
935 * GEOM_Displayer::Redisplay
936 * Calls Redisplay() method for each object in the given list
938 //=================================================================
939 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
941 SALOME_ListIteratorOfListIO Iter( theIOList );
942 for ( ; Iter.More(); Iter.Next() )
943 Redisplay( Iter.Value(), false );
949 //=================================================================
951 * GEOM_Displayer::Update
952 * Update OCC presentaion
953 * [ Reimplemented from SALOME_Displayer ]
955 //=================================================================
956 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
958 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
959 SalomeApp_Study* study = getStudy();
961 if ( !occPrs || myShape.IsNull() || !study )
964 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
967 // specific processing for local coordinate system presentation
970 TopoDS_Face aFace = TopoDS::Face( myShape );
971 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
972 if ( !aPlane.IsNull() )
974 gp_Ax3 aPos = aPlane->Pln().Position();
975 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
977 Handle(GEOM_AISTrihedron) aTrh;
979 if ( occPrs->IsNull() )
981 // new presentation is being created
982 aTrh = new GEOM_AISTrihedron( aPlc );
983 occPrs->AddObject( aTrh );
987 // presentation is being updated
988 AIS_ListOfInteractive aList;
989 occPrs->GetObjects( aList );
990 AIS_ListIteratorOfListOfInteractive anIter( aList );
991 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
992 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
996 if ( !aTrh.IsNull() ) {
997 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
999 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1000 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1002 aTrh->SetWidth( GetWidth() );
1004 if ( !myIO.IsNull() )
1006 aTrh->setIO( myIO );
1007 aTrh->SetOwner( myIO );
1009 aTrh->SetComponent( aPlc );
1010 aTrh->SetToUpdate();
1012 occPrs->SetToActivate( ToActivate() );
1018 // processing for usual geometry presentation
1021 // if presentation is empty we try to create new one
1022 if ( occPrs->IsNull() )
1024 // create presentation (specific for vectors)
1025 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1026 : new GEOM_AISShape ( myShape, "" );
1027 // update shape properties
1028 updateShapeProperties( AISShape, true );
1030 // add shape to the presentation
1031 occPrs->AddObject( AISShape );
1033 // In accordance with ToActivate() value object will be activated/deactivated
1034 // when it will be displayed
1035 occPrs->SetToActivate( ToActivate() );
1037 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1038 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1040 // create additional wireframe shape
1041 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1042 aWirePrs->SetWidth(AISShape->Width());
1043 if ( !myIO.IsNull() ) {
1044 aWirePrs->setIO( myIO );
1045 aWirePrs->SetOwner( myIO );
1048 // add shape to the presentation
1049 occPrs->AddObject( aWirePrs );
1052 // if presentation is found -> set again shape for it
1055 AIS_ListOfInteractive IOList;
1056 occPrs->GetObjects( IOList );
1057 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1058 for ( ; Iter.More(); Iter.Next() )
1060 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1061 if ( AISShape.IsNull() )
1064 // re-set shape (it might be changed)
1065 if ( AISShape->Shape() != myShape )
1066 AISShape->Set( myShape );
1068 // update shape properties
1069 updateShapeProperties( AISShape, false );
1072 AISShape->UpdateSelection();
1073 AISShape->SetToUpdate();
1079 //=================================================================
1081 * GEOM_Displayer::Update
1082 * Update VTK presentaion
1083 * [ Reimplemented from SALOME_Displayer ]
1085 //=================================================================
1086 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1088 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1089 SalomeApp_Study* study = getStudy();
1091 if ( !vtkPrs || myShape.IsNull() || !study )
1094 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1097 // specific processing for local coordinate system presentation
1100 TopoDS_Face aFace = TopoDS::Face( myShape );
1101 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1102 if ( !aPlane.IsNull() ) {
1103 gp_Ax3 aPos = aPlane->Pln().Position();
1104 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1106 GEOM_VTKTrihedron* aTrh = 0;
1108 if ( vtkPrs->IsNull() ) {
1109 // new presentation is being created
1110 aTrh = GEOM_VTKTrihedron::New();
1111 vtkPrs->AddObject( aTrh );
1114 // presentation is being updated
1115 vtkActorCollection* actors = vtkPrs->GetObjects();
1117 actors->InitTraversal();
1118 vtkActor* a = actors->GetNextActor();
1119 while ( a && !aTrh ) {
1120 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1121 a = actors->GetNextActor();
1127 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1129 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1130 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1132 #ifdef VTK_TRIHEDRON_WIDTH
1134 // VSR: currently isn't supported
1136 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1138 aTrh->SetWidth( GetWidth() );
1141 if ( !myIO.IsNull() )
1142 aTrh->setIO( myIO );
1144 aTrh->SetPlacement( aPlc );
1151 // processing for usual geometry presentation
1154 // if presentation is empty we try to create new one
1155 if ( vtkPrs->IsNull() )
1158 GEOM_Actor* actor = GEOM_Actor::New();
1159 // update actor properties
1160 updateActorProperties( actor, true );
1161 // add actor to the presentation
1162 vtkPrs->AddObject( actor );
1165 // presentation is being updated
1166 vtkActorCollection* actors = vtkPrs->GetObjects();
1168 actors->InitTraversal();
1169 vtkActor* a = actors->GetNextActor();
1171 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1173 // update actor properties
1174 updateActorProperties( actor, false );
1175 a = actors->GetNextActor();
1183 //=================================================================
1185 * GEOM_Displayer::BuildPrs
1186 * Build presentation accordint to the current viewer type
1188 //=================================================================
1189 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1191 if ( theObj->_is_nil() )
1194 myViewFrame = GetActiveView();
1195 if ( myViewFrame == 0 )
1198 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1203 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1204 myType = theObj->GetType();
1206 // Update presentation
1212 //=================================================================
1214 * GEOM_Displayer::BuildPrs
1215 * Build presentation accordint to the current viewer type
1217 //=================================================================
1218 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1220 myViewFrame = GetActiveView();
1221 if ( theShape.IsNull() || myViewFrame == 0 )
1224 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1229 setShape( theShape );
1237 //=================================================================
1239 * GEOM_Displayer::buildPresentation
1240 * Builds/finds object's presentation for the current viewer
1241 * Calls corresponding Update() method by means of double dispatch
1244 //=================================================================
1245 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1246 SALOME_View* theViewFrame )
1248 SALOME_Prs* prs = 0;
1251 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1255 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1258 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1259 theIO->setEntry( entry.toLatin1().constData() );
1260 if ( !theIO.IsNull() )
1262 // set interactive object
1264 // Find SOBject (because shape should be published previously)
1265 SUIT_Session* session = SUIT_Session::session();
1266 SUIT_Application* app = session->activeApplication();
1269 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1272 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1275 // get CORBA reference to data object
1276 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1277 if ( !CORBA::is_nil( object ) )
1279 // downcast to GEOM object
1280 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1281 if ( !GeomObject->_is_nil() )
1283 // finally set shape
1284 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1285 myType = GeomObject->GetType();
1292 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1298 //=================================================================
1300 * GEOM_Displayer::buildSubshapePresentation
1301 * Builds/finds object's presentation for the current viewer
1302 * Calls corresponding Update() method by means of double dispatch
1303 * For not published objects (for Mantis issue 0020435)
1305 //=================================================================
1306 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1307 const QString& entry,
1308 SALOME_View* theViewFrame)
1310 SALOME_Prs* prs = 0;
1313 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1317 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1320 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1321 theIO->setEntry(entry.toLatin1().constData());
1322 if (!theIO.IsNull())
1324 // set interactive object
1326 // finally set shape
1328 myType = GEOM_SUBSHAPE;
1330 UpdatePrs(prs); // Update presentation by using of the double dispatch
1336 //=================================================================
1338 * GEOM_Displayer::internalReset
1339 * Resets internal data
1342 //=================================================================
1343 void GEOM_Displayer::internalReset()
1349 //=================================================================
1351 * GEOM_Displayer::LocalSelection
1352 * Activate selection of CAD shapes with activisation of selection
1353 * of their sub-shapes (with opened local context for OCC viewer)
1355 //=================================================================
1356 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1358 SUIT_Session* session = SUIT_Session::session();
1359 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1363 LightApp_SelectionMgr* sm = app->selectionMgr();
1365 // remove all filters from selection
1368 SALOME_View* vf = GetActiveView();
1370 if (!theIO.IsNull() && !vf->isVisible(theIO))
1372 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1373 vf->LocalSelection( prs, theMode );
1374 delete prs; // delete presentation because displayer is its owner
1378 //=================================================================
1380 * GEOM_Displayer::globalSelection
1381 * Activate selection of CAD shapes without activisation of selection
1382 * of their sub-shapes (without opened local context for OCC viewer)
1384 //=================================================================
1385 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1387 TColStd_MapOfInteger aModes;
1388 aModes.Add( theMode );
1389 GlobalSelection( aModes, update );
1392 //=================================================================
1394 * GEOM_Displayer::globalSelection
1395 * Activate selection of CAD shapes without activisation of selection
1396 * of their sub-shapes (without opened local context for OCC viewer)
1398 //=================================================================
1399 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1400 const bool update, const QList<int>* theSubShapes )
1402 SUIT_Session* session = SUIT_Session::session();
1403 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1407 SALOME_View* vf = GetActiveView();
1411 // Close local context
1412 vf->GlobalSelection( update );
1414 // Set selection filters in accordance with current mode
1415 LightApp_SelectionMgr* sm = app->selectionMgr();
1419 // Remove from selection temporary objects if necessary
1420 if ( !theModes.Contains( GEOM_PREVIEW ) )
1421 clearTemporary( sm );
1423 //@ aSel->ClearIndex();
1427 // Remove filters from AIS_InteractiveContext
1428 Handle(AIS_InteractiveContext) ic;
1429 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1432 ic = viewer->getAISContext();
1434 ic->RemoveFilters();
1437 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1440 SUIT_SelectionFilter* aFilter;
1441 if ( theModes.Extent() == 1 )
1443 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1445 if ( aMode == GEOM_COMPOUNDFILTER )
1446 aFilter = getComplexFilter( theSubShapes );
1448 aFilter = getFilter( aMode );
1450 else if ( theModes.Extent() > 1 )
1452 TColStd_MapOfInteger aTopAbsModes;
1453 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1454 QList<SUIT_SelectionFilter*> aListOfFilters;
1455 for ( ; anIter.More(); anIter.Next() )
1457 SUIT_SelectionFilter* aFilter;
1458 int aMode = anIter.Key();
1459 if ( aMode == GEOM_COMPOUNDFILTER )
1460 aFilter = getComplexFilter( theSubShapes );
1462 aFilter = getFilter( aMode );
1465 aListOfFilters.append( aFilter );
1468 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1475 sm->installFilter( aFilter );
1478 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1479 ic->AddFilter( anOCCFilter );
1484 //=================================================================
1486 * GEOM_Displayer::LocalSelection
1487 * Activate selection of CAD shapes with activisation of selection
1488 * of their sub-shapes (with opened local context for OCC viewer)
1490 //=================================================================
1491 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1493 SALOME_ListIteratorOfListIO Iter( theIOList );
1494 for ( ; Iter.More(); Iter.Next() )
1495 LocalSelection( Iter.Value(), theMode );
1498 //=================================================================
1500 * GEOM_Displayer::BeforeDisplay
1501 * Called before displaying of pars. Close local context
1502 * [ Reimplemented from SALOME_Displayer ]
1504 //=================================================================
1505 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1507 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1510 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1513 if ( ic->HasOpenedContext() )
1514 ic->CloseAllContexts();
1519 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1521 SalomeApp_Study* aStudy = getStudy();
1522 if (!aStudy) return;
1523 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1524 if ( vf && !p->IsNull() ) {
1525 int aMgrId = getViewManagerId( vf );
1526 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1527 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1528 if ( !ic.IsNull() && prs ) {
1529 AIS_ListOfInteractive objects;
1530 prs->GetObjects( objects );
1531 AIS_ListIteratorOfListOfInteractive it( objects );
1532 for ( ; it.More(); it.Next() ) {
1533 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1534 if ( sh.IsNull() ) continue;
1535 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1536 if ( IO.IsNull() ) continue;
1537 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1538 if ( aPropMap.contains( GEOM::propertyName( GEOM::Transparency ) ) ) {
1539 double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble();
1540 ic->SetTransparency( sh, transparency, true );
1547 //=================================================================
1549 * GEOM_Displayer::SetColor
1550 * Set color for shape displaying. If it is equal -1 then default color is used.
1551 * Available values are from Quantity_NameOfColor enumeration
1553 //=================================================================
1554 void GEOM_Displayer::SetColor( const int color )
1561 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1565 int GEOM_Displayer::GetColor() const
1570 bool GEOM_Displayer::HasColor() const
1572 return myColor != -1;
1575 void GEOM_Displayer::UnsetColor()
1579 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1580 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1581 myShadingColor = SalomeApp_Tools::color( col );
1584 //=================================================================
1586 * GEOM_Displayer::SetTexture
1587 * Set color for shape displaying. If it is equal -1 then default color is used.
1588 * Available values are from Quantity_NameOfColor enumeration
1590 //=================================================================
1591 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1593 if(texureFileName!="")
1595 myTexture = texureFileName;
1599 bool GEOM_Displayer::HasTexture() const
1601 return myTexture != "";
1604 std::string GEOM_Displayer::GetTexture() const
1609 //=================================================================
1611 * GEOM_Displayer::SetWidth
1612 * Set width of shape displaying. If it is equal -1 then default width is used.
1614 //=================================================================
1615 void GEOM_Displayer::SetWidth( const double width )
1620 double GEOM_Displayer::GetWidth() const
1625 bool GEOM_Displayer::HasWidth() const
1627 return myWidth != -1;
1630 void GEOM_Displayer::UnsetWidth()
1636 int GEOM_Displayer::GetIsosWidth() const
1641 void GEOM_Displayer::SetIsosWidth(const int width)
1643 myIsosWidth = width;
1646 bool GEOM_Displayer::HasIsosWidth() const
1648 return myIsosWidth != -1;
1652 //=================================================================
1654 * GEOM_Displayer::SetToActivate
1655 * This method is used for activisation/deactivisation of objects to be displayed
1657 //=================================================================
1658 void GEOM_Displayer::SetToActivate( const bool toActivate )
1660 myToActivate = toActivate;
1662 bool GEOM_Displayer::ToActivate() const
1664 return myToActivate;
1667 //=================================================================
1669 * GEOM_Displayer::clearTemporary
1670 * Removes from selection temporary objects
1672 //=================================================================
1673 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1675 SALOME_ListIO selected, toSelect;
1676 theSelMgr->selectedObjects( selected );
1678 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1679 Handle(SALOME_InteractiveObject) io = it.Value();
1680 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1681 toSelect.Append( it.Value() );
1684 theSelMgr->setSelectedObjects( toSelect, true );
1687 void GEOM_Displayer::SetName( const char* theName )
1692 void GEOM_Displayer::UnsetName()
1697 SalomeApp_Study* GEOM_Displayer::getStudy() const
1699 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1702 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1707 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1712 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1714 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
1715 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
1716 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
1717 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aCompObj ) ) && (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
1720 int GEOM_Displayer::SetDisplayMode( const int theMode )
1722 int aPrevMode = myDisplayMode;
1723 if ( theMode != -1 ) {
1724 myDisplayMode = theMode;
1725 myHasDisplayMode = true;
1733 int GEOM_Displayer::GetDisplayMode() const
1735 return myDisplayMode;
1738 int GEOM_Displayer::UnsetDisplayMode()
1740 int aPrevMode = myDisplayMode;
1741 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1742 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1743 myHasDisplayMode = false;
1747 bool GEOM_Displayer::HasDisplayMode() const
1749 return myHasDisplayMode;
1752 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1754 static QList<QColor> colors;
1756 if ( colors.isEmpty() ) {
1758 for (int s = 0; s < 2 ; s++)
1760 for (int v = 100; v >= 40; v = v - 20)
1762 for (int h = 0; h < 359 ; h = h + 60)
1764 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1770 static int currentColor = 0;
1772 SALOMEDS::Color color;
1773 color.R = (double)colors[currentColor].red() / 255.0;
1774 color.G = (double)colors[currentColor].green() / 255.0;
1775 color.B = (double)colors[currentColor].blue() / 255.0;
1777 currentColor = (currentColor+1) % colors.count();
1782 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1785 int aTolerance = 64;
1786 int anIterations = 0;
1792 if( anIterations % aPeriod == 0 )
1795 if( aTolerance < 1 )
1798 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1800 aHue = (int)( 360.0 * rand() / RAND_MAX );
1801 //std::cout << "Hue = " << aHue << std::endl;
1803 //std::cout << "Auto colors : ";
1805 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1806 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1807 for( ; it != itEnd; ++it )
1809 SALOMEDS::Color anAutoColor = *it;
1810 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1813 aQColor.getHsv( &h, &s, &v );
1814 //std::cout << h << " ";
1815 if( abs( h - aHue ) < aTolerance )
1818 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1822 //std::cout << std::endl;
1828 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1830 aColor.setHsv( aHue, 255, 255 );
1832 SALOMEDS::Color aSColor;
1833 aSColor.R = (double)aColor.red() / 255.0;
1834 aSColor.G = (double)aColor.green() / 255.0;
1835 aSColor.B = (double)aColor.blue() / 255.0;
1840 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1841 const QString& entry,
1844 // get default properties for the explicitly specified default view type
1845 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1847 if ( study && view ) {
1848 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1849 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1850 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1852 if ( viewModel && viewId != -1 ) {
1853 // get properties from the study
1854 PropMap storedMap = study->getObjectPropMap( viewId, entry );
1855 // overwrite default properties from stored ones (that are specified)
1856 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1857 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1858 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
1859 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1861 // ... specific processing for color
1862 // ... current implementation is to use same stored color for all aspects
1863 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1864 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1865 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1866 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1867 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1868 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1869 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1872 if ( !entry.isEmpty() ) {
1873 // get CORBA reference to geom object
1874 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1876 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1877 if ( !CORBA::is_nil( object ) ) {
1878 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1879 // check that geom object has color properly set
1880 bool hasColor = false;
1881 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1882 // set color from geometry object (only once, if it is not yet set in GUI)
1883 // current implementation is to use same color for all aspects
1884 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1885 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1886 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1887 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
1888 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1889 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
1890 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
1891 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
1893 // check that object has point marker properly set
1894 GEOM::marker_type mType = geomObject->GetMarkerType();
1895 GEOM::marker_size mSize = geomObject->GetMarkerSize();
1896 int mTextureId = geomObject->GetMarkerTexture();
1897 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
1898 ( mType == GEOM::MT_USER && mTextureId > 0 );
1899 // set point marker from geometry object (only once, if it is not yet set in GUI)
1900 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
1901 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
1903 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1904 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
1906 else if ( mType == GEOM::MT_USER ) {
1908 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
1919 PropMap GEOM_Displayer::getDefaultPropertyMap()
1923 // get resource manager
1924 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1926 // fill in the properties map with default values
1928 // - visibility (false by default)
1929 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
1931 // - nb isos (take default value from preferences)
1932 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
1933 QString( "%1%2%3" ).
1934 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
1935 arg( GEOM::subSectionSeparator() ).
1936 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
1938 // - transparency (opacity = 1-transparency)
1939 propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
1941 // - display mode (take default value from preferences)
1942 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
1943 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
1945 // - show edges direction flag (false by default)
1946 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
1948 // - shading color (take default value from preferences)
1949 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
1950 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
1952 // - wireframe color (take default value from preferences)
1953 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
1954 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
1956 // - standalone edges color (take default value from preferences)
1957 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
1958 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
1960 // - free boundaries color (take default value from preferences)
1961 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
1962 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
1964 // - points color (take default value from preferences)
1965 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
1966 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
1968 // - isos color (take default value from preferences)
1969 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
1970 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
1972 // - outlines color (take default value from preferences)
1973 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
1974 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
1976 // - deflection coefficient (take default value from preferences)
1977 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
1978 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
1980 // - material (take default value from preferences)
1981 Material_Model material;
1982 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
1983 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
1985 // - edge width (take default value from preferences)
1986 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
1987 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
1989 // - isos width (take default value from preferences)
1990 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
1991 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
1993 // - point marker (take default value from preferences)
1994 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1995 QString( "%1%2%3" ).
1996 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
1997 arg( GEOM::subSectionSeparator() ).
1998 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2000 // - top-level flag (false by default)
2001 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2006 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2007 SALOMEDS::Color aSColor;
2010 SUIT_Session* session = SUIT_Session::session();
2011 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2013 if ( app && !theGeomObject->_is_nil()) {
2014 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2017 _PTR(Study) aStudy = study->studyDS();
2018 aSColor = theGeomObject->GetColor();
2019 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2021 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2022 bool general_autocolor = true;
2023 #else // auto-color for groups only
2024 bool general_autocolor = false;
2025 #endif // GENERAL_AUTOCOLOR
2026 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2027 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2028 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2029 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2030 aSColor = getPredefinedUniqueColor();
2032 #else // old algorithm for auto-colors
2033 QList<SALOMEDS::Color> aReservedColors;
2034 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2035 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2036 if ( aMainSObject ) {
2037 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2038 for ( ; it->More(); it->Next() ) {
2039 _PTR(SObject) aChildSObject( it->Value() );
2040 GEOM::GEOM_Object_var aChildObject =
2041 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2042 if ( CORBA::is_nil( aChildObject ) )
2045 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2046 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2047 aReservedColors.append( aReservedColor );
2050 aSColor = getUniqueColor( aReservedColors );
2052 #endif // SIMPLE_AUTOCOLOR
2062 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2063 const bool eraseOnlyChildren) {
2064 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2068 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2072 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2077 // Erase from all views
2078 QList<SALOME_View*> views;
2080 ViewManagerList vmans = app->viewManagers();
2081 SUIT_ViewManager* vman;
2082 foreach ( vman, vmans ) {
2083 SUIT_ViewModel* vmod = vman->getViewModel();
2084 view = dynamic_cast<SALOME_View*> ( vmod );
2086 views.append( view );
2089 if( views.count() == 0 )
2092 //Erase childrens w/o update views
2093 DataObjectList listObj = parent->children( true );
2094 SUIT_DataObject* obj;
2095 foreach( obj, listObj ) {
2096 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2098 foreach ( view, views ) {
2099 Handle(SALOME_InteractiveObject) anIO =
2100 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2101 Erase(anIO, false, false, view);
2105 //Erase parent with view update or repaint views
2106 foreach ( view, views ) {
2107 if(!eraseOnlyChildren)
2108 Erase(theIO, false, true, view);