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>
75 #include <OCCViewer_ViewWindow.h>
76 #include <OCCViewer_ViewPort3d.h>
79 #include <AIS_Drawer.hxx>
80 #include <AIS_ListIteratorOfListOfInteractive.hxx>
81 #include <Aspect_ColorScale.hxx>
82 #include <Prs3d_IsoAspect.hxx>
83 #include <Prs3d_PointAspect.hxx>
84 #include <StdSelect_TypeOfEdge.hxx>
85 #include <StdSelect_TypeOfFace.hxx>
86 #include <StdSelect_DisplayMode.hxx>
87 #include <TopoDS_Face.hxx>
88 #include <BRep_Tool.hxx>
89 #include <Geom_Plane.hxx>
90 #include <Geom_Axis2Placement.hxx>
91 #include <Graphic3d_AspectFillArea3d.hxx>
93 #include <TColStd_MapOfInteger.hxx>
94 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
95 #include <TopoDS_Iterator.hxx>
96 #include <Graphic3d_AspectMarker3d.hxx>
97 #include <TopTools_MapOfShape.hxx>
98 #include <TopTools_ListOfShape.hxx>
99 #include <TopTools_ListIteratorOfListOfShape.hxx>
100 #include <TopoDS.hxx>
102 #include <Prs3d_ShadingAspect.hxx>
104 #include <BRepMesh_IncrementalMesh.hxx>
107 #include <vtkActorCollection.h>
108 #include <vtkProperty.h>
111 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
113 #include <GEOMImpl_Types.hxx>
115 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
116 #include <TColStd_HArray1OfByte.hxx>
118 #include <Graphic3d_HArray1OfBytes.hxx>
121 // If the next macro is defined, autocolor feature works for all sub-shapes;
122 // if it is undefined, autocolor feature works for groups only
123 #define GENERAL_AUTOCOLOR
124 // Below macro, when uncommented, switches on simplified (more performant) algorithm
125 // of auto-color picking up
126 #define SIMPLE_AUTOCOLOR
128 // Hard-coded value of shape deflection coefficient for VTK viewer
129 const double VTK_MIN_DEFLECTION = 0.001;
131 //================================================================
132 // Function : getActiveStudy
133 // Purpose : Get active study, returns 0 if no open study frame
134 //================================================================
135 static inline SalomeApp_Study* getActiveStudy()
137 SUIT_Session* session = SUIT_Session::session();
138 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
140 return ( SalomeApp_Study* )app->activeStudy();
144 static inline int getViewManagerId( SALOME_View* theViewFrame) {
145 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
146 SUIT_ViewManager* aViewMgr = 0;
148 aViewMgr = aModel->getViewManager();
149 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
152 //================================================================
153 // Function : getTopAbsMode
154 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
155 // one from GEOMImpl_Types.h
156 //================================================================
157 static inline int getTopAbsMode( const int implType )
161 case GEOM_COMPOUND : return TopAbs_COMPOUND;
162 case GEOM_SOLID : return TopAbs_SOLID;
163 case GEOM_SHELL : return TopAbs_SHELL;
164 case GEOM_FACE : return TopAbs_FACE;
165 case GEOM_WIRE : return TopAbs_WIRE;
166 case GEOM_EDGE : return TopAbs_EDGE;
167 case GEOM_POINT : return TopAbs_VERTEX;
172 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
174 if ( shape.IsNull() )
177 int ret = shape.ShapeType();
179 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
180 TopoDS_Iterator it(shape, Standard_True, Standard_False);
181 for (; it.More(); it.Next()) {
182 TopoDS_Shape sub_shape = it.Value();
183 if ( sub_shape.IsNull() ) continue;
184 int stype = getMinMaxShapeType( sub_shape, ismin );
185 if ( stype == TopAbs_SHAPE ) continue;
186 if ( ismin && stype > ret )
188 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
196 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
198 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
201 //================================================================
202 // Function : getFilter
203 // Purpose : Get filter corresponding to the type of object
204 // from GEOMImpl_Types.h
205 //================================================================
206 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
208 SUIT_SelectionFilter* aFilter;
210 int aTopAbsMode = getTopAbsMode( theMode );
211 if ( aTopAbsMode != -1 )
212 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
216 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
217 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
219 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
220 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
221 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
222 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
223 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
224 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
226 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
228 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
229 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
231 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
237 //================================================================
238 // Function : getComplexFilter
239 // Purpose : Get compound filter corresponding to the type of
240 // object from GEOMImpl_Types.h
241 //================================================================
242 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
244 GEOM_CompoundFilter* aFilter;
246 if(aSubShapes != NULL ) {
247 aFilter = new GEOM_CompoundFilter(getStudy());
248 QList<int> aTopAbsTypes;
249 QList<int>::const_iterator it;
250 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
251 int topAbsMode = getTopAbsMode(*it);
252 if(topAbsMode != -1 )
253 aTopAbsTypes.append(topAbsMode);
255 aFilter->addSubTypes(aTopAbsTypes);
261 //================================================================
262 // Function : getEntry
264 //================================================================
265 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
267 SUIT_Session* session = SUIT_Session::session();
268 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
271 CORBA::String_var IOR = app->orb()->object_to_string( object );
272 if ( strcmp(IOR.in(), "") != 0 )
274 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
275 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
283 //================================================================
284 // Function : getName
286 //================================================================
287 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
289 SUIT_Session* session = SUIT_Session::session();
290 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
293 CORBA::String_var IOR = app->orb()->object_to_string( object );
294 if ( strcmp(IOR.in(), "") != 0 )
296 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
297 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
299 _PTR(GenericAttribute) anAttr;
301 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
303 _PTR(AttributeName) aNameAttr( anAttr );
304 return aNameAttr->Value();
312 //=================================================================
314 * GEOM_Displayer::GEOM_Displayer
317 //=================================================================
318 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
321 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
326 SUIT_Session* session = SUIT_Session::session();
327 SUIT_ResourceMgr* resMgr = session->resourceMgr();
329 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
330 myShadingColor = SalomeApp_Tools::color( col );
332 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
333 myHasDisplayMode = false;
335 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
336 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
337 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
339 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
340 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
341 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
344 // This color is used for shape displaying. If it is equal -1 then
345 // default color is used.
352 // This parameter is used for activisation/deactivisation of objects to be displayed
354 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
355 // Activate parallel vizualisation only for testing purpose
356 // and if the corresponding env variable is set to 1
357 char* parallel_visu = getenv("PARALLEL_VISU");
358 if (parallel_visu && atoi(parallel_visu))
360 MESSAGE("Parallel visualisation on");
361 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
367 myFieldDataType = GEOM::FDT_Double;
368 myFieldDimension = 0;
369 myFieldStepRangeMin = 0;
370 myFieldStepRangeMax = 0;
373 //=================================================================
375 * GEOM_Displayer::~GEOM_Displayer
378 //=================================================================
379 GEOM_Displayer::~GEOM_Displayer()
383 //=================================================================
385 * GEOM_Displayer::Display
386 * Display interactive object in the current viewer
388 //=================================================================
389 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
390 const bool updateViewer,
391 SALOME_View* theViewFrame )
393 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
396 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
400 vf->BeforeDisplay( this, prs );
402 vf->AfterDisplay( this, prs );
407 int aMgrId = getViewManagerId(vf);
408 SalomeApp_Study* aStudy = getStudy();
409 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
411 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
413 delete prs; // delete presentation because displayer is its owner
418 //=================================================================
420 * GEOM_Displayer::Display
421 * This overloaded Display() method can be useful for operations
422 * not using dialog boxes.
424 //=================================================================
425 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
427 if ( theObj->_is_nil() )
430 std::string entry = getEntry( theObj );
432 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
437 //=================================================================
439 * GEOM_Displayer::Erase
440 * Erase interactive object in the current viewer
442 //=================================================================
443 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
445 const bool updateViewer,
446 SALOME_View* theViewFrame )
448 if ( theIO.IsNull() )
451 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
454 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
456 vf->BeforeErase( this, prs );
457 vf->Erase( prs, forced );
458 vf->AfterErase( this, prs );
461 delete prs; // delete presentation because displayer is its owner
463 int aMgrId = getViewManagerId(vf);
464 SalomeApp_Study* aStudy = getStudy();
465 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
467 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
472 //=================================================================
474 * GEOM_Displayer::Erase
475 * Erase geometry object in the current viewer
477 //=================================================================
478 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
480 const bool updateViewer )
482 std::string entry = getEntry( theObj );
485 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
486 forced, updateViewer);
490 //=================================================================
492 * GEOM_Displayer::Redisplay
493 * Redisplay (erase and then display again) interactive object
494 * in the current viewer
496 //=================================================================
497 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
498 const bool updateViewer,
499 const bool checkActiveViewer )
501 // Remove the object permanently (<forced> == true)
502 SUIT_Session* ses = SUIT_Session::session();
503 SUIT_Application* app = ses->activeApplication();
506 SUIT_Desktop* desk = app->desktop();
507 QList<SUIT_ViewWindow*> wnds = desk->windows();
508 SUIT_ViewWindow* wnd;
509 QListIterator<SUIT_ViewWindow*> it( wnds );
510 while ( it.hasNext() && (wnd = it.next()) )
512 SUIT_ViewManager* vman = wnd->getViewManager();
515 SUIT_ViewModel* vmodel = vman->getViewModel();
518 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
521 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
523 Erase( theIO, true, false, view );
524 Display( theIO, updateViewer, view );
533 //=================================================================
535 * GEOM_Displayer::Display
536 * Calls Display() method for each object in the given list
538 //=================================================================
539 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
541 SALOME_ListIteratorOfListIO Iter( theIOList );
542 for ( ; Iter.More(); Iter.Next() ) {
543 Display( Iter.Value(), false );
549 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
551 // VSR: this method can be improved in future:
552 // to improve performance, the default values from resource manager should be cached in the displayer
553 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
556 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
558 // VSR: this method can be improved in future:
559 // to improve performance, the default values from resource manager should be cached in the displayer
560 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
563 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
565 // check that shape is not null
566 if ( AISShape.IsNull() ) return;
568 // check that study is active
569 SalomeApp_Study* study = getStudy();
570 if ( !study ) return;
572 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
573 !TopoDS_Iterator(myShape).More() )
574 return; // NPAL15983 (Bug when displaying empty groups)
576 // set interactive object
578 Handle( SALOME_InteractiveObject ) anIO;
580 if ( !myIO.IsNull() ) {
581 AISShape->setIO( myIO );
582 AISShape->SetOwner( myIO );
585 else if ( !myName.empty() ) {
586 // workaround to allow selection of temporary objects
587 static int tempId = 0;
588 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
589 AISShape->setIO( anIO );
590 AISShape->SetOwner( anIO );
593 // flag: only vertex or compound of vertices is processed (specific handling)
594 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
595 // presentation study entry (empty for temporary objects like preview)
596 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
597 // flag: temporary object
598 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
599 // currently active view window's ID (-1 if no active view)
600 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
602 // get presentation properties
603 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
605 // Temporary staff: vertex must be infinite for correct visualization
606 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
609 Material_Model material;
610 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
612 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
613 // - set front material properties
614 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
615 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
616 // - set back material properties
617 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
618 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
619 // - switch to default (both sides) facing mode
620 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
626 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
627 // we set it to the shape not taking into account material properties
628 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
630 else if ( !material.isPhysical() ) {
631 // shading color from properties is used only for non-physical materials
632 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
636 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
637 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
638 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
639 AISShape->Attributes()->SetLineAspect( anAspect );
641 // - unfree boundaries color
642 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
643 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
644 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
645 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
647 // - free boundaries color
648 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
649 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
650 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
651 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
653 // - standalone edges color
654 anAspect = AISShape->Attributes()->WireAspect();
655 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
656 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
657 AISShape->Attributes()->SetWireAspect( anAspect );
659 // - color for edges in shading+edges mode
660 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
663 AISShape->storeBoundaryColors();
666 AISShape->SetDisplayMode( HasDisplayMode() ?
667 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
669 // display mode from properties
670 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
672 // set display vectors flag
673 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
676 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
678 // set iso properties
679 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
680 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
681 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
682 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
683 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
684 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
685 uIsoAspect->SetColor( isosColor );
686 uIsoAspect->SetWidth( isosWidth );
687 uIsoAspect->SetNumber( uIsos );
688 vIsoAspect->SetColor( isosColor );
689 vIsoAspect->SetWidth( isosWidth );
690 vIsoAspect->SetNumber( vIsos );
691 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
692 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
694 // set deflection coefficient
695 // ... to avoid to small values of the coefficient, its lower value is limited
696 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
699 bool textureAdded = false;
700 if ( HasTexture() ) {
701 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
702 AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
703 if ( ! entry.isEmpty() ) {
704 // check that study is active
705 SalomeApp_Study* study = getActiveStudy();
707 // Store the texture in object properties for next displays
708 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
709 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
711 // Update porpeties map
712 propMap = getObjectProperties( study, entry, myViewFrame );
718 // Texture from properties
719 QString aTexture = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
720 if ( !aTexture.isEmpty() ) {
721 AISShape->SetTextureFileName( TCollection_AsciiString( aTexture.toStdString().c_str() ) );
727 AISShape->SetTextureMapOn();
728 AISShape->DisableTextureModulate();
732 AISShape->SetWidth( HasWidth() ?
733 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
735 // libe width from properties
736 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
738 // set top-level flag
739 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
741 // set point marker (for vertex / compound of vertices only)
743 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
744 if ( aList.size() == 2 ) {
745 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
746 int aTypeOfMarker = aList[0].toInt();
747 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
748 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
749 anAspect->SetScale( aScaleOfMarker );
750 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
751 anAspect->SetColor( HasColor() ?
752 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
753 (Quantity_NameOfColor)GetColor() :
754 // color from properties
755 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
756 AISShape->Attributes()->SetPointAspect( anAspect );
758 else if ( aList.size() == 1 ) {
759 // custom marker string contains "IdOfTexture"
760 int textureId = aList[0].toInt();
761 Standard_Integer aWidth, aHeight;
762 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
763 Handle(TColStd_HArray1OfByte) aTexture =
765 Handle(Graphic3d_HArray1OfBytes) aTexture =
767 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
768 if ( !aTexture.IsNull() ) {
769 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
770 Handle(Prs3d_PointAspect) aTextureAspect =
771 new Prs3d_PointAspect( HasColor() ?
772 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
773 (Quantity_NameOfColor)GetColor() :
774 // color from properties
775 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
780 Handle(Prs3d_PointAspect) aTextureAspect =
781 new Prs3d_PointAspect( HasColor() ?
782 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
783 (Quantity_NameOfColor)GetColor() :
784 // color from properties
785 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
790 AISShape->Attributes()->SetPointAspect( aTextureAspect );
795 // set field step data
796 AISShape->setFieldStepInfo( myFieldDataType,
801 myFieldStepRangeMax );
803 if ( create && !isTemporary && aMgrId != -1 ) {
804 // set properties to the study
805 study->setObjectPropMap( aMgrId, entry, propMap );
808 // AISShape->SetName(???); ??? necessary to set name ???
811 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
813 // check that actor is not null
814 if ( !actor ) return;
816 // check that study is active
817 SalomeApp_Study* study = getStudy();
818 if ( !study ) return;
820 // set interactive object
822 Handle( SALOME_InteractiveObject ) anIO;
824 if ( !myIO.IsNull() ) {
825 actor->setIO( myIO );
828 else if ( !myName.empty() ) {
829 // workaround to allow selection of temporary objects
830 static int tempId = 0;
831 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
832 actor->setIO( anIO );
835 // presentation study entry (empty for temporary objects like preview)
836 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
837 // flag: temporary object
838 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
839 // currently active view window's ID (-1 if no active view)
840 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
842 // get presentation properties
843 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
846 /////////////////////////////////////////////////////////////////////////
847 // VSR: for VTK viewer currently deflection coefficient is hardcoded
848 // due to performance problem
849 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
850 /////////////////////////////////////////////////////////////////////////
851 if ( !actor->getTopo().IsSame( myShape ) )
852 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
855 Material_Model material;
856 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
857 std::vector<vtkProperty*> mprops;
858 mprops.push_back( material.getMaterialVTKProperty( true ) );
859 mprops.push_back( material.getMaterialVTKProperty( false) );
860 actor->SetMaterial( mprops );
862 // set iso-lines properties
864 // - set number of iso-lines
865 int nbIsos[2]= { 1, 1 };
866 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
867 nbIsos[0] = isos[0].toInt();
868 nbIsos[1] = isos[1].toInt();
869 actor->SetNbIsos( nbIsos );
871 // - set iso-lines width
872 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
874 // - set iso-lines color
875 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
876 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
881 // - same color for all sub-actors
882 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
883 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
886 // shading color (for non-physical materials)
887 if ( !material.isPhysical() ) {
888 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
889 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
890 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
893 // - standalone edge color
894 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
895 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
897 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
898 // - shared edges color ???
899 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
901 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
902 // - free edges color ???
903 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
906 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
907 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
910 // - color for edges in shading+edges mode
911 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
912 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
915 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
918 actor->SetWidth( HasWidth() ?
919 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
921 // libe width from properties
922 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
924 // set display vectors flag
925 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
928 int displayMode = HasDisplayMode() ?
929 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
931 // display mode from properties
932 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
934 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
935 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
936 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
937 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
939 if ( displayMode == 2 )
940 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
941 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
943 actor->setDisplayMode( displayMode );
948 actor->PickableOff();
950 if ( create && !isTemporary && aMgrId != -1 ) {
951 // set properties to the study
952 study->setObjectPropMap( aMgrId, entry, propMap );
956 //=================================================================
958 * GEOM_Displayer::Erase
959 * Calls Erase() method for each object in the given list
961 //=================================================================
962 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
964 const bool updateViewer )
966 SALOME_ListIteratorOfListIO Iter( theIOList );
967 for ( ; Iter.More(); Iter.Next() )
968 Erase( Iter.Value(), forced, false );
974 //=================================================================
976 * GEOM_Displayer::Redisplay
977 * Calls Redisplay() method for each object in the given list
979 //=================================================================
980 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
981 const bool updateViewer,
982 const bool checkActiveViewer )
984 SALOME_ListIteratorOfListIO Iter( theIOList );
985 for ( ; Iter.More(); Iter.Next() )
986 Redisplay( Iter.Value(), false, checkActiveViewer );
992 //=================================================================
994 * GEOM_Displayer::Update
995 * Update OCC presentaion
996 * [ Reimplemented from SALOME_Displayer ]
998 //=================================================================
999 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1001 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1002 SalomeApp_Study* study = getStudy();
1004 if ( !occPrs || myShape.IsNull() || !study )
1007 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1010 // specific processing for local coordinate system presentation
1013 TopoDS_Face aFace = TopoDS::Face( myShape );
1014 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1015 if ( !aPlane.IsNull() )
1017 gp_Ax3 aPos = aPlane->Pln().Position();
1018 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1020 Handle(GEOM_AISTrihedron) aTrh;
1022 if ( occPrs->IsNull() )
1024 // new presentation is being created
1025 aTrh = new GEOM_AISTrihedron( aPlc );
1026 occPrs->AddObject( aTrh );
1030 // presentation is being updated
1031 AIS_ListOfInteractive aList;
1032 occPrs->GetObjects( aList );
1033 AIS_ListIteratorOfListOfInteractive anIter( aList );
1034 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1035 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1039 if ( !aTrh.IsNull() ) {
1040 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1042 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1043 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1045 aTrh->SetWidth( GetWidth() );
1047 if ( !myIO.IsNull() )
1049 aTrh->setIO( myIO );
1050 aTrh->SetOwner( myIO );
1052 aTrh->SetComponent( aPlc );
1053 aTrh->SetToUpdate();
1055 occPrs->SetToActivate( ToActivate() );
1061 // processing for usual geometry presentation
1064 // if presentation is empty we try to create new one
1065 if ( occPrs->IsNull() )
1067 // create presentation (specific for vectors)
1068 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1069 : new GEOM_AISShape ( myShape, "" );
1071 if( myType == GEOM_FIELD_STEP )
1072 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1073 // update shape properties
1074 updateShapeProperties( AISShape, true );
1076 // add shape to the presentation
1077 occPrs->AddObject( AISShape );
1079 // In accordance with ToActivate() value object will be activated/deactivated
1080 // when it will be displayed
1081 occPrs->SetToActivate( ToActivate() );
1083 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1084 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1086 // create additional wireframe shape
1087 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1088 aWirePrs->SetWidth(AISShape->Width());
1089 if ( !myIO.IsNull() ) {
1090 aWirePrs->setIO( myIO );
1091 aWirePrs->SetOwner( myIO );
1094 // add shape to the presentation
1095 occPrs->AddObject( aWirePrs );
1098 // if presentation is found -> set again shape for it
1101 AIS_ListOfInteractive IOList;
1102 occPrs->GetObjects( IOList );
1103 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1104 for ( ; Iter.More(); Iter.Next() )
1106 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1107 if ( AISShape.IsNull() )
1110 // re-set shape (it might be changed)
1111 if ( AISShape->Shape() != myShape )
1112 AISShape->Set( myShape );
1114 // update shape properties
1115 updateShapeProperties( AISShape, false );
1118 AISShape->UpdateSelection();
1119 AISShape->SetToUpdate();
1125 //=================================================================
1127 * GEOM_Displayer::Update
1128 * Update VTK presentaion
1129 * [ Reimplemented from SALOME_Displayer ]
1131 //=================================================================
1132 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1134 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1135 SalomeApp_Study* study = getStudy();
1137 if ( !vtkPrs || myShape.IsNull() || !study )
1140 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1143 // specific processing for local coordinate system presentation
1146 TopoDS_Face aFace = TopoDS::Face( myShape );
1147 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1148 if ( !aPlane.IsNull() ) {
1149 gp_Ax3 aPos = aPlane->Pln().Position();
1150 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1152 GEOM_VTKTrihedron* aTrh = 0;
1154 if ( vtkPrs->IsNull() ) {
1155 // new presentation is being created
1156 aTrh = GEOM_VTKTrihedron::New();
1157 vtkPrs->AddObject( aTrh );
1160 // presentation is being updated
1161 vtkActorCollection* actors = vtkPrs->GetObjects();
1163 actors->InitTraversal();
1164 vtkActor* a = actors->GetNextActor();
1165 while ( a && !aTrh ) {
1166 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1167 a = actors->GetNextActor();
1173 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1175 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1176 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1178 #ifdef VTK_TRIHEDRON_WIDTH
1180 // VSR: currently isn't supported
1182 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1184 aTrh->SetWidth( GetWidth() );
1187 if ( !myIO.IsNull() )
1188 aTrh->setIO( myIO );
1190 aTrh->SetPlacement( aPlc );
1197 // processing for usual geometry presentation
1200 // if presentation is empty we try to create new one
1201 if ( vtkPrs->IsNull() )
1204 GEOM_Actor* actor = GEOM_Actor::New();
1205 // update actor properties
1206 updateActorProperties( actor, true );
1207 // add actor to the presentation
1208 vtkPrs->AddObject( actor );
1211 // presentation is being updated
1212 vtkActorCollection* actors = vtkPrs->GetObjects();
1214 actors->InitTraversal();
1215 vtkActor* a = actors->GetNextActor();
1217 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1219 // update actor properties
1220 updateActorProperties( actor, false );
1221 a = actors->GetNextActor();
1229 //=================================================================
1231 * GEOM_Displayer::BuildPrs
1232 * Build presentation accordint to the current viewer type
1234 //=================================================================
1235 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1237 if ( theObj->_is_nil() )
1240 myViewFrame = GetActiveView();
1241 if ( myViewFrame == 0 )
1244 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1249 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1250 myType = theObj->GetType();
1252 // Update presentation
1258 //=================================================================
1260 * GEOM_Displayer::BuildPrs
1261 * Build presentation accordint to the current viewer type
1263 //=================================================================
1264 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1266 myViewFrame = GetActiveView();
1267 if ( theShape.IsNull() || myViewFrame == 0 )
1270 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1275 setShape( theShape );
1283 //=================================================================
1285 * GEOM_Displayer::buildPresentation
1286 * Builds/finds object's presentation for the current viewer
1287 * Calls corresponding Update() method by means of double dispatch
1290 //=================================================================
1291 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1292 SALOME_View* theViewFrame )
1294 SALOME_Prs* prs = 0;
1297 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1301 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1304 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1305 theIO->setEntry( entry.toLatin1().constData() );
1306 if ( !theIO.IsNull() )
1308 // set interactive object
1310 // Find SOBject (because shape should be published previously)
1311 SUIT_Session* session = SUIT_Session::session();
1312 SUIT_Application* app = session->activeApplication();
1315 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1318 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1321 // get CORBA reference to data object
1322 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1323 if ( !CORBA::is_nil( object ) )
1325 // downcast to GEOM base object
1326 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1327 if ( !GeomBaseObject->_is_nil() )
1329 myType = GeomBaseObject->GetType();
1331 // downcast to GEOM object
1332 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1333 if ( myType == GEOM_FIELD_STEP )
1335 // get the GEOM object from the field's shape
1336 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1337 if ( !GeomFieldStep->_is_nil() )
1339 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1340 if ( !GeomField->_is_nil() )
1341 GeomObject = GeomField->GetShape();
1344 // read the field step information
1345 readFieldStepInfo( GeomFieldStep );
1348 if ( !GeomObject->_is_nil() )
1350 // finally set shape
1351 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1359 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1365 //=================================================================
1367 * GEOM_Displayer::buildSubshapePresentation
1368 * Builds/finds object's presentation for the current viewer
1369 * Calls corresponding Update() method by means of double dispatch
1370 * For not published objects (for Mantis issue 0020435)
1372 //=================================================================
1373 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1374 const QString& entry,
1375 SALOME_View* theViewFrame)
1377 SALOME_Prs* prs = 0;
1380 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1384 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1387 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1388 theIO->setEntry(entry.toLatin1().constData());
1389 if (!theIO.IsNull())
1391 // set interactive object
1393 // finally set shape
1395 myType = GEOM_SUBSHAPE;
1397 UpdatePrs(prs); // Update presentation by using of the double dispatch
1403 //=================================================================
1405 * GEOM_Displayer::internalReset
1406 * Resets internal data
1409 //=================================================================
1410 void GEOM_Displayer::internalReset()
1415 myFieldDataType = GEOM::FDT_Double;
1416 myFieldDimension = 0;
1417 myFieldStepData.clear();
1418 myFieldStepName.Clear();
1419 myFieldStepRangeMin = 0;
1420 myFieldStepRangeMax = 0;
1423 //=================================================================
1425 * GEOM_Displayer::LocalSelection
1426 * Activate selection of CAD shapes with activisation of selection
1427 * of their sub-shapes (with opened local context for OCC viewer)
1429 //=================================================================
1430 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1432 SUIT_Session* session = SUIT_Session::session();
1433 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1437 LightApp_SelectionMgr* sm = app->selectionMgr();
1439 // remove all filters from selection
1442 SALOME_View* vf = GetActiveView();
1444 if (!theIO.IsNull() && !vf->isVisible(theIO))
1446 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1447 vf->LocalSelection( prs, theMode );
1448 delete prs; // delete presentation because displayer is its owner
1452 //=================================================================
1454 * GEOM_Displayer::globalSelection
1455 * Activate selection of CAD shapes without activisation of selection
1456 * of their sub-shapes (without opened local context for OCC viewer)
1458 //=================================================================
1459 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1461 TColStd_MapOfInteger aModes;
1462 aModes.Add( theMode );
1463 GlobalSelection( aModes, update );
1466 //=================================================================
1468 * GEOM_Displayer::globalSelection
1469 * Activate selection of CAD shapes without activisation of selection
1470 * of their sub-shapes (without opened local context for OCC viewer)
1472 //=================================================================
1473 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1474 const bool update, const QList<int>* theSubShapes )
1476 SUIT_Session* session = SUIT_Session::session();
1477 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1481 SALOME_View* vf = GetActiveView();
1485 // Close local context
1486 vf->GlobalSelection( update );
1488 // Set selection filters in accordance with current mode
1489 LightApp_SelectionMgr* sm = app->selectionMgr();
1493 // Remove from selection temporary objects if necessary
1494 if ( !theModes.Contains( GEOM_PREVIEW ) )
1495 clearTemporary( sm );
1497 //@ aSel->ClearIndex();
1501 // Remove filters from AIS_InteractiveContext
1502 Handle(AIS_InteractiveContext) ic;
1503 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1506 ic = viewer->getAISContext();
1508 ic->RemoveFilters();
1511 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1514 SUIT_SelectionFilter* aFilter;
1515 if ( theModes.Extent() == 1 )
1517 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1519 if ( aMode == GEOM_COMPOUNDFILTER )
1520 aFilter = getComplexFilter( theSubShapes );
1522 aFilter = getFilter( aMode );
1524 else if ( theModes.Extent() > 1 )
1526 TColStd_MapOfInteger aTopAbsModes;
1527 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1528 QList<SUIT_SelectionFilter*> aListOfFilters;
1529 for ( ; anIter.More(); anIter.Next() )
1531 SUIT_SelectionFilter* aFilter;
1532 int aMode = anIter.Key();
1533 if ( aMode == GEOM_COMPOUNDFILTER )
1534 aFilter = getComplexFilter( theSubShapes );
1536 aFilter = getFilter( aMode );
1539 aListOfFilters.append( aFilter );
1542 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1549 sm->installFilter( aFilter );
1552 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1553 ic->AddFilter( anOCCFilter );
1558 //=================================================================
1560 * GEOM_Displayer::LocalSelection
1561 * Activate selection of CAD shapes with activisation of selection
1562 * of their sub-shapes (with opened local context for OCC viewer)
1564 //=================================================================
1565 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1567 SALOME_ListIteratorOfListIO Iter( theIOList );
1568 for ( ; Iter.More(); Iter.Next() )
1569 LocalSelection( Iter.Value(), theMode );
1572 //=================================================================
1574 * GEOM_Displayer::BeforeDisplay
1575 * Called before displaying of pars. Close local context
1576 * [ Reimplemented from SALOME_Displayer ]
1578 //=================================================================
1579 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1581 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1584 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1587 if ( ic->HasOpenedContext() )
1588 ic->CloseAllContexts();
1593 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1595 UpdateColorScale(false,false);
1598 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1600 LightApp_Displayer::AfterErase( v, p );
1601 UpdateColorScale(false,false);
1604 //=================================================================
1606 * GEOM_Displayer::SetColor
1607 * Set color for shape displaying. If it is equal -1 then default color is used.
1608 * Available values are from Quantity_NameOfColor enumeration
1610 //=================================================================
1611 void GEOM_Displayer::SetColor( const int color )
1618 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1622 int GEOM_Displayer::GetColor() const
1627 bool GEOM_Displayer::HasColor() const
1629 return myColor != -1;
1632 void GEOM_Displayer::UnsetColor()
1636 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1637 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1638 myShadingColor = SalomeApp_Tools::color( col );
1641 //=================================================================
1643 * GEOM_Displayer::SetTexture
1644 * Set color for shape displaying. If it is equal -1 then default color is used.
1645 * Available values are from Quantity_NameOfColor enumeration
1647 //=================================================================
1648 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1650 if(texureFileName!="")
1652 myTexture = texureFileName;
1656 bool GEOM_Displayer::HasTexture() const
1658 return myTexture != "";
1661 std::string GEOM_Displayer::GetTexture() const
1666 //=================================================================
1668 * GEOM_Displayer::SetWidth
1669 * Set width of shape displaying. If it is equal -1 then default width is used.
1671 //=================================================================
1672 void GEOM_Displayer::SetWidth( const double width )
1677 double GEOM_Displayer::GetWidth() const
1682 bool GEOM_Displayer::HasWidth() const
1684 return myWidth != -1;
1687 void GEOM_Displayer::UnsetWidth()
1693 int GEOM_Displayer::GetIsosWidth() const
1698 void GEOM_Displayer::SetIsosWidth(const int width)
1700 myIsosWidth = width;
1703 bool GEOM_Displayer::HasIsosWidth() const
1705 return myIsosWidth != -1;
1709 //=================================================================
1711 * GEOM_Displayer::SetToActivate
1712 * This method is used for activisation/deactivisation of objects to be displayed
1714 //=================================================================
1715 void GEOM_Displayer::SetToActivate( const bool toActivate )
1717 myToActivate = toActivate;
1719 bool GEOM_Displayer::ToActivate() const
1721 return myToActivate;
1724 //=================================================================
1726 * GEOM_Displayer::clearTemporary
1727 * Removes from selection temporary objects
1729 //=================================================================
1730 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1732 SALOME_ListIO selected, toSelect;
1733 theSelMgr->selectedObjects( selected );
1735 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1736 Handle(SALOME_InteractiveObject) io = it.Value();
1737 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1738 toSelect.Append( it.Value() );
1741 theSelMgr->setSelectedObjects( toSelect, true );
1744 void GEOM_Displayer::SetName( const char* theName )
1749 void GEOM_Displayer::UnsetName()
1754 SalomeApp_Study* GEOM_Displayer::getStudy() const
1756 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1759 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1764 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1769 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
1770 const int theFieldDimension,
1771 const QList<QVariant>& theFieldStepData,
1772 const TCollection_AsciiString& theFieldStepName,
1773 const double theFieldStepRangeMin,
1774 const double theFieldStepRangeMax )
1776 myFieldDataType = theFieldDataType;
1777 myFieldDimension = theFieldDimension;
1778 myFieldStepData = theFieldStepData;
1779 myFieldStepName = theFieldStepName;
1780 myFieldStepRangeMin = theFieldStepRangeMin;
1781 myFieldStepRangeMax = theFieldStepRangeMax;
1784 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1786 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
1787 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
1788 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
1789 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
1790 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
1791 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
1794 int GEOM_Displayer::SetDisplayMode( const int theMode )
1796 int aPrevMode = myDisplayMode;
1797 if ( theMode != -1 ) {
1798 myDisplayMode = theMode;
1799 myHasDisplayMode = true;
1807 int GEOM_Displayer::GetDisplayMode() const
1809 return myDisplayMode;
1812 int GEOM_Displayer::UnsetDisplayMode()
1814 int aPrevMode = myDisplayMode;
1815 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1816 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1817 myHasDisplayMode = false;
1821 bool GEOM_Displayer::HasDisplayMode() const
1823 return myHasDisplayMode;
1826 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1828 static QList<QColor> colors;
1830 if ( colors.isEmpty() ) {
1832 for (int s = 0; s < 2 ; s++)
1834 for (int v = 100; v >= 40; v = v - 20)
1836 for (int h = 0; h < 359 ; h = h + 60)
1838 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1844 static int currentColor = 0;
1846 SALOMEDS::Color color;
1847 color.R = (double)colors[currentColor].red() / 255.0;
1848 color.G = (double)colors[currentColor].green() / 255.0;
1849 color.B = (double)colors[currentColor].blue() / 255.0;
1851 currentColor = (currentColor+1) % colors.count();
1856 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1859 int aTolerance = 64;
1860 int anIterations = 0;
1866 if( anIterations % aPeriod == 0 )
1869 if( aTolerance < 1 )
1872 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1874 aHue = (int)( 360.0 * rand() / RAND_MAX );
1875 //std::cout << "Hue = " << aHue << std::endl;
1877 //std::cout << "Auto colors : ";
1879 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1880 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1881 for( ; it != itEnd; ++it )
1883 SALOMEDS::Color anAutoColor = *it;
1884 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1887 aQColor.getHsv( &h, &s, &v );
1888 //std::cout << h << " ";
1889 if( abs( h - aHue ) < aTolerance )
1892 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1896 //std::cout << std::endl;
1902 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1904 aColor.setHsv( aHue, 255, 255 );
1906 SALOMEDS::Color aSColor;
1907 aSColor.R = (double)aColor.red() / 255.0;
1908 aSColor.G = (double)aColor.green() / 255.0;
1909 aSColor.B = (double)aColor.blue() / 255.0;
1914 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1915 const QString& entry,
1918 // get default properties for the explicitly specified default view type
1919 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1921 if ( study && view ) {
1922 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1923 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1924 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1926 if ( viewModel && viewId != -1 ) {
1927 // get properties from the study
1928 PropMap storedMap = study->getObjectPropMap( viewId, entry );
1929 // overwrite default properties from stored ones (that are specified)
1930 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1931 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1932 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
1933 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1935 // ... specific processing for color
1936 // ... current implementation is to use same stored color for all aspects
1937 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1938 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1939 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1940 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1941 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1942 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1943 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1946 if ( !entry.isEmpty() ) {
1947 // get CORBA reference to geom object
1948 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1950 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1951 if ( !CORBA::is_nil( object ) ) {
1952 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1953 if ( !CORBA::is_nil( geomObject ) ) { // to check
1954 // check that geom object has color properly set
1955 bool hasColor = false;
1956 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1957 // set color from geometry object (only once, if it is not yet set in GUI)
1958 // current implementation is to use same color for all aspects
1959 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1960 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1961 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1962 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
1963 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1964 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
1965 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
1966 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
1968 // check that object has point marker properly set
1969 GEOM::marker_type mType = geomObject->GetMarkerType();
1970 GEOM::marker_size mSize = geomObject->GetMarkerSize();
1971 int mTextureId = geomObject->GetMarkerTexture();
1972 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
1973 ( mType == GEOM::MT_USER && mTextureId > 0 );
1974 // set point marker from geometry object (only once, if it is not yet set in GUI)
1975 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
1976 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
1978 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1979 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
1981 else if ( mType == GEOM::MT_USER ) {
1983 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
1995 PropMap GEOM_Displayer::getDefaultPropertyMap()
1999 // get resource manager
2000 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2002 // fill in the properties map with default values
2004 // - visibility (false by default)
2005 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2007 // - nb isos (take default value from preferences)
2008 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2009 QString( "%1%2%3" ).
2010 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2011 arg( GEOM::subSectionSeparator() ).
2012 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2014 // - transparency (opacity = 1-transparency)
2015 propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2017 // - display mode (take default value from preferences)
2018 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2019 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2021 // - show edges direction flag (false by default)
2022 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2024 // - shading color (take default value from preferences)
2025 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2026 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2028 // - wireframe color (take default value from preferences)
2029 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2030 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2032 // - standalone edges color (take default value from preferences)
2033 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2034 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2036 // - free boundaries color (take default value from preferences)
2037 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2038 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2040 // - points color (take default value from preferences)
2041 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2042 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2044 // - isos color (take default value from preferences)
2045 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2046 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2048 // - outlines color (take default value from preferences)
2049 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2050 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2052 // - deflection coefficient (take default value from preferences)
2053 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2054 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2056 // - material (take default value from preferences)
2057 Material_Model material;
2058 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2059 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2061 // - edge width (take default value from preferences)
2062 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2063 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2065 // - isos width (take default value from preferences)
2066 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2067 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2069 // - point marker (take default value from preferences)
2070 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2071 QString( "%1%2%3" ).
2072 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2073 arg( GEOM::subSectionSeparator() ).
2074 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2076 // - top-level flag (false by default)
2077 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2082 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2083 SALOMEDS::Color aSColor;
2086 SUIT_Session* session = SUIT_Session::session();
2087 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2089 if ( app && !theGeomObject->_is_nil()) {
2090 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2093 _PTR(Study) aStudy = study->studyDS();
2094 aSColor = theGeomObject->GetColor();
2095 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2097 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2098 bool general_autocolor = true;
2099 #else // auto-color for groups only
2100 bool general_autocolor = false;
2101 #endif // GENERAL_AUTOCOLOR
2102 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2103 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2104 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2105 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2106 aSColor = getPredefinedUniqueColor();
2108 #else // old algorithm for auto-colors
2109 QList<SALOMEDS::Color> aReservedColors;
2110 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2111 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2112 if ( aMainSObject ) {
2113 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2114 for ( ; it->More(); it->Next() ) {
2115 _PTR(SObject) aChildSObject( it->Value() );
2116 GEOM::GEOM_Object_var aChildObject =
2117 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2118 if ( CORBA::is_nil( aChildObject ) )
2121 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2122 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2123 aReservedColors.append( aReservedColor );
2126 aSColor = getUniqueColor( aReservedColors );
2128 #endif // SIMPLE_AUTOCOLOR
2138 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2139 const bool eraseOnlyChildren) {
2140 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2144 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2148 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2153 // Erase from all views
2154 QList<SALOME_View*> views;
2156 ViewManagerList vmans = app->viewManagers();
2157 SUIT_ViewManager* vman;
2158 foreach ( vman, vmans ) {
2159 SUIT_ViewModel* vmod = vman->getViewModel();
2160 view = dynamic_cast<SALOME_View*> ( vmod );
2162 views.append( view );
2165 if( views.count() == 0 )
2168 //Erase childrens w/o update views
2169 DataObjectList listObj = parent->children( true );
2170 SUIT_DataObject* obj;
2171 foreach( obj, listObj ) {
2172 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2174 foreach ( view, views ) {
2175 Handle(SALOME_InteractiveObject) anIO =
2176 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2177 Erase(anIO, false, false, view);
2181 //Erase parent with view update or repaint views
2182 foreach ( view, views ) {
2183 if(!eraseOnlyChildren)
2184 Erase(theIO, false, true, view);
2190 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2192 if( theGeomFieldStep->_is_nil() )
2195 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2196 if( aGeomField->_is_nil() )
2199 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2200 if( aGeomFieldShape->_is_nil() )
2203 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2204 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2205 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2207 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2209 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2211 int aFieldDimension = aGeomField->GetDimension();
2213 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2214 int aFieldNbComponents = aFieldComponents->length();
2216 QList<QVariant> aFieldStepData;
2217 if( aFieldDataType == GEOM::FDT_Bool )
2219 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2220 if ( !aGeomBoolFieldStep->_is_nil() )
2222 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2223 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2224 aFieldStepData << (bool)aValues[i];
2227 else if( aFieldDataType == GEOM::FDT_Int )
2229 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2230 if ( !aGeomIntFieldStep->_is_nil() )
2232 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2233 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2234 aFieldStepData << (qlonglong)aValues[i];
2237 else if( aFieldDataType == GEOM::FDT_Double )
2239 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2240 if ( !aGeomDoubleFieldStep->_is_nil() )
2242 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2243 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2244 aFieldStepData << (double)aValues[i];
2247 else if( aFieldDataType == GEOM::FDT_String )
2249 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2250 if ( !aGeomStringFieldStep->_is_nil() )
2252 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2253 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2254 aFieldStepData << QString( aValues[i] );
2258 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2259 aFieldStepData = groupFieldData( aFieldStepData,
2261 aFieldDataType == GEOM::FDT_String,
2263 aFieldStepRangeMax );
2265 setFieldStepInfo( aFieldDataType,
2270 aFieldStepRangeMax );
2273 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2274 const int theFieldNbComponents,
2275 const bool theIsString,
2276 double& theFieldStepRangeMin,
2277 double& theFieldStepRangeMax )
2279 QList<QVariant> aResultList;
2280 theFieldStepRangeMin = 0;
2281 theFieldStepRangeMax = 0;
2283 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2286 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2288 QList<QVariant> aGroupedList;
2290 bool anIsBoolean = false;
2291 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2294 QStringList aStringList;
2296 int aBaseIndex = aSubShape * theFieldNbComponents;
2297 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2299 int anIndex = aComponent + aBaseIndex;
2301 const QVariant& aVariant = theFieldStepData[ anIndex ];
2304 if( aVariant.type() == QVariant::String )
2305 aStringList << aVariant.toString();
2310 if( aVariant.type() == QVariant::Bool )
2312 aValue = aVariant.toBool() ? 1.0 : 0.0;
2318 if( aVariant.type() == QVariant::Int )
2319 aValue = double( aVariant.toInt() );
2320 else if( aVariant.type() == QVariant::Double )
2321 aValue = aVariant.toDouble();
2322 aNorm += aValue * aValue;
2328 aGroupedList << aStringList.join( "\n" );
2332 aNorm /= theFieldNbComponents;
2334 aNorm = pow( aNorm, 0.5 );
2336 if( aGroupedList.isEmpty() )
2337 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2340 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2341 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2344 aGroupedList << aNorm;
2350 theFieldStepRangeMin = 0.0;
2351 theFieldStepRangeMax = 1.0;
2354 SUIT_Session* session = SUIT_Session::session();
2355 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2356 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2358 QListIterator<QVariant> anIter( aGroupedList );
2359 while( anIter.hasNext() )
2361 const QVariant& aVariant = anIter.next();
2363 aResultList << aVariant;
2367 Quantity_Color aColor;
2368 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2369 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2370 aResultList << aQColor;
2376 // Note: the method is copied from Aspect_ColorScale class
2377 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2378 const Standard_Integer aMin,
2379 const Standard_Integer aMax )
2381 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2383 Standard_Integer aHue = maxLimit;
2385 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2387 aHue = Min( Max( minLimit, aHue ), maxLimit );
2392 // Note: the method is copied from Aspect_ColorScale class
2393 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2394 const Standard_Real aMin,
2395 const Standard_Real aMax,
2396 const Standard_Integer ColorsCount,
2397 Quantity_Color& aColor )
2399 if( aValue<aMin || aValue>aMax || aMax<aMin )
2400 return Standard_False;
2404 Standard_Real IntervNumber = 0;
2407 else if( aValue>aMax )
2408 IntervNumber = ColorsCount-1;
2409 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2410 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2412 Standard_Integer Interv = Standard_Integer( IntervNumber );
2414 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2416 return Standard_True;
2420 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2422 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2426 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2430 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2431 if( aViewer.IsNull() )
2434 aViewer->InitActiveViews();
2435 if( !aViewer->MoreActiveViews() )
2438 Handle(V3d_View) aView = aViewer->ActiveView();
2439 if( aView.IsNull() )
2442 Standard_Boolean anIsDisplayColorScale = Standard_False;
2443 TCollection_AsciiString aColorScaleTitle;
2444 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2445 Standard_Boolean anIsBoolean = Standard_False;
2447 SALOME_ListIO aSelectedObjects;
2448 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2449 if( aSelectedObjects.Extent() == 1 )
2451 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2452 if( !anIO.IsNull() )
2454 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2457 AIS_ListOfInteractive aList;
2458 aPrs->GetObjects( aList );
2459 AIS_ListIteratorOfListOfInteractive anIter( aList );
2460 for( ; anIter.More(); anIter.Next() )
2462 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2463 if( !aShape.IsNull() )
2465 GEOM::field_data_type aFieldDataType;
2466 int aFieldDimension;
2467 QList<QVariant> aFieldStepData;
2468 TCollection_AsciiString aFieldStepName;
2469 double aFieldStepRangeMin, aFieldStepRangeMax;
2470 aShape->getFieldStepInfo( aFieldDataType,
2475 aFieldStepRangeMax );
2476 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2478 anIsDisplayColorScale = Standard_True;
2479 aColorScaleTitle = aFieldStepName;
2480 aColorScaleMin = aFieldStepRangeMin;
2481 aColorScaleMax = aFieldStepRangeMax;
2482 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2490 if( anIsDisplayColorScale )
2492 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2493 if( !aColorScale.IsNull() )
2495 SUIT_Session* session = SUIT_Session::session();
2496 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2498 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2499 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2500 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2501 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2502 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2503 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2505 aColorScale->SetXPosition( anXPos );
2506 aColorScale->SetYPosition( anYPos );
2507 aColorScale->SetWidth( aWidth );
2508 aColorScale->SetHeight( aHeight );
2510 aColorScale->SetTextHeight( aTextHeight );
2511 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2513 aColorScale->SetTitle( aColorScaleTitle );
2514 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2516 if( !aView->ColorScaleIsDisplayed() )
2517 aView->ColorScaleDisplay();
2521 if( aView->ColorScaleIsDisplayed() )
2522 aView->ColorScaleErase();
2525 if( theIsRedisplayFieldSteps )
2527 _PTR(Study) aStudyDS = aStudy->studyDS();
2528 QList<SUIT_ViewManager*> vmList;
2529 myApp->viewManagers( vmList );
2530 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2532 if( SUIT_ViewManager* aViewManager = *vmIt )
2534 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2535 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2537 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2540 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2541 if( !CORBA::is_nil( anObject ) )
2543 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2544 if( !aFieldStep->_is_nil() )
2546 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2547 Handle(SALOME_InteractiveObject) aStepIO =
2548 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2549 Redisplay( aStepIO, false, false );