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 // VSR: ??? next line is commented: transparency property is set in the AfterDisplay() function
677 //AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
679 // set iso properties
680 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
681 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
682 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
683 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
684 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
685 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
686 uIsoAspect->SetColor( isosColor );
687 uIsoAspect->SetWidth( isosWidth );
688 uIsoAspect->SetNumber( uIsos );
689 vIsoAspect->SetColor( isosColor );
690 vIsoAspect->SetWidth( isosWidth );
691 vIsoAspect->SetNumber( vIsos );
692 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
693 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
695 // set deflection coefficient
696 // ... to avoid to small values of the coefficient, its lower value is limited
697 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
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 AISShape->SetTextureMapOn();
704 AISShape->DisableTextureModulate();
705 AISShape->SetDisplayMode( 3 );
709 AISShape->SetWidth( HasWidth() ?
710 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
712 // libe width from properties
713 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
715 // set top-level flag
716 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
718 // set point marker (for vertex / compound of vertices only)
720 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
721 if ( aList.size() == 2 ) {
722 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
723 int aTypeOfMarker = aList[0].toInt();
724 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
725 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
726 anAspect->SetScale( aScaleOfMarker );
727 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
728 anAspect->SetColor( HasColor() ?
729 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
730 (Quantity_NameOfColor)GetColor() :
731 // color from properties
732 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
733 AISShape->Attributes()->SetPointAspect( anAspect );
735 else if ( aList.size() == 1 ) {
736 // custom marker string contains "IdOfTexture"
737 int textureId = aList[0].toInt();
738 Standard_Integer aWidth, aHeight;
739 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
740 Handle(TColStd_HArray1OfByte) aTexture =
742 Handle(Graphic3d_HArray1OfBytes) aTexture =
744 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
745 if ( !aTexture.IsNull() ) {
746 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
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 Handle(Prs3d_PointAspect) aTextureAspect =
758 new Prs3d_PointAspect( HasColor() ?
759 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
760 (Quantity_NameOfColor)GetColor() :
761 // color from properties
762 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
767 AISShape->Attributes()->SetPointAspect( aTextureAspect );
772 // set field step data
773 AISShape->setFieldStepInfo( myFieldDataType,
778 myFieldStepRangeMax );
780 if ( create && !isTemporary && aMgrId != -1 ) {
781 // set properties to the study
782 study->setObjectPropMap( aMgrId, entry, propMap );
785 // AISShape->SetName(???); ??? necessary to set name ???
788 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
790 // check that actor is not null
791 if ( !actor ) return;
793 // check that study is active
794 SalomeApp_Study* study = getStudy();
795 if ( !study ) return;
797 // set interactive object
799 Handle( SALOME_InteractiveObject ) anIO;
801 if ( !myIO.IsNull() ) {
802 actor->setIO( myIO );
805 else if ( !myName.empty() ) {
806 // workaround to allow selection of temporary objects
807 static int tempId = 0;
808 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
809 actor->setIO( anIO );
812 // presentation study entry (empty for temporary objects like preview)
813 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
814 // flag: temporary object
815 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
816 // currently active view window's ID (-1 if no active view)
817 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
819 // get presentation properties
820 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
823 /////////////////////////////////////////////////////////////////////////
824 // VSR: for VTK viewer currently deflection coefficient is hardcoded
825 // due to performance problem
826 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
827 /////////////////////////////////////////////////////////////////////////
828 if ( !actor->getTopo().IsSame( myShape ) )
829 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
832 Material_Model material;
833 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
834 std::vector<vtkProperty*> mprops;
835 mprops.push_back( material.getMaterialVTKProperty( true ) );
836 mprops.push_back( material.getMaterialVTKProperty( false) );
837 actor->SetMaterial( mprops );
839 // set iso-lines properties
841 // - set number of iso-lines
842 int nbIsos[2]= { 1, 1 };
843 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
844 nbIsos[0] = isos[0].toInt();
845 nbIsos[1] = isos[1].toInt();
846 actor->SetNbIsos( nbIsos );
848 // - set iso-lines width
849 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
851 // - set iso-lines color
852 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
853 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
858 // - same color for all sub-actors
859 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
860 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
863 // shading color (for non-physical materials)
864 if ( !material.isPhysical() ) {
865 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
866 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
867 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
870 // - standalone edge color
871 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
872 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
874 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
875 // - shared edges color ???
876 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
878 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
879 // - free edges color ???
880 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
883 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
884 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
887 // - color for edges in shading+edges mode
888 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
889 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
892 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
895 actor->SetWidth( HasWidth() ?
896 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
898 // libe width from properties
899 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
901 // set display vectors flag
902 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
905 int displayMode = HasDisplayMode() ?
906 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
908 // display mode from properties
909 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
911 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
912 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
913 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
914 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
916 if ( displayMode == 2 )
917 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
918 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
920 actor->setDisplayMode( displayMode );
925 actor->PickableOff();
927 if ( create && !isTemporary && aMgrId != -1 ) {
928 // set properties to the study
929 study->setObjectPropMap( aMgrId, entry, propMap );
933 //=================================================================
935 * GEOM_Displayer::Erase
936 * Calls Erase() method for each object in the given list
938 //=================================================================
939 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
941 const bool updateViewer )
943 SALOME_ListIteratorOfListIO Iter( theIOList );
944 for ( ; Iter.More(); Iter.Next() )
945 Erase( Iter.Value(), forced, false );
951 //=================================================================
953 * GEOM_Displayer::Redisplay
954 * Calls Redisplay() method for each object in the given list
956 //=================================================================
957 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
958 const bool updateViewer,
959 const bool checkActiveViewer )
961 SALOME_ListIteratorOfListIO Iter( theIOList );
962 for ( ; Iter.More(); Iter.Next() )
963 Redisplay( Iter.Value(), false, checkActiveViewer );
969 //=================================================================
971 * GEOM_Displayer::Update
972 * Update OCC presentaion
973 * [ Reimplemented from SALOME_Displayer ]
975 //=================================================================
976 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
978 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
979 SalomeApp_Study* study = getStudy();
981 if ( !occPrs || myShape.IsNull() || !study )
984 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
987 // specific processing for local coordinate system presentation
990 TopoDS_Face aFace = TopoDS::Face( myShape );
991 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
992 if ( !aPlane.IsNull() )
994 gp_Ax3 aPos = aPlane->Pln().Position();
995 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
997 Handle(GEOM_AISTrihedron) aTrh;
999 if ( occPrs->IsNull() )
1001 // new presentation is being created
1002 aTrh = new GEOM_AISTrihedron( aPlc );
1003 occPrs->AddObject( aTrh );
1007 // presentation is being updated
1008 AIS_ListOfInteractive aList;
1009 occPrs->GetObjects( aList );
1010 AIS_ListIteratorOfListOfInteractive anIter( aList );
1011 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1012 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1016 if ( !aTrh.IsNull() ) {
1017 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1019 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1020 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1022 aTrh->SetWidth( GetWidth() );
1024 if ( !myIO.IsNull() )
1026 aTrh->setIO( myIO );
1027 aTrh->SetOwner( myIO );
1029 aTrh->SetComponent( aPlc );
1030 aTrh->SetToUpdate();
1032 occPrs->SetToActivate( ToActivate() );
1038 // processing for usual geometry presentation
1041 // if presentation is empty we try to create new one
1042 if ( occPrs->IsNull() )
1044 // create presentation (specific for vectors)
1045 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1046 : new GEOM_AISShape ( myShape, "" );
1047 // update shape properties
1048 updateShapeProperties( AISShape, true );
1050 // add shape to the presentation
1051 occPrs->AddObject( AISShape );
1053 // In accordance with ToActivate() value object will be activated/deactivated
1054 // when it will be displayed
1055 occPrs->SetToActivate( ToActivate() );
1057 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1058 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1060 // create additional wireframe shape
1061 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1062 aWirePrs->SetWidth(AISShape->Width());
1063 if ( !myIO.IsNull() ) {
1064 aWirePrs->setIO( myIO );
1065 aWirePrs->SetOwner( myIO );
1068 // add shape to the presentation
1069 occPrs->AddObject( aWirePrs );
1072 // if presentation is found -> set again shape for it
1075 AIS_ListOfInteractive IOList;
1076 occPrs->GetObjects( IOList );
1077 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1078 for ( ; Iter.More(); Iter.Next() )
1080 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1081 if ( AISShape.IsNull() )
1084 // re-set shape (it might be changed)
1085 if ( AISShape->Shape() != myShape )
1086 AISShape->Set( myShape );
1088 // update shape properties
1089 updateShapeProperties( AISShape, false );
1092 AISShape->UpdateSelection();
1093 AISShape->SetToUpdate();
1099 //=================================================================
1101 * GEOM_Displayer::Update
1102 * Update VTK presentaion
1103 * [ Reimplemented from SALOME_Displayer ]
1105 //=================================================================
1106 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1108 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1109 SalomeApp_Study* study = getStudy();
1111 if ( !vtkPrs || myShape.IsNull() || !study )
1114 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1117 // specific processing for local coordinate system presentation
1120 TopoDS_Face aFace = TopoDS::Face( myShape );
1121 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1122 if ( !aPlane.IsNull() ) {
1123 gp_Ax3 aPos = aPlane->Pln().Position();
1124 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1126 GEOM_VTKTrihedron* aTrh = 0;
1128 if ( vtkPrs->IsNull() ) {
1129 // new presentation is being created
1130 aTrh = GEOM_VTKTrihedron::New();
1131 vtkPrs->AddObject( aTrh );
1134 // presentation is being updated
1135 vtkActorCollection* actors = vtkPrs->GetObjects();
1137 actors->InitTraversal();
1138 vtkActor* a = actors->GetNextActor();
1139 while ( a && !aTrh ) {
1140 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1141 a = actors->GetNextActor();
1147 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1149 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1150 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1152 #ifdef VTK_TRIHEDRON_WIDTH
1154 // VSR: currently isn't supported
1156 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1158 aTrh->SetWidth( GetWidth() );
1161 if ( !myIO.IsNull() )
1162 aTrh->setIO( myIO );
1164 aTrh->SetPlacement( aPlc );
1171 // processing for usual geometry presentation
1174 // if presentation is empty we try to create new one
1175 if ( vtkPrs->IsNull() )
1178 GEOM_Actor* actor = GEOM_Actor::New();
1179 // update actor properties
1180 updateActorProperties( actor, true );
1181 // add actor to the presentation
1182 vtkPrs->AddObject( actor );
1185 // presentation is being updated
1186 vtkActorCollection* actors = vtkPrs->GetObjects();
1188 actors->InitTraversal();
1189 vtkActor* a = actors->GetNextActor();
1191 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1193 // update actor properties
1194 updateActorProperties( actor, false );
1195 a = actors->GetNextActor();
1203 //=================================================================
1205 * GEOM_Displayer::BuildPrs
1206 * Build presentation accordint to the current viewer type
1208 //=================================================================
1209 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1211 if ( theObj->_is_nil() )
1214 myViewFrame = GetActiveView();
1215 if ( myViewFrame == 0 )
1218 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1223 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1224 myType = theObj->GetType();
1226 // Update presentation
1232 //=================================================================
1234 * GEOM_Displayer::BuildPrs
1235 * Build presentation accordint to the current viewer type
1237 //=================================================================
1238 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1240 myViewFrame = GetActiveView();
1241 if ( theShape.IsNull() || myViewFrame == 0 )
1244 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1249 setShape( theShape );
1257 //=================================================================
1259 * GEOM_Displayer::buildPresentation
1260 * Builds/finds object's presentation for the current viewer
1261 * Calls corresponding Update() method by means of double dispatch
1264 //=================================================================
1265 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1266 SALOME_View* theViewFrame )
1268 SALOME_Prs* prs = 0;
1271 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1275 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1278 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1279 theIO->setEntry( entry.toLatin1().constData() );
1280 if ( !theIO.IsNull() )
1282 // set interactive object
1284 // Find SOBject (because shape should be published previously)
1285 SUIT_Session* session = SUIT_Session::session();
1286 SUIT_Application* app = session->activeApplication();
1289 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1292 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1295 // get CORBA reference to data object
1296 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1297 if ( !CORBA::is_nil( object ) )
1299 // downcast to GEOM base object
1300 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1301 if ( !GeomBaseObject->_is_nil() )
1303 myType = GeomBaseObject->GetType();
1305 // downcast to GEOM object
1306 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1307 if ( myType == GEOM_FIELD_STEP )
1309 // get the GEOM object from the field's shape
1310 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1311 if ( !GeomFieldStep->_is_nil() )
1313 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1314 if ( !GeomField->_is_nil() )
1315 GeomObject = GeomField->GetShape();
1318 // read the field step information
1319 readFieldStepInfo( GeomFieldStep );
1322 if ( !GeomObject->_is_nil() )
1324 // finally set shape
1325 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1333 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1339 //=================================================================
1341 * GEOM_Displayer::buildSubshapePresentation
1342 * Builds/finds object's presentation for the current viewer
1343 * Calls corresponding Update() method by means of double dispatch
1344 * For not published objects (for Mantis issue 0020435)
1346 //=================================================================
1347 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1348 const QString& entry,
1349 SALOME_View* theViewFrame)
1351 SALOME_Prs* prs = 0;
1354 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1358 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1361 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1362 theIO->setEntry(entry.toLatin1().constData());
1363 if (!theIO.IsNull())
1365 // set interactive object
1367 // finally set shape
1369 myType = GEOM_SUBSHAPE;
1371 UpdatePrs(prs); // Update presentation by using of the double dispatch
1377 //=================================================================
1379 * GEOM_Displayer::internalReset
1380 * Resets internal data
1383 //=================================================================
1384 void GEOM_Displayer::internalReset()
1389 myFieldDataType = GEOM::FDT_Double;
1390 myFieldDimension = 0;
1391 myFieldStepData.clear();
1392 myFieldStepName.Clear();
1393 myFieldStepRangeMin = 0;
1394 myFieldStepRangeMax = 0;
1397 //=================================================================
1399 * GEOM_Displayer::LocalSelection
1400 * Activate selection of CAD shapes with activisation of selection
1401 * of their sub-shapes (with opened local context for OCC viewer)
1403 //=================================================================
1404 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1406 SUIT_Session* session = SUIT_Session::session();
1407 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1411 LightApp_SelectionMgr* sm = app->selectionMgr();
1413 // remove all filters from selection
1416 SALOME_View* vf = GetActiveView();
1418 if (!theIO.IsNull() && !vf->isVisible(theIO))
1420 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1421 vf->LocalSelection( prs, theMode );
1422 delete prs; // delete presentation because displayer is its owner
1426 //=================================================================
1428 * GEOM_Displayer::globalSelection
1429 * Activate selection of CAD shapes without activisation of selection
1430 * of their sub-shapes (without opened local context for OCC viewer)
1432 //=================================================================
1433 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1435 TColStd_MapOfInteger aModes;
1436 aModes.Add( theMode );
1437 GlobalSelection( aModes, update );
1440 //=================================================================
1442 * GEOM_Displayer::globalSelection
1443 * Activate selection of CAD shapes without activisation of selection
1444 * of their sub-shapes (without opened local context for OCC viewer)
1446 //=================================================================
1447 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1448 const bool update, const QList<int>* theSubShapes )
1450 SUIT_Session* session = SUIT_Session::session();
1451 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1455 SALOME_View* vf = GetActiveView();
1459 // Close local context
1460 vf->GlobalSelection( update );
1462 // Set selection filters in accordance with current mode
1463 LightApp_SelectionMgr* sm = app->selectionMgr();
1467 // Remove from selection temporary objects if necessary
1468 if ( !theModes.Contains( GEOM_PREVIEW ) )
1469 clearTemporary( sm );
1471 //@ aSel->ClearIndex();
1475 // Remove filters from AIS_InteractiveContext
1476 Handle(AIS_InteractiveContext) ic;
1477 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1480 ic = viewer->getAISContext();
1482 ic->RemoveFilters();
1485 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1488 SUIT_SelectionFilter* aFilter;
1489 if ( theModes.Extent() == 1 )
1491 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1493 if ( aMode == GEOM_COMPOUNDFILTER )
1494 aFilter = getComplexFilter( theSubShapes );
1496 aFilter = getFilter( aMode );
1498 else if ( theModes.Extent() > 1 )
1500 TColStd_MapOfInteger aTopAbsModes;
1501 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1502 QList<SUIT_SelectionFilter*> aListOfFilters;
1503 for ( ; anIter.More(); anIter.Next() )
1505 SUIT_SelectionFilter* aFilter;
1506 int aMode = anIter.Key();
1507 if ( aMode == GEOM_COMPOUNDFILTER )
1508 aFilter = getComplexFilter( theSubShapes );
1510 aFilter = getFilter( aMode );
1513 aListOfFilters.append( aFilter );
1516 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1523 sm->installFilter( aFilter );
1526 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1527 ic->AddFilter( anOCCFilter );
1532 //=================================================================
1534 * GEOM_Displayer::LocalSelection
1535 * Activate selection of CAD shapes with activisation of selection
1536 * of their sub-shapes (with opened local context for OCC viewer)
1538 //=================================================================
1539 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1541 SALOME_ListIteratorOfListIO Iter( theIOList );
1542 for ( ; Iter.More(); Iter.Next() )
1543 LocalSelection( Iter.Value(), theMode );
1546 //=================================================================
1548 * GEOM_Displayer::BeforeDisplay
1549 * Called before displaying of pars. Close local context
1550 * [ Reimplemented from SALOME_Displayer ]
1552 //=================================================================
1553 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1555 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1558 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1561 if ( ic->HasOpenedContext() )
1562 ic->CloseAllContexts();
1567 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1569 SalomeApp_Study* aStudy = getStudy();
1570 if (!aStudy) return;
1571 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1572 if ( vf && !p->IsNull() ) {
1573 int aMgrId = getViewManagerId( vf );
1574 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1575 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1576 if ( !ic.IsNull() && prs ) {
1577 AIS_ListOfInteractive objects;
1578 prs->GetObjects( objects );
1579 AIS_ListIteratorOfListOfInteractive it( objects );
1580 for ( ; it.More(); it.Next() ) {
1581 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1582 if ( sh.IsNull() ) continue;
1583 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1584 if ( IO.IsNull() ) continue;
1585 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1586 if ( aPropMap.contains( GEOM::propertyName( GEOM::Transparency ) ) ) {
1587 double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble();
1588 ic->SetTransparency( sh, transparency, true );
1596 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1598 LightApp_Displayer::AfterErase( v, p );
1602 //=================================================================
1604 * GEOM_Displayer::SetColor
1605 * Set color for shape displaying. If it is equal -1 then default color is used.
1606 * Available values are from Quantity_NameOfColor enumeration
1608 //=================================================================
1609 void GEOM_Displayer::SetColor( const int color )
1616 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1620 int GEOM_Displayer::GetColor() const
1625 bool GEOM_Displayer::HasColor() const
1627 return myColor != -1;
1630 void GEOM_Displayer::UnsetColor()
1634 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1635 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1636 myShadingColor = SalomeApp_Tools::color( col );
1639 //=================================================================
1641 * GEOM_Displayer::SetTexture
1642 * Set color for shape displaying. If it is equal -1 then default color is used.
1643 * Available values are from Quantity_NameOfColor enumeration
1645 //=================================================================
1646 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1648 if(texureFileName!="")
1650 myTexture = texureFileName;
1654 bool GEOM_Displayer::HasTexture() const
1656 return myTexture != "";
1659 std::string GEOM_Displayer::GetTexture() const
1664 //=================================================================
1666 * GEOM_Displayer::SetWidth
1667 * Set width of shape displaying. If it is equal -1 then default width is used.
1669 //=================================================================
1670 void GEOM_Displayer::SetWidth( const double width )
1675 double GEOM_Displayer::GetWidth() const
1680 bool GEOM_Displayer::HasWidth() const
1682 return myWidth != -1;
1685 void GEOM_Displayer::UnsetWidth()
1691 int GEOM_Displayer::GetIsosWidth() const
1696 void GEOM_Displayer::SetIsosWidth(const int width)
1698 myIsosWidth = width;
1701 bool GEOM_Displayer::HasIsosWidth() const
1703 return myIsosWidth != -1;
1707 //=================================================================
1709 * GEOM_Displayer::SetToActivate
1710 * This method is used for activisation/deactivisation of objects to be displayed
1712 //=================================================================
1713 void GEOM_Displayer::SetToActivate( const bool toActivate )
1715 myToActivate = toActivate;
1717 bool GEOM_Displayer::ToActivate() const
1719 return myToActivate;
1722 //=================================================================
1724 * GEOM_Displayer::clearTemporary
1725 * Removes from selection temporary objects
1727 //=================================================================
1728 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1730 SALOME_ListIO selected, toSelect;
1731 theSelMgr->selectedObjects( selected );
1733 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1734 Handle(SALOME_InteractiveObject) io = it.Value();
1735 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1736 toSelect.Append( it.Value() );
1739 theSelMgr->setSelectedObjects( toSelect, true );
1742 void GEOM_Displayer::SetName( const char* theName )
1747 void GEOM_Displayer::UnsetName()
1752 SalomeApp_Study* GEOM_Displayer::getStudy() const
1754 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1757 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1762 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1767 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
1768 const int theFieldDimension,
1769 const QList<QVariant>& theFieldStepData,
1770 const TCollection_AsciiString& theFieldStepName,
1771 const double theFieldStepRangeMin,
1772 const double theFieldStepRangeMax )
1774 myFieldDataType = theFieldDataType;
1775 myFieldDimension = theFieldDimension;
1776 myFieldStepData = theFieldStepData;
1777 myFieldStepName = theFieldStepName;
1778 myFieldStepRangeMin = theFieldStepRangeMin;
1779 myFieldStepRangeMax = theFieldStepRangeMax;
1782 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1784 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
1785 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
1786 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
1787 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
1788 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
1789 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
1792 int GEOM_Displayer::SetDisplayMode( const int theMode )
1794 int aPrevMode = myDisplayMode;
1795 if ( theMode != -1 ) {
1796 myDisplayMode = theMode;
1797 myHasDisplayMode = true;
1805 int GEOM_Displayer::GetDisplayMode() const
1807 return myDisplayMode;
1810 int GEOM_Displayer::UnsetDisplayMode()
1812 int aPrevMode = myDisplayMode;
1813 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1814 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1815 myHasDisplayMode = false;
1819 bool GEOM_Displayer::HasDisplayMode() const
1821 return myHasDisplayMode;
1824 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1826 static QList<QColor> colors;
1828 if ( colors.isEmpty() ) {
1830 for (int s = 0; s < 2 ; s++)
1832 for (int v = 100; v >= 40; v = v - 20)
1834 for (int h = 0; h < 359 ; h = h + 60)
1836 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1842 static int currentColor = 0;
1844 SALOMEDS::Color color;
1845 color.R = (double)colors[currentColor].red() / 255.0;
1846 color.G = (double)colors[currentColor].green() / 255.0;
1847 color.B = (double)colors[currentColor].blue() / 255.0;
1849 currentColor = (currentColor+1) % colors.count();
1854 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1857 int aTolerance = 64;
1858 int anIterations = 0;
1864 if( anIterations % aPeriod == 0 )
1867 if( aTolerance < 1 )
1870 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1872 aHue = (int)( 360.0 * rand() / RAND_MAX );
1873 //std::cout << "Hue = " << aHue << std::endl;
1875 //std::cout << "Auto colors : ";
1877 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1878 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1879 for( ; it != itEnd; ++it )
1881 SALOMEDS::Color anAutoColor = *it;
1882 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1885 aQColor.getHsv( &h, &s, &v );
1886 //std::cout << h << " ";
1887 if( abs( h - aHue ) < aTolerance )
1890 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1894 //std::cout << std::endl;
1900 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1902 aColor.setHsv( aHue, 255, 255 );
1904 SALOMEDS::Color aSColor;
1905 aSColor.R = (double)aColor.red() / 255.0;
1906 aSColor.G = (double)aColor.green() / 255.0;
1907 aSColor.B = (double)aColor.blue() / 255.0;
1912 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1913 const QString& entry,
1916 // get default properties for the explicitly specified default view type
1917 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1919 if ( study && view ) {
1920 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1921 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1922 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1924 if ( viewModel && viewId != -1 ) {
1925 // get properties from the study
1926 PropMap storedMap = study->getObjectPropMap( viewId, entry );
1927 // overwrite default properties from stored ones (that are specified)
1928 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1929 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1930 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
1931 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1933 // ... specific processing for color
1934 // ... current implementation is to use same stored color for all aspects
1935 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1936 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1937 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1938 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1939 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1940 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1941 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1944 if ( !entry.isEmpty() ) {
1945 // get CORBA reference to geom object
1946 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1948 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1949 if ( !CORBA::is_nil( object ) ) {
1950 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1951 if ( !CORBA::is_nil( geomObject ) ) { // to check
1952 // check that geom object has color properly set
1953 bool hasColor = false;
1954 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1955 // set color from geometry object (only once, if it is not yet set in GUI)
1956 // current implementation is to use same color for all aspects
1957 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1958 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1959 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1960 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
1961 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1962 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
1963 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
1964 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
1966 // check that object has point marker properly set
1967 GEOM::marker_type mType = geomObject->GetMarkerType();
1968 GEOM::marker_size mSize = geomObject->GetMarkerSize();
1969 int mTextureId = geomObject->GetMarkerTexture();
1970 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
1971 ( mType == GEOM::MT_USER && mTextureId > 0 );
1972 // set point marker from geometry object (only once, if it is not yet set in GUI)
1973 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
1974 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
1976 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1977 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
1979 else if ( mType == GEOM::MT_USER ) {
1981 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
1993 PropMap GEOM_Displayer::getDefaultPropertyMap()
1997 // get resource manager
1998 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2000 // fill in the properties map with default values
2002 // - visibility (false by default)
2003 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2005 // - nb isos (take default value from preferences)
2006 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2007 QString( "%1%2%3" ).
2008 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2009 arg( GEOM::subSectionSeparator() ).
2010 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2012 // - transparency (opacity = 1-transparency)
2013 propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2015 // - display mode (take default value from preferences)
2016 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2017 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2019 // - show edges direction flag (false by default)
2020 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2022 // - shading color (take default value from preferences)
2023 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2024 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2026 // - wireframe color (take default value from preferences)
2027 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2028 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2030 // - standalone edges color (take default value from preferences)
2031 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2032 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2034 // - free boundaries color (take default value from preferences)
2035 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2036 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2038 // - points color (take default value from preferences)
2039 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2040 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2042 // - isos color (take default value from preferences)
2043 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2044 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2046 // - outlines color (take default value from preferences)
2047 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2048 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2050 // - deflection coefficient (take default value from preferences)
2051 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2052 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2054 // - material (take default value from preferences)
2055 Material_Model material;
2056 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2057 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2059 // - edge width (take default value from preferences)
2060 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2061 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2063 // - isos width (take default value from preferences)
2064 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2065 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2067 // - point marker (take default value from preferences)
2068 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2069 QString( "%1%2%3" ).
2070 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2071 arg( GEOM::subSectionSeparator() ).
2072 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2074 // - top-level flag (false by default)
2075 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2080 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2081 SALOMEDS::Color aSColor;
2084 SUIT_Session* session = SUIT_Session::session();
2085 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2087 if ( app && !theGeomObject->_is_nil()) {
2088 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2091 _PTR(Study) aStudy = study->studyDS();
2092 aSColor = theGeomObject->GetColor();
2093 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2095 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2096 bool general_autocolor = true;
2097 #else // auto-color for groups only
2098 bool general_autocolor = false;
2099 #endif // GENERAL_AUTOCOLOR
2100 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2101 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2102 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2103 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2104 aSColor = getPredefinedUniqueColor();
2106 #else // old algorithm for auto-colors
2107 QList<SALOMEDS::Color> aReservedColors;
2108 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2109 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2110 if ( aMainSObject ) {
2111 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2112 for ( ; it->More(); it->Next() ) {
2113 _PTR(SObject) aChildSObject( it->Value() );
2114 GEOM::GEOM_Object_var aChildObject =
2115 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2116 if ( CORBA::is_nil( aChildObject ) )
2119 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2120 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2121 aReservedColors.append( aReservedColor );
2124 aSColor = getUniqueColor( aReservedColors );
2126 #endif // SIMPLE_AUTOCOLOR
2136 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2137 const bool eraseOnlyChildren) {
2138 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2142 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2146 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2151 // Erase from all views
2152 QList<SALOME_View*> views;
2154 ViewManagerList vmans = app->viewManagers();
2155 SUIT_ViewManager* vman;
2156 foreach ( vman, vmans ) {
2157 SUIT_ViewModel* vmod = vman->getViewModel();
2158 view = dynamic_cast<SALOME_View*> ( vmod );
2160 views.append( view );
2163 if( views.count() == 0 )
2166 //Erase childrens w/o update views
2167 DataObjectList listObj = parent->children( true );
2168 SUIT_DataObject* obj;
2169 foreach( obj, listObj ) {
2170 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2172 foreach ( view, views ) {
2173 Handle(SALOME_InteractiveObject) anIO =
2174 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2175 Erase(anIO, false, false, view);
2179 //Erase parent with view update or repaint views
2180 foreach ( view, views ) {
2181 if(!eraseOnlyChildren)
2182 Erase(theIO, false, true, view);
2188 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2190 if( theGeomFieldStep->_is_nil() )
2193 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2194 if( aGeomField->_is_nil() )
2197 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2198 if( aGeomFieldShape->_is_nil() )
2201 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2202 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2203 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2205 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2207 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2209 int aFieldDimension = aGeomField->GetDimension();
2211 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2212 int aFieldNbComponents = aFieldComponents->length();
2214 QList<QVariant> aFieldStepData;
2215 if( aFieldDataType == GEOM::FDT_Bool )
2217 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2218 if ( !aGeomBoolFieldStep->_is_nil() )
2220 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2221 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2222 aFieldStepData << (bool)aValues[i];
2225 else if( aFieldDataType == GEOM::FDT_Int )
2227 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2228 if ( !aGeomIntFieldStep->_is_nil() )
2230 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2231 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2232 aFieldStepData << aValues[i];
2235 else if( aFieldDataType == GEOM::FDT_Double )
2237 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2238 if ( !aGeomDoubleFieldStep->_is_nil() )
2240 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2241 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2242 aFieldStepData << aValues[i];
2245 else if( aFieldDataType == GEOM::FDT_String )
2247 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2248 if ( !aGeomStringFieldStep->_is_nil() )
2250 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2251 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2252 aFieldStepData << QString( aValues[i] );
2256 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2257 aFieldStepData = groupFieldData( aFieldStepData,
2259 aFieldDataType == GEOM::FDT_String,
2261 aFieldStepRangeMax );
2263 setFieldStepInfo( aFieldDataType,
2268 aFieldStepRangeMax );
2271 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2272 const int theFieldNbComponents,
2273 const bool theIsString,
2274 double& theFieldStepRangeMin,
2275 double& theFieldStepRangeMax )
2277 QList<QVariant> aResultList;
2278 theFieldStepRangeMin = 0;
2279 theFieldStepRangeMax = 0;
2281 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2284 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2286 QList<QVariant> aGroupedList;
2288 bool anIsBoolean = false;
2289 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2292 QStringList aStringList;
2294 int aBaseIndex = aSubShape * theFieldNbComponents;
2295 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2297 int anIndex = aComponent + aBaseIndex;
2299 const QVariant& aVariant = theFieldStepData[ anIndex ];
2302 if( aVariant.type() == QVariant::String )
2303 aStringList << aVariant.toString();
2308 if( aVariant.type() == QVariant::Bool )
2310 aValue = aVariant.toBool() ? 1.0 : 0.0;
2316 if( aVariant.type() == QVariant::Int )
2317 aValue = double( aVariant.toInt() );
2318 else if( aVariant.type() == QVariant::Double )
2319 aValue = aVariant.toDouble();
2320 aNorm += aValue * aValue;
2326 aGroupedList << aStringList.join( "\n" );
2330 aNorm /= theFieldNbComponents;
2332 aNorm = pow( aNorm, 0.5 );
2334 if( aGroupedList.isEmpty() )
2335 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2338 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2339 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2342 aGroupedList << aNorm;
2348 theFieldStepRangeMin = 0.0;
2349 theFieldStepRangeMax = 1.0;
2352 SUIT_Session* session = SUIT_Session::session();
2353 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2354 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2356 QListIterator<QVariant> anIter( aGroupedList );
2357 while( anIter.hasNext() )
2359 const QVariant& aVariant = anIter.next();
2361 aResultList << aVariant;
2365 Quantity_Color aColor;
2366 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2367 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2368 aResultList << aQColor;
2374 // Note: the method is copied from Aspect_ColorScale class
2375 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2376 const Standard_Integer aMin,
2377 const Standard_Integer aMax )
2379 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2381 Standard_Integer aHue = maxLimit;
2383 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2385 aHue = Min( Max( minLimit, aHue ), maxLimit );
2390 // Note: the method is copied from Aspect_ColorScale class
2391 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2392 const Standard_Real aMin,
2393 const Standard_Real aMax,
2394 const Standard_Integer ColorsCount,
2395 Quantity_Color& aColor )
2397 if( aValue<aMin || aValue>aMax || aMax<aMin )
2398 return Standard_False;
2402 Standard_Real IntervNumber = 0;
2405 else if( aValue>aMax )
2406 IntervNumber = ColorsCount-1;
2407 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2408 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2410 Standard_Integer Interv = Standard_Integer( IntervNumber );
2412 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2414 return Standard_True;
2418 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps )
2420 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2424 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2428 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2429 if( aViewer.IsNull() )
2432 aViewer->InitActiveViews();
2433 if( !aViewer->MoreActiveViews() )
2436 Handle(V3d_View) aView = aViewer->ActiveView();
2437 if( aView.IsNull() )
2440 Standard_Boolean anIsDisplayColorScale = Standard_False;
2441 TCollection_AsciiString aColorScaleTitle;
2442 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2443 Standard_Boolean anIsBoolean = Standard_False;
2445 SALOME_ListIO aSelectedObjects;
2446 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2447 if( aSelectedObjects.Extent() == 1 )
2449 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2450 if( !anIO.IsNull() )
2452 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2455 AIS_ListOfInteractive aList;
2456 aPrs->GetObjects( aList );
2457 AIS_ListIteratorOfListOfInteractive anIter( aList );
2458 for( ; anIter.More(); anIter.Next() )
2460 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2461 if( !aShape.IsNull() )
2463 GEOM::field_data_type aFieldDataType;
2464 int aFieldDimension;
2465 QList<QVariant> aFieldStepData;
2466 TCollection_AsciiString aFieldStepName;
2467 double aFieldStepRangeMin, aFieldStepRangeMax;
2468 aShape->getFieldStepInfo( aFieldDataType,
2473 aFieldStepRangeMax );
2474 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2476 anIsDisplayColorScale = Standard_True;
2477 aColorScaleTitle = aFieldStepName;
2478 aColorScaleMin = aFieldStepRangeMin;
2479 aColorScaleMax = aFieldStepRangeMax;
2480 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2488 if( anIsDisplayColorScale )
2490 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2491 if( !aColorScale.IsNull() )
2493 SUIT_Session* session = SUIT_Session::session();
2494 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2496 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2497 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2498 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2499 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2500 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2501 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2503 aColorScale->SetXPosition( anXPos );
2504 aColorScale->SetYPosition( anYPos );
2505 aColorScale->SetWidth( aWidth );
2506 aColorScale->SetHeight( aHeight );
2508 aColorScale->SetTextHeight( aTextHeight );
2509 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2511 aColorScale->SetTitle( aColorScaleTitle );
2512 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2514 if( !aView->ColorScaleIsDisplayed() )
2515 aView->ColorScaleDisplay();
2519 if( aView->ColorScaleIsDisplayed() )
2520 aView->ColorScaleErase();
2523 if( theIsRedisplayFieldSteps )
2525 _PTR(Study) aStudyDS = aStudy->studyDS();
2526 QList<SUIT_ViewManager*> vmList;
2527 myApp->viewManagers( vmList );
2528 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2530 if( SUIT_ViewManager* aViewManager = *vmIt )
2532 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2533 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2535 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2538 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2539 if( !CORBA::is_nil( anObject ) )
2541 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2542 if( !aFieldStep->_is_nil() )
2544 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2545 Handle(SALOME_InteractiveObject) aStepIO =
2546 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2547 Redisplay( aStepIO, false, false );