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 bool textureAdded = false;
701 if ( HasTexture() ) {
702 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
703 AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
704 if ( ! entry.isEmpty() ) {
705 // check that study is active
706 SalomeApp_Study* study = getActiveStudy();
708 // Store the texture in object properties for next displays
709 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
710 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
712 // Update porpeties map
713 propMap = getObjectProperties( study, entry, myViewFrame );
719 // Texture from properties
720 QString aTexture = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
721 if ( !aTexture.isEmpty() ) {
722 AISShape->SetTextureFileName( TCollection_AsciiString( aTexture.toStdString().c_str() ) );
728 AISShape->SetTextureMapOn();
729 AISShape->DisableTextureModulate();
733 AISShape->SetWidth( HasWidth() ?
734 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
736 // libe width from properties
737 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
739 // set top-level flag
740 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
742 // set point marker (for vertex / compound of vertices only)
744 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
745 if ( aList.size() == 2 ) {
746 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
747 int aTypeOfMarker = aList[0].toInt();
748 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
749 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
750 anAspect->SetScale( aScaleOfMarker );
751 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
752 anAspect->SetColor( HasColor() ?
753 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
754 (Quantity_NameOfColor)GetColor() :
755 // color from properties
756 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
757 AISShape->Attributes()->SetPointAspect( anAspect );
759 else if ( aList.size() == 1 ) {
760 // custom marker string contains "IdOfTexture"
761 int textureId = aList[0].toInt();
762 Standard_Integer aWidth, aHeight;
763 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
764 Handle(TColStd_HArray1OfByte) aTexture =
766 Handle(Graphic3d_HArray1OfBytes) aTexture =
768 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
769 if ( !aTexture.IsNull() ) {
770 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
771 Handle(Prs3d_PointAspect) aTextureAspect =
772 new Prs3d_PointAspect( HasColor() ?
773 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
774 (Quantity_NameOfColor)GetColor() :
775 // color from properties
776 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
781 Handle(Prs3d_PointAspect) aTextureAspect =
782 new Prs3d_PointAspect( HasColor() ?
783 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
784 (Quantity_NameOfColor)GetColor() :
785 // color from properties
786 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
791 AISShape->Attributes()->SetPointAspect( aTextureAspect );
796 // set field step data
797 AISShape->setFieldStepInfo( myFieldDataType,
802 myFieldStepRangeMax );
804 if ( create && !isTemporary && aMgrId != -1 ) {
805 // set properties to the study
806 study->setObjectPropMap( aMgrId, entry, propMap );
809 // AISShape->SetName(???); ??? necessary to set name ???
812 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
814 // check that actor is not null
815 if ( !actor ) return;
817 // check that study is active
818 SalomeApp_Study* study = getStudy();
819 if ( !study ) return;
821 // set interactive object
823 Handle( SALOME_InteractiveObject ) anIO;
825 if ( !myIO.IsNull() ) {
826 actor->setIO( myIO );
829 else if ( !myName.empty() ) {
830 // workaround to allow selection of temporary objects
831 static int tempId = 0;
832 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
833 actor->setIO( anIO );
836 // presentation study entry (empty for temporary objects like preview)
837 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
838 // flag: temporary object
839 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
840 // currently active view window's ID (-1 if no active view)
841 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
843 // get presentation properties
844 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
847 /////////////////////////////////////////////////////////////////////////
848 // VSR: for VTK viewer currently deflection coefficient is hardcoded
849 // due to performance problem
850 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
851 /////////////////////////////////////////////////////////////////////////
852 if ( !actor->getTopo().IsSame( myShape ) )
853 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
856 Material_Model material;
857 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
858 std::vector<vtkProperty*> mprops;
859 mprops.push_back( material.getMaterialVTKProperty( true ) );
860 mprops.push_back( material.getMaterialVTKProperty( false) );
861 actor->SetMaterial( mprops );
863 // set iso-lines properties
865 // - set number of iso-lines
866 int nbIsos[2]= { 1, 1 };
867 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
868 nbIsos[0] = isos[0].toInt();
869 nbIsos[1] = isos[1].toInt();
870 actor->SetNbIsos( nbIsos );
872 // - set iso-lines width
873 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
875 // - set iso-lines color
876 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
877 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
882 // - same color for all sub-actors
883 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
884 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
887 // shading color (for non-physical materials)
888 if ( !material.isPhysical() ) {
889 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
890 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
891 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
894 // - standalone edge color
895 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
896 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
898 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
899 // - shared edges color ???
900 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
902 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
903 // - free edges color ???
904 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
907 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
908 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
911 // - color for edges in shading+edges mode
912 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
913 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
916 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
919 actor->SetWidth( HasWidth() ?
920 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
922 // libe width from properties
923 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
925 // set display vectors flag
926 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
929 int displayMode = HasDisplayMode() ?
930 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
932 // display mode from properties
933 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
935 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
936 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
937 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
938 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
940 if ( displayMode == 2 )
941 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
942 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
944 actor->setDisplayMode( displayMode );
949 actor->PickableOff();
951 if ( create && !isTemporary && aMgrId != -1 ) {
952 // set properties to the study
953 study->setObjectPropMap( aMgrId, entry, propMap );
957 //=================================================================
959 * GEOM_Displayer::Erase
960 * Calls Erase() method for each object in the given list
962 //=================================================================
963 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
965 const bool updateViewer )
967 SALOME_ListIteratorOfListIO Iter( theIOList );
968 for ( ; Iter.More(); Iter.Next() )
969 Erase( Iter.Value(), forced, false );
975 //=================================================================
977 * GEOM_Displayer::Redisplay
978 * Calls Redisplay() method for each object in the given list
980 //=================================================================
981 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
982 const bool updateViewer,
983 const bool checkActiveViewer )
985 SALOME_ListIteratorOfListIO Iter( theIOList );
986 for ( ; Iter.More(); Iter.Next() )
987 Redisplay( Iter.Value(), false, checkActiveViewer );
993 //=================================================================
995 * GEOM_Displayer::Update
996 * Update OCC presentaion
997 * [ Reimplemented from SALOME_Displayer ]
999 //=================================================================
1000 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1002 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1003 SalomeApp_Study* study = getStudy();
1005 if ( !occPrs || myShape.IsNull() || !study )
1008 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1011 // specific processing for local coordinate system presentation
1014 TopoDS_Face aFace = TopoDS::Face( myShape );
1015 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1016 if ( !aPlane.IsNull() )
1018 gp_Ax3 aPos = aPlane->Pln().Position();
1019 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1021 Handle(GEOM_AISTrihedron) aTrh;
1023 if ( occPrs->IsNull() )
1025 // new presentation is being created
1026 aTrh = new GEOM_AISTrihedron( aPlc );
1027 occPrs->AddObject( aTrh );
1031 // presentation is being updated
1032 AIS_ListOfInteractive aList;
1033 occPrs->GetObjects( aList );
1034 AIS_ListIteratorOfListOfInteractive anIter( aList );
1035 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1036 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1040 if ( !aTrh.IsNull() ) {
1041 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1043 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1044 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1046 aTrh->SetWidth( GetWidth() );
1048 if ( !myIO.IsNull() )
1050 aTrh->setIO( myIO );
1051 aTrh->SetOwner( myIO );
1053 aTrh->SetComponent( aPlc );
1054 aTrh->SetToUpdate();
1056 occPrs->SetToActivate( ToActivate() );
1062 // processing for usual geometry presentation
1065 // if presentation is empty we try to create new one
1066 if ( occPrs->IsNull() )
1068 // create presentation (specific for vectors)
1069 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1070 : new GEOM_AISShape ( myShape, "" );
1072 if( myType == GEOM_FIELD_STEP )
1073 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1074 // update shape properties
1075 updateShapeProperties( AISShape, true );
1077 // add shape to the presentation
1078 occPrs->AddObject( AISShape );
1080 // In accordance with ToActivate() value object will be activated/deactivated
1081 // when it will be displayed
1082 occPrs->SetToActivate( ToActivate() );
1084 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1085 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1087 // create additional wireframe shape
1088 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1089 aWirePrs->SetWidth(AISShape->Width());
1090 if ( !myIO.IsNull() ) {
1091 aWirePrs->setIO( myIO );
1092 aWirePrs->SetOwner( myIO );
1095 // add shape to the presentation
1096 occPrs->AddObject( aWirePrs );
1099 // if presentation is found -> set again shape for it
1102 AIS_ListOfInteractive IOList;
1103 occPrs->GetObjects( IOList );
1104 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1105 for ( ; Iter.More(); Iter.Next() )
1107 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1108 if ( AISShape.IsNull() )
1111 // re-set shape (it might be changed)
1112 if ( AISShape->Shape() != myShape )
1113 AISShape->Set( myShape );
1115 // update shape properties
1116 updateShapeProperties( AISShape, false );
1119 AISShape->UpdateSelection();
1120 AISShape->SetToUpdate();
1126 //=================================================================
1128 * GEOM_Displayer::Update
1129 * Update VTK presentaion
1130 * [ Reimplemented from SALOME_Displayer ]
1132 //=================================================================
1133 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1135 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1136 SalomeApp_Study* study = getStudy();
1138 if ( !vtkPrs || myShape.IsNull() || !study )
1141 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1144 // specific processing for local coordinate system presentation
1147 TopoDS_Face aFace = TopoDS::Face( myShape );
1148 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1149 if ( !aPlane.IsNull() ) {
1150 gp_Ax3 aPos = aPlane->Pln().Position();
1151 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1153 GEOM_VTKTrihedron* aTrh = 0;
1155 if ( vtkPrs->IsNull() ) {
1156 // new presentation is being created
1157 aTrh = GEOM_VTKTrihedron::New();
1158 vtkPrs->AddObject( aTrh );
1161 // presentation is being updated
1162 vtkActorCollection* actors = vtkPrs->GetObjects();
1164 actors->InitTraversal();
1165 vtkActor* a = actors->GetNextActor();
1166 while ( a && !aTrh ) {
1167 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1168 a = actors->GetNextActor();
1174 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1176 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1177 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1179 #ifdef VTK_TRIHEDRON_WIDTH
1181 // VSR: currently isn't supported
1183 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1185 aTrh->SetWidth( GetWidth() );
1188 if ( !myIO.IsNull() )
1189 aTrh->setIO( myIO );
1191 aTrh->SetPlacement( aPlc );
1198 // processing for usual geometry presentation
1201 // if presentation is empty we try to create new one
1202 if ( vtkPrs->IsNull() )
1205 GEOM_Actor* actor = GEOM_Actor::New();
1206 // update actor properties
1207 updateActorProperties( actor, true );
1208 // add actor to the presentation
1209 vtkPrs->AddObject( actor );
1212 // presentation is being updated
1213 vtkActorCollection* actors = vtkPrs->GetObjects();
1215 actors->InitTraversal();
1216 vtkActor* a = actors->GetNextActor();
1218 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1220 // update actor properties
1221 updateActorProperties( actor, false );
1222 a = actors->GetNextActor();
1230 //=================================================================
1232 * GEOM_Displayer::BuildPrs
1233 * Build presentation accordint to the current viewer type
1235 //=================================================================
1236 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1238 if ( theObj->_is_nil() )
1241 myViewFrame = GetActiveView();
1242 if ( myViewFrame == 0 )
1245 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1250 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1251 myType = theObj->GetType();
1253 // Update presentation
1259 //=================================================================
1261 * GEOM_Displayer::BuildPrs
1262 * Build presentation accordint to the current viewer type
1264 //=================================================================
1265 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1267 myViewFrame = GetActiveView();
1268 if ( theShape.IsNull() || myViewFrame == 0 )
1271 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1276 setShape( theShape );
1284 //=================================================================
1286 * GEOM_Displayer::buildPresentation
1287 * Builds/finds object's presentation for the current viewer
1288 * Calls corresponding Update() method by means of double dispatch
1291 //=================================================================
1292 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1293 SALOME_View* theViewFrame )
1295 SALOME_Prs* prs = 0;
1298 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1302 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1305 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1306 theIO->setEntry( entry.toLatin1().constData() );
1307 if ( !theIO.IsNull() )
1309 // set interactive object
1311 // Find SOBject (because shape should be published previously)
1312 SUIT_Session* session = SUIT_Session::session();
1313 SUIT_Application* app = session->activeApplication();
1316 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1319 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1322 // get CORBA reference to data object
1323 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1324 if ( !CORBA::is_nil( object ) )
1326 // downcast to GEOM base object
1327 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1328 if ( !GeomBaseObject->_is_nil() )
1330 myType = GeomBaseObject->GetType();
1332 // downcast to GEOM object
1333 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1334 if ( myType == GEOM_FIELD_STEP )
1336 // get the GEOM object from the field's shape
1337 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1338 if ( !GeomFieldStep->_is_nil() )
1340 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1341 if ( !GeomField->_is_nil() )
1342 GeomObject = GeomField->GetShape();
1345 // read the field step information
1346 readFieldStepInfo( GeomFieldStep );
1349 if ( !GeomObject->_is_nil() )
1351 // finally set shape
1352 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1360 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1366 //=================================================================
1368 * GEOM_Displayer::buildSubshapePresentation
1369 * Builds/finds object's presentation for the current viewer
1370 * Calls corresponding Update() method by means of double dispatch
1371 * For not published objects (for Mantis issue 0020435)
1373 //=================================================================
1374 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1375 const QString& entry,
1376 SALOME_View* theViewFrame)
1378 SALOME_Prs* prs = 0;
1381 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1385 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1388 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1389 theIO->setEntry(entry.toLatin1().constData());
1390 if (!theIO.IsNull())
1392 // set interactive object
1394 // finally set shape
1396 myType = GEOM_SUBSHAPE;
1398 UpdatePrs(prs); // Update presentation by using of the double dispatch
1404 //=================================================================
1406 * GEOM_Displayer::internalReset
1407 * Resets internal data
1410 //=================================================================
1411 void GEOM_Displayer::internalReset()
1416 myFieldDataType = GEOM::FDT_Double;
1417 myFieldDimension = 0;
1418 myFieldStepData.clear();
1419 myFieldStepName.Clear();
1420 myFieldStepRangeMin = 0;
1421 myFieldStepRangeMax = 0;
1424 //=================================================================
1426 * GEOM_Displayer::LocalSelection
1427 * Activate selection of CAD shapes with activisation of selection
1428 * of their sub-shapes (with opened local context for OCC viewer)
1430 //=================================================================
1431 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1433 SUIT_Session* session = SUIT_Session::session();
1434 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1438 LightApp_SelectionMgr* sm = app->selectionMgr();
1440 // remove all filters from selection
1443 SALOME_View* vf = GetActiveView();
1445 if (!theIO.IsNull() && !vf->isVisible(theIO))
1447 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1448 vf->LocalSelection( prs, theMode );
1449 delete prs; // delete presentation because displayer is its owner
1453 //=================================================================
1455 * GEOM_Displayer::globalSelection
1456 * Activate selection of CAD shapes without activisation of selection
1457 * of their sub-shapes (without opened local context for OCC viewer)
1459 //=================================================================
1460 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1462 TColStd_MapOfInteger aModes;
1463 aModes.Add( theMode );
1464 GlobalSelection( aModes, update );
1467 //=================================================================
1469 * GEOM_Displayer::globalSelection
1470 * Activate selection of CAD shapes without activisation of selection
1471 * of their sub-shapes (without opened local context for OCC viewer)
1473 //=================================================================
1474 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1475 const bool update, const QList<int>* theSubShapes )
1477 SUIT_Session* session = SUIT_Session::session();
1478 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1482 SALOME_View* vf = GetActiveView();
1486 // Close local context
1487 vf->GlobalSelection( update );
1489 // Set selection filters in accordance with current mode
1490 LightApp_SelectionMgr* sm = app->selectionMgr();
1494 // Remove from selection temporary objects if necessary
1495 if ( !theModes.Contains( GEOM_PREVIEW ) )
1496 clearTemporary( sm );
1498 //@ aSel->ClearIndex();
1502 // Remove filters from AIS_InteractiveContext
1503 Handle(AIS_InteractiveContext) ic;
1504 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1507 ic = viewer->getAISContext();
1509 ic->RemoveFilters();
1512 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1515 SUIT_SelectionFilter* aFilter;
1516 if ( theModes.Extent() == 1 )
1518 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1520 if ( aMode == GEOM_COMPOUNDFILTER )
1521 aFilter = getComplexFilter( theSubShapes );
1523 aFilter = getFilter( aMode );
1525 else if ( theModes.Extent() > 1 )
1527 TColStd_MapOfInteger aTopAbsModes;
1528 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1529 QList<SUIT_SelectionFilter*> aListOfFilters;
1530 for ( ; anIter.More(); anIter.Next() )
1532 SUIT_SelectionFilter* aFilter;
1533 int aMode = anIter.Key();
1534 if ( aMode == GEOM_COMPOUNDFILTER )
1535 aFilter = getComplexFilter( theSubShapes );
1537 aFilter = getFilter( aMode );
1540 aListOfFilters.append( aFilter );
1543 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1550 sm->installFilter( aFilter );
1553 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1554 ic->AddFilter( anOCCFilter );
1559 //=================================================================
1561 * GEOM_Displayer::LocalSelection
1562 * Activate selection of CAD shapes with activisation of selection
1563 * of their sub-shapes (with opened local context for OCC viewer)
1565 //=================================================================
1566 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1568 SALOME_ListIteratorOfListIO Iter( theIOList );
1569 for ( ; Iter.More(); Iter.Next() )
1570 LocalSelection( Iter.Value(), theMode );
1573 //=================================================================
1575 * GEOM_Displayer::BeforeDisplay
1576 * Called before displaying of pars. Close local context
1577 * [ Reimplemented from SALOME_Displayer ]
1579 //=================================================================
1580 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1582 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1585 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1588 if ( ic->HasOpenedContext() )
1589 ic->CloseAllContexts();
1594 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1596 SalomeApp_Study* aStudy = getStudy();
1597 if (!aStudy) return;
1598 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1599 if ( vf && !p->IsNull() ) {
1600 int aMgrId = getViewManagerId( vf );
1601 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1602 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1603 if ( !ic.IsNull() && prs ) {
1604 AIS_ListOfInteractive objects;
1605 prs->GetObjects( objects );
1606 AIS_ListIteratorOfListOfInteractive it( objects );
1607 for ( ; it.More(); it.Next() ) {
1608 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1609 if ( sh.IsNull() ) continue;
1610 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1611 if ( IO.IsNull() ) continue;
1612 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1613 if ( aPropMap.contains( GEOM::propertyName( GEOM::Transparency ) ) ) {
1614 double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble();
1615 ic->SetTransparency( sh, transparency, true );
1620 UpdateColorScale(false,false);
1623 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1625 LightApp_Displayer::AfterErase( v, p );
1626 UpdateColorScale(false,false);
1629 //=================================================================
1631 * GEOM_Displayer::SetColor
1632 * Set color for shape displaying. If it is equal -1 then default color is used.
1633 * Available values are from Quantity_NameOfColor enumeration
1635 //=================================================================
1636 void GEOM_Displayer::SetColor( const int color )
1643 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1647 int GEOM_Displayer::GetColor() const
1652 bool GEOM_Displayer::HasColor() const
1654 return myColor != -1;
1657 void GEOM_Displayer::UnsetColor()
1661 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1662 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1663 myShadingColor = SalomeApp_Tools::color( col );
1666 //=================================================================
1668 * GEOM_Displayer::SetTexture
1669 * Set color for shape displaying. If it is equal -1 then default color is used.
1670 * Available values are from Quantity_NameOfColor enumeration
1672 //=================================================================
1673 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1675 if(texureFileName!="")
1677 myTexture = texureFileName;
1681 bool GEOM_Displayer::HasTexture() const
1683 return myTexture != "";
1686 std::string GEOM_Displayer::GetTexture() const
1691 //=================================================================
1693 * GEOM_Displayer::SetWidth
1694 * Set width of shape displaying. If it is equal -1 then default width is used.
1696 //=================================================================
1697 void GEOM_Displayer::SetWidth( const double width )
1702 double GEOM_Displayer::GetWidth() const
1707 bool GEOM_Displayer::HasWidth() const
1709 return myWidth != -1;
1712 void GEOM_Displayer::UnsetWidth()
1718 int GEOM_Displayer::GetIsosWidth() const
1723 void GEOM_Displayer::SetIsosWidth(const int width)
1725 myIsosWidth = width;
1728 bool GEOM_Displayer::HasIsosWidth() const
1730 return myIsosWidth != -1;
1734 //=================================================================
1736 * GEOM_Displayer::SetToActivate
1737 * This method is used for activisation/deactivisation of objects to be displayed
1739 //=================================================================
1740 void GEOM_Displayer::SetToActivate( const bool toActivate )
1742 myToActivate = toActivate;
1744 bool GEOM_Displayer::ToActivate() const
1746 return myToActivate;
1749 //=================================================================
1751 * GEOM_Displayer::clearTemporary
1752 * Removes from selection temporary objects
1754 //=================================================================
1755 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1757 SALOME_ListIO selected, toSelect;
1758 theSelMgr->selectedObjects( selected );
1760 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1761 Handle(SALOME_InteractiveObject) io = it.Value();
1762 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1763 toSelect.Append( it.Value() );
1766 theSelMgr->setSelectedObjects( toSelect, true );
1769 void GEOM_Displayer::SetName( const char* theName )
1774 void GEOM_Displayer::UnsetName()
1779 SalomeApp_Study* GEOM_Displayer::getStudy() const
1781 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1784 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1789 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1794 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
1795 const int theFieldDimension,
1796 const QList<QVariant>& theFieldStepData,
1797 const TCollection_AsciiString& theFieldStepName,
1798 const double theFieldStepRangeMin,
1799 const double theFieldStepRangeMax )
1801 myFieldDataType = theFieldDataType;
1802 myFieldDimension = theFieldDimension;
1803 myFieldStepData = theFieldStepData;
1804 myFieldStepName = theFieldStepName;
1805 myFieldStepRangeMin = theFieldStepRangeMin;
1806 myFieldStepRangeMax = theFieldStepRangeMax;
1809 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1811 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
1812 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
1813 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
1814 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
1815 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
1816 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
1819 int GEOM_Displayer::SetDisplayMode( const int theMode )
1821 int aPrevMode = myDisplayMode;
1822 if ( theMode != -1 ) {
1823 myDisplayMode = theMode;
1824 myHasDisplayMode = true;
1832 int GEOM_Displayer::GetDisplayMode() const
1834 return myDisplayMode;
1837 int GEOM_Displayer::UnsetDisplayMode()
1839 int aPrevMode = myDisplayMode;
1840 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1841 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1842 myHasDisplayMode = false;
1846 bool GEOM_Displayer::HasDisplayMode() const
1848 return myHasDisplayMode;
1851 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1853 static QList<QColor> colors;
1855 if ( colors.isEmpty() ) {
1857 for (int s = 0; s < 2 ; s++)
1859 for (int v = 100; v >= 40; v = v - 20)
1861 for (int h = 0; h < 359 ; h = h + 60)
1863 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1869 static int currentColor = 0;
1871 SALOMEDS::Color color;
1872 color.R = (double)colors[currentColor].red() / 255.0;
1873 color.G = (double)colors[currentColor].green() / 255.0;
1874 color.B = (double)colors[currentColor].blue() / 255.0;
1876 currentColor = (currentColor+1) % colors.count();
1881 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1884 int aTolerance = 64;
1885 int anIterations = 0;
1891 if( anIterations % aPeriod == 0 )
1894 if( aTolerance < 1 )
1897 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1899 aHue = (int)( 360.0 * rand() / RAND_MAX );
1900 //std::cout << "Hue = " << aHue << std::endl;
1902 //std::cout << "Auto colors : ";
1904 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1905 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1906 for( ; it != itEnd; ++it )
1908 SALOMEDS::Color anAutoColor = *it;
1909 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1912 aQColor.getHsv( &h, &s, &v );
1913 //std::cout << h << " ";
1914 if( abs( h - aHue ) < aTolerance )
1917 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1921 //std::cout << std::endl;
1927 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1929 aColor.setHsv( aHue, 255, 255 );
1931 SALOMEDS::Color aSColor;
1932 aSColor.R = (double)aColor.red() / 255.0;
1933 aSColor.G = (double)aColor.green() / 255.0;
1934 aSColor.B = (double)aColor.blue() / 255.0;
1939 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1940 const QString& entry,
1943 // get default properties for the explicitly specified default view type
1944 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1946 if ( study && view ) {
1947 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1948 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1949 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1951 if ( viewModel && viewId != -1 ) {
1952 // get properties from the study
1953 PropMap storedMap = study->getObjectPropMap( viewId, entry );
1954 // overwrite default properties from stored ones (that are specified)
1955 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1956 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1957 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
1958 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1960 // ... specific processing for color
1961 // ... current implementation is to use same stored color for all aspects
1962 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1963 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1964 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1965 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1966 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1967 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1968 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1971 if ( !entry.isEmpty() ) {
1972 // get CORBA reference to geom object
1973 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1975 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1976 if ( !CORBA::is_nil( object ) ) {
1977 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1978 if ( !CORBA::is_nil( geomObject ) ) { // to check
1979 // check that geom object has color properly set
1980 bool hasColor = false;
1981 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1982 // set color from geometry object (only once, if it is not yet set in GUI)
1983 // current implementation is to use same color for all aspects
1984 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1985 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1986 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1987 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
1988 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1989 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
1990 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
1991 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
1993 // check that object has point marker properly set
1994 GEOM::marker_type mType = geomObject->GetMarkerType();
1995 GEOM::marker_size mSize = geomObject->GetMarkerSize();
1996 int mTextureId = geomObject->GetMarkerTexture();
1997 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
1998 ( mType == GEOM::MT_USER && mTextureId > 0 );
1999 // set point marker from geometry object (only once, if it is not yet set in GUI)
2000 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2001 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2003 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2004 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2006 else if ( mType == GEOM::MT_USER ) {
2008 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2020 PropMap GEOM_Displayer::getDefaultPropertyMap()
2024 // get resource manager
2025 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2027 // fill in the properties map with default values
2029 // - visibility (false by default)
2030 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2032 // - nb isos (take default value from preferences)
2033 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2034 QString( "%1%2%3" ).
2035 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2036 arg( GEOM::subSectionSeparator() ).
2037 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2039 // - transparency (opacity = 1-transparency)
2040 propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2042 // - display mode (take default value from preferences)
2043 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2044 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2046 // - show edges direction flag (false by default)
2047 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2049 // - shading color (take default value from preferences)
2050 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2051 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2053 // - wireframe color (take default value from preferences)
2054 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2055 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2057 // - standalone edges color (take default value from preferences)
2058 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2059 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2061 // - free boundaries color (take default value from preferences)
2062 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2063 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2065 // - points color (take default value from preferences)
2066 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2067 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2069 // - isos color (take default value from preferences)
2070 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2071 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2073 // - outlines color (take default value from preferences)
2074 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2075 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2077 // - deflection coefficient (take default value from preferences)
2078 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2079 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2081 // - material (take default value from preferences)
2082 Material_Model material;
2083 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2084 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2086 // - edge width (take default value from preferences)
2087 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2088 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2090 // - isos width (take default value from preferences)
2091 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2092 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2094 // - point marker (take default value from preferences)
2095 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2096 QString( "%1%2%3" ).
2097 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2098 arg( GEOM::subSectionSeparator() ).
2099 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2101 // - top-level flag (false by default)
2102 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2107 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2108 SALOMEDS::Color aSColor;
2111 SUIT_Session* session = SUIT_Session::session();
2112 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2114 if ( app && !theGeomObject->_is_nil()) {
2115 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2118 _PTR(Study) aStudy = study->studyDS();
2119 aSColor = theGeomObject->GetColor();
2120 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2122 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2123 bool general_autocolor = true;
2124 #else // auto-color for groups only
2125 bool general_autocolor = false;
2126 #endif // GENERAL_AUTOCOLOR
2127 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2128 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2129 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2130 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2131 aSColor = getPredefinedUniqueColor();
2133 #else // old algorithm for auto-colors
2134 QList<SALOMEDS::Color> aReservedColors;
2135 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2136 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2137 if ( aMainSObject ) {
2138 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2139 for ( ; it->More(); it->Next() ) {
2140 _PTR(SObject) aChildSObject( it->Value() );
2141 GEOM::GEOM_Object_var aChildObject =
2142 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2143 if ( CORBA::is_nil( aChildObject ) )
2146 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2147 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2148 aReservedColors.append( aReservedColor );
2151 aSColor = getUniqueColor( aReservedColors );
2153 #endif // SIMPLE_AUTOCOLOR
2163 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2164 const bool eraseOnlyChildren) {
2165 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2169 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2173 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2178 // Erase from all views
2179 QList<SALOME_View*> views;
2181 ViewManagerList vmans = app->viewManagers();
2182 SUIT_ViewManager* vman;
2183 foreach ( vman, vmans ) {
2184 SUIT_ViewModel* vmod = vman->getViewModel();
2185 view = dynamic_cast<SALOME_View*> ( vmod );
2187 views.append( view );
2190 if( views.count() == 0 )
2193 //Erase childrens w/o update views
2194 DataObjectList listObj = parent->children( true );
2195 SUIT_DataObject* obj;
2196 foreach( obj, listObj ) {
2197 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2199 foreach ( view, views ) {
2200 Handle(SALOME_InteractiveObject) anIO =
2201 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2202 Erase(anIO, false, false, view);
2206 //Erase parent with view update or repaint views
2207 foreach ( view, views ) {
2208 if(!eraseOnlyChildren)
2209 Erase(theIO, false, true, view);
2215 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2217 if( theGeomFieldStep->_is_nil() )
2220 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2221 if( aGeomField->_is_nil() )
2224 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2225 if( aGeomFieldShape->_is_nil() )
2228 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2229 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2230 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2232 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2234 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2236 int aFieldDimension = aGeomField->GetDimension();
2238 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2239 int aFieldNbComponents = aFieldComponents->length();
2241 QList<QVariant> aFieldStepData;
2242 if( aFieldDataType == GEOM::FDT_Bool )
2244 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2245 if ( !aGeomBoolFieldStep->_is_nil() )
2247 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2248 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2249 aFieldStepData << (bool)aValues[i];
2252 else if( aFieldDataType == GEOM::FDT_Int )
2254 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2255 if ( !aGeomIntFieldStep->_is_nil() )
2257 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2258 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2259 aFieldStepData << (qlonglong)aValues[i];
2262 else if( aFieldDataType == GEOM::FDT_Double )
2264 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2265 if ( !aGeomDoubleFieldStep->_is_nil() )
2267 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2268 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2269 aFieldStepData << (double)aValues[i];
2272 else if( aFieldDataType == GEOM::FDT_String )
2274 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2275 if ( !aGeomStringFieldStep->_is_nil() )
2277 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2278 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2279 aFieldStepData << QString( aValues[i] );
2283 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2284 aFieldStepData = groupFieldData( aFieldStepData,
2286 aFieldDataType == GEOM::FDT_String,
2288 aFieldStepRangeMax );
2290 setFieldStepInfo( aFieldDataType,
2295 aFieldStepRangeMax );
2298 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2299 const int theFieldNbComponents,
2300 const bool theIsString,
2301 double& theFieldStepRangeMin,
2302 double& theFieldStepRangeMax )
2304 QList<QVariant> aResultList;
2305 theFieldStepRangeMin = 0;
2306 theFieldStepRangeMax = 0;
2308 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2311 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2313 QList<QVariant> aGroupedList;
2315 bool anIsBoolean = false;
2316 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2319 QStringList aStringList;
2321 int aBaseIndex = aSubShape * theFieldNbComponents;
2322 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2324 int anIndex = aComponent + aBaseIndex;
2326 const QVariant& aVariant = theFieldStepData[ anIndex ];
2329 if( aVariant.type() == QVariant::String )
2330 aStringList << aVariant.toString();
2335 if( aVariant.type() == QVariant::Bool )
2337 aValue = aVariant.toBool() ? 1.0 : 0.0;
2343 if( aVariant.type() == QVariant::Int )
2344 aValue = double( aVariant.toInt() );
2345 else if( aVariant.type() == QVariant::Double )
2346 aValue = aVariant.toDouble();
2347 aNorm += aValue * aValue;
2353 aGroupedList << aStringList.join( "\n" );
2357 aNorm /= theFieldNbComponents;
2359 aNorm = pow( aNorm, 0.5 );
2361 if( aGroupedList.isEmpty() )
2362 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2365 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2366 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2369 aGroupedList << aNorm;
2375 theFieldStepRangeMin = 0.0;
2376 theFieldStepRangeMax = 1.0;
2379 SUIT_Session* session = SUIT_Session::session();
2380 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2381 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2383 QListIterator<QVariant> anIter( aGroupedList );
2384 while( anIter.hasNext() )
2386 const QVariant& aVariant = anIter.next();
2388 aResultList << aVariant;
2392 Quantity_Color aColor;
2393 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2394 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2395 aResultList << aQColor;
2401 // Note: the method is copied from Aspect_ColorScale class
2402 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2403 const Standard_Integer aMin,
2404 const Standard_Integer aMax )
2406 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2408 Standard_Integer aHue = maxLimit;
2410 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2412 aHue = Min( Max( minLimit, aHue ), maxLimit );
2417 // Note: the method is copied from Aspect_ColorScale class
2418 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2419 const Standard_Real aMin,
2420 const Standard_Real aMax,
2421 const Standard_Integer ColorsCount,
2422 Quantity_Color& aColor )
2424 if( aValue<aMin || aValue>aMax || aMax<aMin )
2425 return Standard_False;
2429 Standard_Real IntervNumber = 0;
2432 else if( aValue>aMax )
2433 IntervNumber = ColorsCount-1;
2434 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2435 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2437 Standard_Integer Interv = Standard_Integer( IntervNumber );
2439 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2441 return Standard_True;
2445 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2447 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2451 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2455 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2456 if( aViewer.IsNull() )
2459 aViewer->InitActiveViews();
2460 if( !aViewer->MoreActiveViews() )
2463 Handle(V3d_View) aView = aViewer->ActiveView();
2464 if( aView.IsNull() )
2467 Standard_Boolean anIsDisplayColorScale = Standard_False;
2468 TCollection_AsciiString aColorScaleTitle;
2469 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2470 Standard_Boolean anIsBoolean = Standard_False;
2472 SALOME_ListIO aSelectedObjects;
2473 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2474 if( aSelectedObjects.Extent() == 1 )
2476 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2477 if( !anIO.IsNull() )
2479 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2482 AIS_ListOfInteractive aList;
2483 aPrs->GetObjects( aList );
2484 AIS_ListIteratorOfListOfInteractive anIter( aList );
2485 for( ; anIter.More(); anIter.Next() )
2487 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2488 if( !aShape.IsNull() )
2490 GEOM::field_data_type aFieldDataType;
2491 int aFieldDimension;
2492 QList<QVariant> aFieldStepData;
2493 TCollection_AsciiString aFieldStepName;
2494 double aFieldStepRangeMin, aFieldStepRangeMax;
2495 aShape->getFieldStepInfo( aFieldDataType,
2500 aFieldStepRangeMax );
2501 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2503 anIsDisplayColorScale = Standard_True;
2504 aColorScaleTitle = aFieldStepName;
2505 aColorScaleMin = aFieldStepRangeMin;
2506 aColorScaleMax = aFieldStepRangeMax;
2507 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2515 if( anIsDisplayColorScale )
2517 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2518 if( !aColorScale.IsNull() )
2520 SUIT_Session* session = SUIT_Session::session();
2521 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2523 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2524 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2525 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2526 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2527 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2528 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2530 aColorScale->SetXPosition( anXPos );
2531 aColorScale->SetYPosition( anYPos );
2532 aColorScale->SetWidth( aWidth );
2533 aColorScale->SetHeight( aHeight );
2535 aColorScale->SetTextHeight( aTextHeight );
2536 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2538 aColorScale->SetTitle( aColorScaleTitle );
2539 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2541 if( !aView->ColorScaleIsDisplayed() )
2542 aView->ColorScaleDisplay();
2546 if( aView->ColorScaleIsDisplayed() )
2547 aView->ColorScaleErase();
2550 if( theIsRedisplayFieldSteps )
2552 _PTR(Study) aStudyDS = aStudy->studyDS();
2553 QList<SUIT_ViewManager*> vmList;
2554 myApp->viewManagers( vmList );
2555 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2557 if( SUIT_ViewManager* aViewManager = *vmIt )
2559 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2560 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2562 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2565 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2566 if( !CORBA::is_nil( anObject ) )
2568 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2569 if( !aFieldStep->_is_nil() )
2571 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2572 Handle(SALOME_InteractiveObject) aStepIO =
2573 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2574 Redisplay( aStepIO, false, false );