1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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"
28 #include "GEOMGUI_DimensionProperty.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_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
59 #include <Basics_OCCTVersion.hxx>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
68 #include <SALOME_ListIO.hxx>
69 #include <SALOME_Prs.h>
72 #include <SOCC_ViewModel.h>
75 #include <SVTK_ViewModel.h>
77 #include <OCCViewer_ViewWindow.h>
78 #include <OCCViewer_ViewPort3d.h>
79 #include <OCCViewer_Utilities.h>
82 #include <AIS_Drawer.hxx>
83 #include <AIS_Dimension.hxx>
84 #include <AIS_LengthDimension.hxx>
85 #include <AIS_DiameterDimension.hxx>
86 #include <AIS_AngleDimension.hxx>
87 #include <AIS_ListIteratorOfListOfInteractive.hxx>
88 #include <Aspect_PolygonOffsetMode.hxx>
89 #include <Aspect_ColorScale.hxx>
90 #include <Prs3d_IsoAspect.hxx>
91 #include <Prs3d_PointAspect.hxx>
92 #include <StdSelect_TypeOfEdge.hxx>
93 #include <StdSelect_TypeOfFace.hxx>
94 #include <StdSelect_DisplayMode.hxx>
95 #include <TopoDS_Face.hxx>
96 #include <BRep_Tool.hxx>
97 #include <Geom_Plane.hxx>
98 #include <Geom_Axis2Placement.hxx>
99 #include <Graphic3d_AspectFillArea3d.hxx>
100 #include <gp_Pln.hxx>
101 #include <TColStd_MapOfInteger.hxx>
102 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
103 #include <TopoDS_Iterator.hxx>
104 #include <Graphic3d_AspectMarker3d.hxx>
105 #include <TopTools_MapOfShape.hxx>
106 #include <TopTools_ListOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopoDS.hxx>
109 #include <NCollection_DataMap.hxx>
110 #include <NCollection_Map.hxx>
112 #include <Prs3d_ShadingAspect.hxx>
114 #include <BRepMesh_IncrementalMesh.hxx>
117 #include <vtkActorCollection.h>
118 #include <vtkProperty.h>
121 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
123 #include <GEOMImpl_Types.hxx>
125 #include <TColStd_HArray1OfByte.hxx>
127 // If the next macro is defined, autocolor feature works for all sub-shapes;
128 // if it is undefined, autocolor feature works for groups only
129 #define GENERAL_AUTOCOLOR
130 // Below macro, when uncommented, switches on simplified (more performant) algorithm
131 // of auto-color picking up
132 #define SIMPLE_AUTOCOLOR
134 // Hard-coded value of shape deflection coefficient for VTK viewer
135 const double VTK_MIN_DEFLECTION = 0.001;
137 // Pixmap caching support
140 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
141 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
142 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
144 static inline PixmapUsageMap& getPixmapUsageMap()
146 static PixmapUsageMap aMap;
150 static inline PixmapCacheMap& getPixmapCacheMap()
152 static PixmapCacheMap aMap;
156 //===========================================================================
157 // Function : getDefaultTexture
158 // Purpose : Get default texture
159 //===========================================================================
160 static inline Handle(Image_PixMap) getDefaultTexture()
162 static Handle(Image_PixMap) aPixmap;
163 if ( aPixmap.IsNull() ) {
164 QPixmap px(":images/default_texture.png");
166 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
171 //===========================================================================
172 // Function : cacheTextureFor
173 // Purpose : Load and cache image for the specified presentation.
174 //===========================================================================
175 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
176 const Handle(GEOM_AISShape)& theShape )
178 if ( thePath.isEmpty() )
181 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
182 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
184 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
185 if ( !aPixmap.IsNull() ) {
186 // point that the texture is used by the presentation
187 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
188 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
190 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
195 // convert texture to compatible image format
196 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
197 if ( anImage.isNull() )
200 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
202 aPixmapCacheMap.insert( thePath, aPixmap );
204 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
205 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
207 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
212 //===========================================================================
213 // Function : releaseTextures
214 // Purpose : Releases cached textures found for the specified presentation.
215 //===========================================================================
216 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
218 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
220 AIS_ListOfInteractive aListOfIO;
222 anOccPrs->GetObjects( aListOfIO );
224 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
226 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
227 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
229 for ( ; aIterateIO.More(); aIterateIO.Next() )
231 Handle(GEOM_AISShape) aAISShape =
232 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
234 if ( aAISShape.IsNull() )
237 #ifdef USE_TEXTURED_SHAPE
238 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
239 if ( aPixmap.IsNull() )
242 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
245 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
247 aUsersShapes.Remove( aAISShape );
249 if ( aUsersShapes.IsEmpty() ) {
250 aPixmapUsersMap.UnBind( aPixmap );
251 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
258 //================================================================
259 // Function : getActiveStudy
260 // Purpose : Get active study, returns 0 if no open study frame
261 //================================================================
262 static inline SalomeApp_Study* getActiveStudy()
264 SUIT_Session* session = SUIT_Session::session();
265 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
267 return ( SalomeApp_Study* )app->activeStudy();
271 static inline int getViewManagerId( SALOME_View* theViewFrame) {
272 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
273 SUIT_ViewManager* aViewMgr = 0;
275 aViewMgr = aModel->getViewManager();
276 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
279 //================================================================
280 // Function : getTopAbsMode
281 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
282 // one from GEOMImpl_Types.h
283 //================================================================
284 static inline int getTopAbsMode( const int implType )
288 case GEOM_COMPOUND : return TopAbs_COMPOUND;
289 case GEOM_SOLID : return TopAbs_SOLID;
290 case GEOM_SHELL : return TopAbs_SHELL;
291 case GEOM_FACE : return TopAbs_FACE;
292 case GEOM_WIRE : return TopAbs_WIRE;
293 case GEOM_EDGE : return TopAbs_EDGE;
294 case GEOM_POINT : return TopAbs_VERTEX;
299 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
301 if ( shape.IsNull() )
304 int ret = shape.ShapeType();
306 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
307 TopoDS_Iterator it(shape, Standard_True, Standard_False);
308 for (; it.More(); it.Next()) {
309 TopoDS_Shape sub_shape = it.Value();
310 if ( sub_shape.IsNull() ) continue;
311 int stype = getMinMaxShapeType( sub_shape, ismin );
312 if ( stype == TopAbs_SHAPE ) continue;
313 if ( ismin && stype > ret )
315 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
323 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
325 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
328 //================================================================
329 // Function : getFilter
330 // Purpose : Get filter corresponding to the type of object
331 // from GEOMImpl_Types.h
332 //================================================================
333 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
335 SUIT_SelectionFilter* aFilter;
337 int aTopAbsMode = getTopAbsMode( theMode );
338 if ( aTopAbsMode != -1 )
339 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
343 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
344 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
346 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
347 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
348 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
349 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
350 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
351 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
353 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
355 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
356 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
358 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
364 //================================================================
365 // Function : getComplexFilter
366 // Purpose : Get compound filter corresponding to the type of
367 // object from GEOMImpl_Types.h
368 //================================================================
369 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
371 GEOM_CompoundFilter* aFilter;
373 if(aSubShapes != NULL ) {
374 aFilter = new GEOM_CompoundFilter(getStudy());
375 QList<int> aTopAbsTypes;
376 QList<int>::const_iterator it;
377 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
378 int topAbsMode = getTopAbsMode(*it);
379 if(topAbsMode != -1 )
380 aTopAbsTypes.append(topAbsMode);
382 aFilter->addSubTypes(aTopAbsTypes);
388 //================================================================
389 // Function : getEntry
391 //================================================================
392 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
394 SUIT_Session* session = SUIT_Session::session();
395 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
398 CORBA::String_var IOR = app->orb()->object_to_string( object );
399 if ( strcmp(IOR.in(), "") != 0 )
401 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
402 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
410 //================================================================
411 // Function : getName
413 //================================================================
414 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
416 SUIT_Session* session = SUIT_Session::session();
417 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
420 CORBA::String_var IOR = app->orb()->object_to_string( object );
421 if ( strcmp(IOR.in(), "") != 0 )
423 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
424 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
426 _PTR(GenericAttribute) anAttr;
428 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
430 _PTR(AttributeName) aNameAttr( anAttr );
431 return aNameAttr->Value();
439 //=================================================================
441 * GEOM_Displayer::GEOM_Displayer
444 //=================================================================
445 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
448 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
453 SUIT_Session* session = SUIT_Session::session();
454 SUIT_ResourceMgr* resMgr = session->resourceMgr();
456 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
457 myShadingColor = SalomeApp_Tools::color( col );
459 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
460 myHasDisplayMode = false;
462 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
463 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
464 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
466 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
467 myHasTransparency = false;
469 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
470 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
471 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
474 // This color is used for shape displaying. If it is equal -1 then
475 // default color is used.
481 // This parameter is used for activisation/deactivisation of objects to be displayed
483 // Activate parallel vizualisation only for testing purpose
484 // and if the corresponding env variable is set to 1
485 char* parallel_visu = getenv("PARALLEL_VISU");
486 if (parallel_visu && atoi(parallel_visu))
488 MESSAGE("Parallel visualisation on");
489 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
494 myFieldDataType = GEOM::FDT_Double;
495 myFieldDimension = 0;
496 myFieldStepRangeMin = 0;
497 myFieldStepRangeMax = 0;
500 //=================================================================
502 * GEOM_Displayer::~GEOM_Displayer
505 //=================================================================
506 GEOM_Displayer::~GEOM_Displayer()
510 //=================================================================
512 * GEOM_Displayer::Display
513 * Display interactive object in the current viewer
515 //=================================================================
516 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
517 const bool updateViewer,
518 SALOME_View* theViewFrame )
520 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
523 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
527 vf->BeforeDisplay( this, prs );
529 vf->AfterDisplay( this, prs );
534 int aMgrId = getViewManagerId(vf);
535 SalomeApp_Study* aStudy = getStudy();
536 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
538 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
540 delete prs; // delete presentation because displayer is its owner
545 //=================================================================
547 * GEOM_Displayer::Display
548 * This overloaded Display() method can be useful for operations
549 * not using dialog boxes.
551 //=================================================================
552 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
554 if ( theObj->_is_nil() )
557 std::string entry = getEntry( theObj );
559 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
564 //=================================================================
566 * GEOM_Displayer::Erase
567 * Erase interactive object in the current viewer
569 //=================================================================
570 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
572 const bool updateViewer,
573 SALOME_View* theViewFrame )
575 if ( theIO.IsNull() )
578 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
581 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
583 vf->BeforeErase( this, prs );
584 vf->Erase( prs, forced );
585 vf->AfterErase( this, prs );
588 delete prs; // delete presentation because displayer is its owner
590 int aMgrId = getViewManagerId(vf);
591 SalomeApp_Study* aStudy = getStudy();
592 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
594 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
599 //=================================================================
601 * GEOM_Displayer::Erase
602 * Erase geometry object in the current viewer
604 //=================================================================
605 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
607 const bool updateViewer,
608 SALOME_View* theViewFrame)
610 std::string entry = getEntry( theObj );
613 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
614 forced, updateViewer, theViewFrame);
618 //=================================================================
620 * GEOM_Displayer::Redisplay
621 * Redisplay (erase and then display again) interactive object
622 * in the current viewer
624 //=================================================================
625 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
626 const bool updateViewer,
627 const bool checkActiveViewer )
629 // Remove the object permanently (<forced> == true)
630 SUIT_Session* ses = SUIT_Session::session();
631 SUIT_Application* app = ses->activeApplication();
634 SUIT_Desktop* desk = app->desktop();
635 QList<SUIT_ViewWindow*> wnds = desk->windows();
636 SUIT_ViewWindow* wnd;
637 QListIterator<SUIT_ViewWindow*> it( wnds );
638 while ( it.hasNext() && (wnd = it.next()) )
640 SUIT_ViewManager* vman = wnd->getViewManager();
643 SUIT_ViewModel* vmodel = vman->getViewModel();
646 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
649 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
651 Redisplay( theIO, updateViewer, view );
660 //=================================================================
662 * GEOM_Displayer::Redisplay
663 * Redisplay (erase and then display again) interactive object
664 * in the specified view
666 //=================================================================
667 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
668 const bool theUpdateViewer,
669 SALOME_View* theViewFrame )
671 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
677 Erase( theIO, true, false, theViewFrame );
678 Display( theIO, theUpdateViewer, theViewFrame );
681 //=================================================================
683 * GEOM_Displayer::Display
684 * Calls Display() method for each object in the given list
686 //=================================================================
687 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
689 SALOME_ListIteratorOfListIO Iter( theIOList );
690 for ( ; Iter.More(); Iter.Next() ) {
691 Display( Iter.Value(), false );
697 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
699 // VSR: this method can be improved in future:
700 // to improve performance, the default values from resource manager should be cached in the displayer
701 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
704 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
706 // VSR: this method can be improved in future:
707 // to improve performance, the default values from resource manager should be cached in the displayer
708 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
711 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
713 // check that shape is not null
714 if ( AISShape.IsNull() ) return;
716 // check that study is active
717 SalomeApp_Study* study = getStudy();
718 if ( !study ) return;
720 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
721 !TopoDS_Iterator(myShape).More() )
722 return; // NPAL15983 (Bug when displaying empty groups)
724 // set interactive object
726 Handle( SALOME_InteractiveObject ) anIO;
728 if ( !myIO.IsNull() ) {
729 AISShape->setIO( myIO );
730 AISShape->SetOwner( myIO );
733 else if ( !myName.empty() ) {
734 // workaround to allow selection of temporary objects
735 static int tempId = 0;
736 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
737 AISShape->setIO( anIO );
738 AISShape->SetOwner( anIO );
741 // flag: only vertex or compound of vertices is processed (specific handling)
742 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
743 // presentation study entry (empty for temporary objects like preview)
744 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
745 // flag: temporary object
746 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
747 // currently active view window's ID (-1 if no active view)
748 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
750 // get presentation properties
751 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
753 // Temporary staff: vertex must be infinite for correct visualization
754 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
757 Material_Model material;
758 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
760 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
761 // - set front material properties
762 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
763 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
764 // - set back material properties
765 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
766 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
767 // - switch to default (both sides) facing mode
768 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
774 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
775 // we set it to the shape not taking into account material properties
776 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
778 else if ( !material.isPhysical() ) {
779 // shading color from properties is used only for non-physical materials
780 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
784 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
785 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
786 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
787 AISShape->Attributes()->SetLineAspect( anAspect );
789 // - unfree boundaries color
790 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
791 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
792 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
793 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
795 // - free boundaries color
796 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
797 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
798 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
799 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
801 // - standalone edges color
802 anAspect = AISShape->Attributes()->WireAspect();
803 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
804 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
805 AISShape->Attributes()->SetWireAspect( anAspect );
807 // - color for edges in shading+edges mode
808 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
811 AISShape->SetDisplayMode( HasDisplayMode() ?
812 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
814 // display mode from properties
815 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
817 // - face boundaries color
818 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
819 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
820 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
821 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
822 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
824 // set display vectors flag
825 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
827 // set display vertices flag
828 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
829 AISShape->SetDisplayVertices( isVerticesMode );
832 if( HasTransparency() ) {
833 AISShape->SetTransparency( GetTransparency() );
835 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
838 // set iso properties
839 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
840 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
841 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
842 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
843 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
844 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
845 uIsoAspect->SetColor( isosColor );
846 uIsoAspect->SetWidth( isosWidth );
847 uIsoAspect->SetNumber( uIsos );
848 vIsoAspect->SetColor( isosColor );
849 vIsoAspect->SetWidth( isosWidth );
850 vIsoAspect->SetNumber( vIsos );
851 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
852 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
854 // set deflection coefficient
855 // ... to avoid to small values of the coefficient, its lower value is limited
856 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
860 if ( HasTexture() ) {
861 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
862 aImagePath = GetTexture().c_str();
863 if ( ! entry.isEmpty() ) {
864 // check that study is active
865 SalomeApp_Study* study = getActiveStudy();
867 // Store the texture in object properties for next displays
868 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
869 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
871 // Update propeties map
872 propMap = getObjectProperties( study, entry, myViewFrame );
877 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
880 #ifdef USE_TEXTURED_SHAPE
881 Handle(Image_PixMap) aPixmap;
882 if ( !aImagePath.isEmpty() )
883 aPixmap = cacheTextureFor( aImagePath, AISShape );
885 aPixmap = getDefaultTexture();
887 // apply image to shape
888 if ( !aPixmap.IsNull() ) {
889 AISShape->SetTexturePixMap( aPixmap );
890 AISShape->SetTextureMapOn();
891 AISShape->DisableTextureModulate();
894 AISShape->SetTextureMapOff();
899 AISShape->SetWidth( HasWidth() ?
900 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
902 // libe width from properties
903 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
905 // set top-level flag
906 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
908 // set point marker (for vertex / compound of vertices only)
909 if ( onlyVertex || isVerticesMode ) {
910 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
911 if ( aList.size() == 2 ) {
912 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
913 int aTypeOfMarker = aList[0].toInt();
914 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
915 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
916 anAspect->SetScale( aScaleOfMarker );
917 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
918 anAspect->SetColor( HasColor() ?
919 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
920 (Quantity_NameOfColor)GetColor() :
921 // color from properties
922 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
923 AISShape->Attributes()->SetPointAspect( anAspect );
925 else if ( aList.size() == 1 ) {
926 // custom marker string contains "IdOfTexture"
927 int textureId = aList[0].toInt();
928 Standard_Integer aWidth, aHeight;
929 Handle(TColStd_HArray1OfByte) aTexture =
930 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
931 if ( !aTexture.IsNull() ) {
932 Handle(Prs3d_PointAspect) aTextureAspect =
933 new Prs3d_PointAspect( HasColor() ?
934 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
935 (Quantity_NameOfColor)GetColor() :
936 // color from properties
937 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
940 AISShape->Attributes()->SetPointAspect( aTextureAspect );
945 // set field step data
946 AISShape->setFieldStepInfo( myFieldDataType,
951 myFieldStepRangeMax );
953 if ( create && !isTemporary && aMgrId != -1 ) {
954 // set properties to the study
955 study->setObjectPropMap( aMgrId, entry, propMap );
958 // AISShape->SetName(???); ??? necessary to set name ???
961 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
963 // check that actor is not null
964 if ( !actor ) return;
966 // check that study is active
967 SalomeApp_Study* study = getStudy();
968 if ( !study ) return;
970 // set interactive object
972 Handle( SALOME_InteractiveObject ) anIO;
974 if ( !myIO.IsNull() ) {
975 actor->setIO( myIO );
978 else if ( !myName.empty() ) {
979 // workaround to allow selection of temporary objects
980 static int tempId = 0;
981 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
982 actor->setIO( anIO );
985 // presentation study entry (empty for temporary objects like preview)
986 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
987 // flag: temporary object
988 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
989 // currently active view window's ID (-1 if no active view)
990 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
992 // get presentation properties
993 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
996 /////////////////////////////////////////////////////////////////////////
997 // VSR: for VTK viewer currently deflection coefficient is hardcoded
998 // due to performance problem
999 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1000 /////////////////////////////////////////////////////////////////////////
1001 if ( !actor->getTopo().IsSame( myShape ) )
1002 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1005 Material_Model material;
1006 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1007 std::vector<vtkProperty*> mprops;
1008 mprops.push_back( material.getMaterialVTKProperty( true ) );
1009 mprops.push_back( material.getMaterialVTKProperty( false) );
1010 actor->SetMaterial( mprops );
1012 // set iso-lines properties
1014 // - set number of iso-lines
1015 int nbIsos[2]= { 1, 1 };
1016 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1017 nbIsos[0] = isos[0].toInt();
1018 nbIsos[1] = isos[1].toInt();
1019 actor->SetNbIsos( nbIsos );
1021 // - set iso-lines width
1022 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1024 // - set iso-lines color
1025 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1026 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1031 // - same color for all sub-actors
1032 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1033 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1036 // shading color (for non-physical materials)
1037 if ( !material.isPhysical() ) {
1038 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1039 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1040 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1043 // - standalone edge color
1044 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1045 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1047 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1048 // - shared edges color ???
1049 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1051 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1052 // - free edges color ???
1053 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1056 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1057 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1060 // - color for edges in shading+edges mode
1061 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1062 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1065 if( HasTransparency() ) {
1066 actor->SetOpacity( 1.0 - GetTransparency() );
1068 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1072 actor->SetWidth( HasWidth() ?
1073 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1075 // libe width from properties
1076 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1078 // set display vectors flag
1079 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1081 // set display vertices flag
1082 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1085 int displayMode = HasDisplayMode() ?
1086 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1088 // display mode from properties
1089 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1091 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1092 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1093 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1094 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1096 if ( displayMode == 2 )
1097 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1098 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1100 actor->setDisplayMode( displayMode );
1103 actor->PickableOn();
1105 actor->PickableOff();
1107 if ( create && !isTemporary && aMgrId != -1 ) {
1108 // set properties to the study
1109 study->setObjectPropMap( aMgrId, entry, propMap );
1113 //=================================================================
1115 * GEOM_Displayer::updateDimensions
1116 * Creates or renews dimension presentation for the IO.
1118 //=================================================================
1119 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1120 SALOME_OCCPrs* thePrs,
1121 const gp_Ax3& theShapeLCS )
1123 SalomeApp_Study* aStudy = getStudy();
1129 if ( theIO.IsNull() )
1134 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1136 AIS_ListOfInteractive aListOfIO;
1138 anOccPrs->GetObjects( aListOfIO );
1140 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1142 // remove outdated presentations of dimensions
1143 for ( ; aIterateIO.More(); aIterateIO.Next() )
1145 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1146 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1151 aListOfIO.Remove( aIterateIO );
1153 if ( !aIterateIO.More() )
1159 // prepare dimension styling
1160 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1162 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1163 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1164 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1165 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1166 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1167 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1168 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1170 // restore dimension presentation from saved attribute or property data
1171 AIS_ListOfInteractive aRestoredDimensions;
1173 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1175 GEOM::propertyName( GEOM::Dimensions ),
1178 GEOMGUI_DimensionProperty aRecords;
1180 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1182 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1186 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1189 // create up-to-date dimension presentations
1190 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1192 if ( !aRecords.IsVisible( aPrsIt ) )
1197 // init dimension by type
1198 Handle(AIS_Dimension) aPrs;
1199 switch( aRecords.GetType( aPrsIt ) )
1201 case GEOMGUI_DimensionProperty::DimensionType_Length :
1203 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1204 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1209 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1211 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1212 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1217 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1219 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1220 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1226 aPrs->SetOwner( theIO );
1228 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1230 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1232 aStyle->SetCommonColor( aColor );
1233 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1234 aStyle->MakeText3d( Standard_True );
1235 aStyle->MakeTextShaded( Standard_True );
1236 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1237 aStyle->TextAspect()->SetHeight( aFontHeight );
1238 aStyle->ArrowAspect()->SetLength( anArrowLength );
1239 aStyle->LineAspect()->SetWidth( aLineWidth );
1240 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1241 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1242 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1243 aPrs->SetDimensionAspect( aStyle );
1244 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1245 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1246 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1248 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1250 // show degree symbol for dimension instead of label "deg"
1251 if ( aUnitsAngle == "deg" )
1253 aPrs->SetSpecialSymbol(0xB0);
1254 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1255 aStyle->MakeUnitsDisplayed(Standard_False);
1259 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1260 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1265 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1268 aListOfIO.Append( aPrs );
1271 // update presentation
1274 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1276 anOccPrs->AddObject( aIterateIO.Value() );
1280 //=================================================================
1282 * GEOM_Displayer::Erase
1283 * Calls Erase() method for each object in the given list
1285 //=================================================================
1286 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1288 const bool updateViewer )
1290 SALOME_ListIteratorOfListIO Iter( theIOList );
1291 for ( ; Iter.More(); Iter.Next() )
1292 Erase( Iter.Value(), forced, false );
1298 //=================================================================
1300 * GEOM_Displayer::Redisplay
1301 * Calls Redisplay() method for each object in the given list
1303 //=================================================================
1304 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1305 const bool updateViewer,
1306 const bool checkActiveViewer )
1308 SALOME_ListIteratorOfListIO Iter( theIOList );
1309 for ( ; Iter.More(); Iter.Next() )
1310 Redisplay( Iter.Value(), false, checkActiveViewer );
1316 //=================================================================
1318 * GEOM_Displayer::Redisplay
1319 * Calls Redisplay() method for each object in the given list
1321 //=================================================================
1322 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1323 const bool theUpdateViewer,
1324 SALOME_View* theViewFrame )
1326 SALOME_ListIteratorOfListIO anIter( theIOList );
1327 for ( ; anIter.More(); anIter.Next() )
1329 Redisplay( anIter.Value(), false, theViewFrame );
1332 if ( theUpdateViewer )
1338 //=================================================================
1340 * GEOM_Displayer::Update
1341 * Update OCC presentaion
1342 * [ Reimplemented from SALOME_Displayer ]
1344 //=================================================================
1345 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1347 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1348 SalomeApp_Study* study = getStudy();
1350 if ( !occPrs || myShape.IsNull() || !study )
1353 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1356 // specific processing for local coordinate system presentation
1359 TopoDS_Face aFace = TopoDS::Face( myShape );
1360 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1361 if ( !aPlane.IsNull() )
1363 gp_Ax3 aPos = aPlane->Pln().Position();
1364 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1366 Handle(GEOM_AISTrihedron) aTrh;
1368 if ( occPrs->IsNull() )
1370 // new presentation is being created
1371 aTrh = new GEOM_AISTrihedron( aPlc );
1372 occPrs->AddObject( aTrh );
1376 // presentation is being updated
1377 AIS_ListOfInteractive aList;
1378 occPrs->GetObjects( aList );
1379 AIS_ListIteratorOfListOfInteractive anIter( aList );
1380 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1381 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1385 if ( !aTrh.IsNull() ) {
1386 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1388 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1389 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1391 aTrh->SetWidth( GetWidth() );
1393 if ( !myIO.IsNull() )
1395 aTrh->setIO( myIO );
1396 aTrh->SetOwner( myIO );
1398 aTrh->SetComponent( aPlc );
1399 aTrh->SetToUpdate();
1401 occPrs->SetToActivate( ToActivate() );
1407 // processing for usual geometry presentation
1410 // if presentation is empty we try to create new one
1411 if ( occPrs->IsNull() )
1413 // create presentation (specific for vectors)
1414 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1415 : new GEOM_AISShape ( myShape, "" );
1417 if( myType == GEOM_FIELD_STEP )
1418 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1419 // update shape properties
1420 updateShapeProperties( AISShape, true );
1422 // add shape to the presentation
1423 occPrs->AddObject( AISShape );
1425 // In accordance with ToActivate() value object will be activated/deactivated
1426 // when it will be displayed
1427 occPrs->SetToActivate( ToActivate() );
1429 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1430 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1432 // create additional wireframe shape
1433 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1434 aWirePrs->SetWidth(AISShape->Width());
1435 if ( !myIO.IsNull() ) {
1436 aWirePrs->setIO( myIO );
1437 aWirePrs->SetOwner( myIO );
1440 // add shape to the presentation
1441 occPrs->AddObject( aWirePrs );
1444 // if presentation is found -> set again shape for it
1447 AIS_ListOfInteractive IOList;
1448 occPrs->GetObjects( IOList );
1449 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1450 for ( ; Iter.More(); Iter.Next() )
1452 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1453 if ( AISShape.IsNull() )
1456 // re-set shape (it might be changed)
1457 if ( AISShape->Shape() != myShape )
1458 AISShape->Set( myShape );
1460 // update shape properties
1461 updateShapeProperties( AISShape, false );
1464 AISShape->UpdateSelection();
1465 AISShape->SetToUpdate();
1469 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1473 //=================================================================
1475 * GEOM_Displayer::Update
1476 * Update VTK presentaion
1477 * [ Reimplemented from SALOME_Displayer ]
1479 //=================================================================
1480 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1482 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1483 SalomeApp_Study* study = getStudy();
1485 if ( !vtkPrs || myShape.IsNull() || !study )
1488 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1491 // specific processing for local coordinate system presentation
1494 TopoDS_Face aFace = TopoDS::Face( myShape );
1495 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1496 if ( !aPlane.IsNull() ) {
1497 gp_Ax3 aPos = aPlane->Pln().Position();
1498 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1500 GEOM_VTKTrihedron* aTrh = 0;
1502 if ( vtkPrs->IsNull() ) {
1503 // new presentation is being created
1504 aTrh = GEOM_VTKTrihedron::New();
1505 vtkPrs->AddObject( aTrh );
1508 // presentation is being updated
1509 vtkActorCollection* actors = vtkPrs->GetObjects();
1511 actors->InitTraversal();
1512 vtkActor* a = actors->GetNextActor();
1513 while ( a && !aTrh ) {
1514 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1515 a = actors->GetNextActor();
1521 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1523 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1524 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1526 #ifdef VTK_TRIHEDRON_WIDTH
1528 // VSR: currently isn't supported
1530 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1532 aTrh->SetWidth( GetWidth() );
1535 if ( !myIO.IsNull() )
1536 aTrh->setIO( myIO );
1538 aTrh->SetPlacement( aPlc );
1545 // processing for usual geometry presentation
1548 // if presentation is empty we try to create new one
1549 if ( vtkPrs->IsNull() )
1552 GEOM_Actor* actor = GEOM_Actor::New();
1553 // update actor properties
1554 updateActorProperties( actor, true );
1555 // add actor to the presentation
1556 vtkPrs->AddObject( actor );
1559 // presentation is being updated
1560 vtkActorCollection* actors = vtkPrs->GetObjects();
1562 actors->InitTraversal();
1563 vtkActor* a = actors->GetNextActor();
1565 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1567 // update actor properties
1568 updateActorProperties( actor, false );
1569 a = actors->GetNextActor();
1577 //=================================================================
1579 * GEOM_Displayer::BuildPrs
1580 * Build presentation accordint to the current viewer type
1582 //=================================================================
1583 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1585 if ( theObj->_is_nil() )
1588 myViewFrame = GetActiveView();
1589 if ( myViewFrame == 0 )
1592 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1597 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1598 myType = theObj->GetType();
1600 // Update presentation
1606 //=================================================================
1608 * GEOM_Displayer::BuildPrs
1609 * Build presentation accordint to the current viewer type
1611 //=================================================================
1612 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1614 myViewFrame = GetActiveView();
1615 if ( theShape.IsNull() || myViewFrame == 0 )
1618 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1623 setShape( theShape );
1631 //=================================================================
1633 * GEOM_Displayer::buildPresentation
1634 * Builds/finds object's presentation for the current viewer
1635 * Calls corresponding Update() method by means of double dispatch
1638 //=================================================================
1639 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1640 SALOME_View* theViewFrame )
1642 SALOME_Prs* prs = 0;
1645 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1649 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1652 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1653 theIO->setEntry( entry.toLatin1().constData() );
1654 if ( !theIO.IsNull() )
1656 // set interactive object
1658 // Find SOBject (because shape should be published previously)
1659 SUIT_Session* session = SUIT_Session::session();
1660 SUIT_Application* app = session->activeApplication();
1663 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1666 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1669 // get CORBA reference to data object
1670 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1671 if ( !CORBA::is_nil( object ) )
1673 // downcast to GEOM base object
1674 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1675 if ( !GeomBaseObject->_is_nil() )
1677 myType = GeomBaseObject->GetType();
1679 // downcast to GEOM object
1680 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1681 if ( myType == GEOM_FIELD_STEP )
1683 // get the GEOM object from the field's shape
1684 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1685 if ( !GeomFieldStep->_is_nil() )
1687 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1688 if ( !GeomField->_is_nil() )
1689 GeomObject = GeomField->GetShape();
1692 // read the field step information
1693 readFieldStepInfo( GeomFieldStep );
1696 if ( !GeomObject->_is_nil() )
1698 // finally set shape
1699 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1707 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1713 //=================================================================
1715 * GEOM_Displayer::buildSubshapePresentation
1716 * Builds/finds object's presentation for the current viewer
1717 * Calls corresponding Update() method by means of double dispatch
1718 * For not published objects (for Mantis issue 0020435)
1720 //=================================================================
1721 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1722 const QString& entry,
1723 SALOME_View* theViewFrame)
1725 SALOME_Prs* prs = 0;
1728 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1732 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1735 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1736 theIO->setEntry(entry.toLatin1().constData());
1737 if (!theIO.IsNull())
1739 // set interactive object
1741 // finally set shape
1743 myType = GEOM_SUBSHAPE;
1745 UpdatePrs(prs); // Update presentation by using of the double dispatch
1751 //=================================================================
1753 * GEOM_Displayer::internalReset
1754 * Resets internal data
1757 //=================================================================
1758 void GEOM_Displayer::internalReset()
1763 myFieldDataType = GEOM::FDT_Double;
1764 myFieldDimension = 0;
1765 myFieldStepData.clear();
1766 myFieldStepName.Clear();
1767 myFieldStepRangeMin = 0;
1768 myFieldStepRangeMax = 0;
1771 //=================================================================
1773 * GEOM_Displayer::LocalSelection
1774 * Activate selection of CAD shapes with activisation of selection
1775 * of their sub-shapes (with opened local context for OCC viewer)
1777 //=================================================================
1778 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1780 SUIT_Session* session = SUIT_Session::session();
1781 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1785 LightApp_SelectionMgr* sm = app->selectionMgr();
1787 // remove all filters from selection
1790 SALOME_View* vf = GetActiveView();
1792 if (!theIO.IsNull() && !vf->isVisible(theIO))
1794 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1795 vf->LocalSelection( prs, theMode );
1796 delete prs; // delete presentation because displayer is its owner
1800 //=================================================================
1802 * GEOM_Displayer::globalSelection
1803 * Activate selection of CAD shapes without activisation of selection
1804 * of their sub-shapes (without opened local context for OCC viewer)
1806 //=================================================================
1807 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1809 TColStd_MapOfInteger aModes;
1810 aModes.Add( theMode );
1811 GlobalSelection( aModes, update );
1814 //=================================================================
1816 * GEOM_Displayer::globalSelection
1817 * Activate selection of CAD shapes without activisation of selection
1818 * of their sub-shapes (without opened local context for OCC viewer)
1820 //=================================================================
1821 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1822 const bool update, const QList<int>* theSubShapes )
1824 SUIT_Session* session = SUIT_Session::session();
1825 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1829 SALOME_View* vf = GetActiveView();
1833 // Close local context
1834 vf->GlobalSelection( update );
1836 // Set selection filters in accordance with current mode
1837 LightApp_SelectionMgr* sm = app->selectionMgr();
1841 // Remove from selection temporary objects if necessary
1842 if ( !theModes.Contains( GEOM_PREVIEW ) )
1843 clearTemporary( sm );
1845 //@ aSel->ClearIndex();
1849 // Remove filters from AIS_InteractiveContext
1850 Handle(AIS_InteractiveContext) ic;
1851 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1854 ic = viewer->getAISContext();
1856 ic->RemoveFilters();
1859 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1862 SUIT_SelectionFilter* aFilter;
1863 if ( theModes.Extent() == 1 )
1865 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1867 if ( aMode == GEOM_COMPOUNDFILTER )
1868 aFilter = getComplexFilter( theSubShapes );
1870 aFilter = getFilter( aMode );
1872 else if ( theModes.Extent() > 1 )
1874 TColStd_MapOfInteger aTopAbsModes;
1875 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1876 QList<SUIT_SelectionFilter*> aListOfFilters;
1877 for ( ; anIter.More(); anIter.Next() )
1879 SUIT_SelectionFilter* aFilter;
1880 int aMode = anIter.Key();
1881 if ( aMode == GEOM_COMPOUNDFILTER )
1882 aFilter = getComplexFilter( theSubShapes );
1884 aFilter = getFilter( aMode );
1887 aListOfFilters.append( aFilter );
1890 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1897 sm->installFilter( aFilter );
1900 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1901 ic->AddFilter( anOCCFilter );
1906 //=================================================================
1908 * GEOM_Displayer::LocalSelection
1909 * Activate selection of CAD shapes with activisation of selection
1910 * of their sub-shapes (with opened local context for OCC viewer)
1912 //=================================================================
1913 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1915 SALOME_ListIteratorOfListIO Iter( theIOList );
1916 for ( ; Iter.More(); Iter.Next() )
1917 LocalSelection( Iter.Value(), theMode );
1920 //=================================================================
1922 * GEOM_Displayer::BeforeDisplay
1923 * Called before displaying of pars. Close local context
1924 * [ Reimplemented from SALOME_Displayer ]
1926 //=================================================================
1927 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1929 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1932 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1935 if ( ic->HasOpenedContext() )
1936 ic->CloseAllContexts();
1941 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1943 UpdateColorScale(false,false);
1946 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1948 LightApp_Displayer::BeforeErase( v, p );
1949 releaseTextures( p );
1952 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1954 LightApp_Displayer::AfterErase( v, p );
1955 UpdateColorScale(false,false);
1958 //=================================================================
1960 * GEOM_Displayer::SetColor
1961 * Set color for shape displaying. If it is equal -1 then default color is used.
1962 * Available values are from Quantity_NameOfColor enumeration
1964 //=================================================================
1965 void GEOM_Displayer::SetColor( const int color )
1972 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1976 int GEOM_Displayer::GetColor() const
1981 bool GEOM_Displayer::HasColor() const
1983 return myColor != -1;
1986 void GEOM_Displayer::UnsetColor()
1990 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1991 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1992 myShadingColor = SalomeApp_Tools::color( col );
1995 //=================================================================
1997 * GEOM_Displayer::SetTransparency
1998 * Set transparency for shape displaying.
2000 //=================================================================
2001 double GEOM_Displayer::SetTransparency( const double transparency )
2003 double aPrevTransparency = myTransparency;
2004 if ( transparency < 0 ) {
2005 UnsetTransparency();
2008 myTransparency = transparency;
2009 myHasTransparency = true;
2011 return aPrevTransparency;
2014 //=================================================================
2016 * GEOM_Displayer::GetTransparency
2017 * Get transparency for shape displaying.
2019 //=================================================================
2020 double GEOM_Displayer::GetTransparency() const
2022 return myTransparency;
2025 //=================================================================
2027 * GEOM_Displayer::HasTransparency
2028 * Check if transparency for shape displaying is set.
2030 //=================================================================
2031 bool GEOM_Displayer::HasTransparency() const
2033 return myHasTransparency;
2036 //=================================================================
2038 * GEOM_Displayer::UnsetTransparency
2039 * Unset transparency for shape displaying.
2041 //=================================================================
2042 double GEOM_Displayer::UnsetTransparency()
2044 double aPrevTransparency = myTransparency;
2045 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2046 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
2047 myHasTransparency = false;
2048 return aPrevTransparency;
2052 //=================================================================
2054 * GEOM_Displayer::SetTexture
2055 * Set color for shape displaying. If it is equal -1 then default color is used.
2056 * Available values are from Quantity_NameOfColor enumeration
2058 //=================================================================
2059 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2061 if(texureFileName!="")
2063 myTexture = texureFileName;
2067 bool GEOM_Displayer::HasTexture() const
2069 return myTexture != "";
2072 std::string GEOM_Displayer::GetTexture() const
2077 //=================================================================
2079 * GEOM_Displayer::SetWidth
2080 * Set width of shape displaying. If it is equal -1 then default width is used.
2082 //=================================================================
2083 void GEOM_Displayer::SetWidth( const double width )
2088 double GEOM_Displayer::GetWidth() const
2093 bool GEOM_Displayer::HasWidth() const
2095 return myWidth != -1;
2098 void GEOM_Displayer::UnsetWidth()
2104 int GEOM_Displayer::GetIsosWidth() const
2109 void GEOM_Displayer::SetIsosWidth(const int width)
2111 myIsosWidth = width;
2114 bool GEOM_Displayer::HasIsosWidth() const
2116 return myIsosWidth != -1;
2120 //=================================================================
2122 * GEOM_Displayer::SetToActivate
2123 * This method is used for activisation/deactivisation of objects to be displayed
2125 //=================================================================
2126 void GEOM_Displayer::SetToActivate( const bool toActivate )
2128 myToActivate = toActivate;
2130 bool GEOM_Displayer::ToActivate() const
2132 return myToActivate;
2135 //=================================================================
2137 * GEOM_Displayer::clearTemporary
2138 * Removes from selection temporary objects
2140 //=================================================================
2141 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2143 SALOME_ListIO selected, toSelect;
2144 theSelMgr->selectedObjects( selected );
2146 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2147 Handle(SALOME_InteractiveObject) io = it.Value();
2148 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2149 toSelect.Append( it.Value() );
2152 theSelMgr->setSelectedObjects( toSelect, true );
2155 void GEOM_Displayer::SetName( const char* theName )
2160 void GEOM_Displayer::UnsetName()
2165 SalomeApp_Study* GEOM_Displayer::getStudy() const
2167 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2170 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2175 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2180 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2181 const int theFieldDimension,
2182 const QList<QVariant>& theFieldStepData,
2183 const TCollection_AsciiString& theFieldStepName,
2184 const double theFieldStepRangeMin,
2185 const double theFieldStepRangeMax )
2187 myFieldDataType = theFieldDataType;
2188 myFieldDimension = theFieldDimension;
2189 myFieldStepData = theFieldStepData;
2190 myFieldStepName = theFieldStepName;
2191 myFieldStepRangeMin = theFieldStepRangeMin;
2192 myFieldStepRangeMax = theFieldStepRangeMax;
2195 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2197 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2198 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2199 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2200 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2201 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2202 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2205 int GEOM_Displayer::SetDisplayMode( const int theMode )
2207 int aPrevMode = myDisplayMode;
2208 if ( theMode != -1 ) {
2209 myDisplayMode = theMode;
2210 myHasDisplayMode = true;
2218 int GEOM_Displayer::GetDisplayMode() const
2220 return myDisplayMode;
2223 int GEOM_Displayer::UnsetDisplayMode()
2225 int aPrevMode = myDisplayMode;
2226 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2227 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2228 myHasDisplayMode = false;
2232 bool GEOM_Displayer::HasDisplayMode() const
2234 return myHasDisplayMode;
2237 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2239 static QList<QColor> colors;
2241 if ( colors.isEmpty() ) {
2243 for (int s = 0; s < 2 ; s++)
2245 for (int v = 100; v >= 40; v = v - 20)
2247 for (int h = 0; h < 359 ; h = h + 60)
2249 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2255 static int currentColor = 0;
2257 SALOMEDS::Color color;
2258 color.R = (double)colors[currentColor].red() / 255.0;
2259 color.G = (double)colors[currentColor].green() / 255.0;
2260 color.B = (double)colors[currentColor].blue() / 255.0;
2262 currentColor = (currentColor+1) % colors.count();
2267 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2270 int aTolerance = 64;
2271 int anIterations = 0;
2277 if( anIterations % aPeriod == 0 )
2280 if( aTolerance < 1 )
2283 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2285 aHue = (int)( 360.0 * rand() / RAND_MAX );
2286 //std::cout << "Hue = " << aHue << std::endl;
2288 //std::cout << "Auto colors : ";
2290 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2291 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2292 for( ; it != itEnd; ++it )
2294 SALOMEDS::Color anAutoColor = *it;
2295 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2298 aQColor.getHsv( &h, &s, &v );
2299 //std::cout << h << " ";
2300 if( abs( h - aHue ) < aTolerance )
2303 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2307 //std::cout << std::endl;
2313 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2315 aColor.setHsv( aHue, 255, 255 );
2317 SALOMEDS::Color aSColor;
2318 aSColor.R = (double)aColor.red() / 255.0;
2319 aSColor.G = (double)aColor.green() / 255.0;
2320 aSColor.B = (double)aColor.blue() / 255.0;
2325 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2326 const QString& entry,
2329 // get default properties for the explicitly specified default view type
2330 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2332 if ( study && view ) {
2333 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2334 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2335 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2337 if ( viewModel && viewId != -1 ) {
2338 // get properties from the study
2339 PropMap storedMap = study->getObjectPropMap( viewId, entry );
2340 // overwrite default properties from stored ones (that are specified)
2341 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2342 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2343 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2344 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2346 // ... specific processing for color
2347 // ... current implementation is to use same stored color for all aspects
2348 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2349 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2350 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2351 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2352 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2353 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2354 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2357 if ( !entry.isEmpty() ) {
2358 // get CORBA reference to geom object
2359 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2361 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2362 if ( !CORBA::is_nil( object ) ) {
2363 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2364 if ( !CORBA::is_nil( geomObject ) ) { // to check
2365 // check that geom object has color properly set
2366 bool hasColor = false;
2367 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2368 // set color from geometry object (only once, if it is not yet set in GUI)
2369 // current implementation is to use same color for all aspects
2370 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2371 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2372 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2373 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2374 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2375 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2376 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2377 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2379 // check that object has point marker properly set
2380 GEOM::marker_type mType = geomObject->GetMarkerType();
2381 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2382 int mTextureId = geomObject->GetMarkerTexture();
2383 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2384 ( mType == GEOM::MT_USER && mTextureId > 0 );
2385 // set point marker from geometry object (only once, if it is not yet set in GUI)
2386 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2387 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2389 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2390 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2392 else if ( mType == GEOM::MT_USER ) {
2394 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2406 PropMap GEOM_Displayer::getDefaultPropertyMap()
2410 // get resource manager
2411 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2413 // fill in the properties map with default values
2415 // - visibility (false by default)
2416 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2418 // - nb isos (take default value from preferences)
2419 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2420 QString( "%1%2%3" ).
2421 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2422 arg( GEOM::subSectionSeparator() ).
2423 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2425 // - transparency (opacity = 1-transparency)
2426 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2427 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2429 // - display mode (take default value from preferences)
2430 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2431 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2433 // - show edges direction flag (false by default)
2434 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2436 // - show vertices flag (false by default)
2437 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2439 // - shading color (take default value from preferences)
2440 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2441 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2443 // - wireframe color (take default value from preferences)
2444 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2445 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2447 // - standalone edges color (take default value from preferences)
2448 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2449 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2451 // - free boundaries color (take default value from preferences)
2452 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2453 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2455 // - points color (take default value from preferences)
2456 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2457 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2459 // - isos color (take default value from preferences)
2460 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2461 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2463 // - outlines color (take default value from preferences)
2464 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2465 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2467 // - deflection coefficient (take default value from preferences)
2468 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2469 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2471 // - material (take default value from preferences)
2472 Material_Model material;
2473 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2474 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2476 // - edge width (take default value from preferences)
2477 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2478 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2480 // - isos width (take default value from preferences)
2481 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2482 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2484 // - point marker (take default value from preferences)
2485 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2486 QString( "%1%2%3" ).
2487 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2488 arg( GEOM::subSectionSeparator() ).
2489 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2491 // - top-level flag (false by default)
2492 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2497 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2498 SALOMEDS::Color aSColor;
2501 SUIT_Session* session = SUIT_Session::session();
2502 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2504 if ( app && !theGeomObject->_is_nil()) {
2505 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2508 _PTR(Study) aStudy = study->studyDS();
2509 aSColor = theGeomObject->GetColor();
2510 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2512 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2513 bool general_autocolor = true;
2514 #else // auto-color for groups only
2515 bool general_autocolor = false;
2516 #endif // GENERAL_AUTOCOLOR
2517 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2518 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2519 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2520 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2521 aSColor = getPredefinedUniqueColor();
2523 #else // old algorithm for auto-colors
2524 QList<SALOMEDS::Color> aReservedColors;
2525 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2526 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2527 if ( aMainSObject ) {
2528 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2529 for ( ; it->More(); it->Next() ) {
2530 _PTR(SObject) aChildSObject( it->Value() );
2531 GEOM::GEOM_Object_var aChildObject =
2532 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2533 if ( CORBA::is_nil( aChildObject ) )
2536 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2537 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2538 aReservedColors.append( aReservedColor );
2541 aSColor = getUniqueColor( aReservedColors );
2543 #endif // SIMPLE_AUTOCOLOR
2553 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2554 const bool eraseOnlyChildren) {
2555 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2559 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2563 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2568 // Erase from all views
2569 QList<SALOME_View*> views;
2571 ViewManagerList vmans = app->viewManagers();
2572 SUIT_ViewManager* vman;
2573 foreach ( vman, vmans ) {
2574 SUIT_ViewModel* vmod = vman->getViewModel();
2575 view = dynamic_cast<SALOME_View*> ( vmod );
2577 views.append( view );
2580 if( views.count() == 0 )
2583 //Erase childrens w/o update views
2584 DataObjectList listObj = parent->children( true );
2585 SUIT_DataObject* obj;
2586 foreach( obj, listObj ) {
2587 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2589 foreach ( view, views ) {
2590 Handle(SALOME_InteractiveObject) anIO =
2591 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2592 Erase(anIO, false, false, view);
2596 //Erase parent with view update or repaint views
2597 foreach ( view, views ) {
2598 if(!eraseOnlyChildren)
2599 Erase(theIO, false, true, view);
2605 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2607 if( theGeomFieldStep->_is_nil() )
2610 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2611 if( aGeomField->_is_nil() )
2614 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2615 if( aGeomFieldShape->_is_nil() )
2618 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2619 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2620 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2622 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2624 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2626 int aFieldDimension = aGeomField->GetDimension();
2628 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2629 int aFieldNbComponents = aFieldComponents->length();
2631 QList<QVariant> aFieldStepData;
2632 if( aFieldDataType == GEOM::FDT_Bool )
2634 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2635 if ( !aGeomBoolFieldStep->_is_nil() )
2637 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2638 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2639 aFieldStepData << (bool)aValues[i];
2642 else if( aFieldDataType == GEOM::FDT_Int )
2644 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2645 if ( !aGeomIntFieldStep->_is_nil() )
2647 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2648 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2649 aFieldStepData << (qlonglong)aValues[i];
2652 else if( aFieldDataType == GEOM::FDT_Double )
2654 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2655 if ( !aGeomDoubleFieldStep->_is_nil() )
2657 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2658 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2659 aFieldStepData << (double)aValues[i];
2662 else if( aFieldDataType == GEOM::FDT_String )
2664 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2665 if ( !aGeomStringFieldStep->_is_nil() )
2667 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2668 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2669 aFieldStepData << QString( aValues[i] );
2673 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2674 aFieldStepData = groupFieldData( aFieldStepData,
2676 aFieldDataType == GEOM::FDT_String,
2678 aFieldStepRangeMax );
2680 setFieldStepInfo( aFieldDataType,
2685 aFieldStepRangeMax );
2688 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2689 const int theFieldNbComponents,
2690 const bool theIsString,
2691 double& theFieldStepRangeMin,
2692 double& theFieldStepRangeMax )
2694 QList<QVariant> aResultList;
2695 theFieldStepRangeMin = 0;
2696 theFieldStepRangeMax = 0;
2698 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2701 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2703 QList<QVariant> aGroupedList;
2705 bool anIsBoolean = false;
2706 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2709 QStringList aStringList;
2711 int aBaseIndex = aSubShape * theFieldNbComponents;
2712 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2714 int anIndex = aComponent + aBaseIndex;
2716 const QVariant& aVariant = theFieldStepData[ anIndex ];
2719 if( aVariant.type() == QVariant::String )
2720 aStringList << aVariant.toString();
2725 if( aVariant.type() == QVariant::Bool )
2727 aValue = aVariant.toBool() ? 1.0 : 0.0;
2733 if( aVariant.type() == QVariant::LongLong )
2734 aValue = double( aVariant.toLongLong() );
2735 else if( aVariant.type() == QVariant::Double )
2736 aValue = aVariant.toDouble();
2737 aNorm += aValue * aValue;
2743 aGroupedList << aStringList.join( "\n" );
2747 aNorm /= theFieldNbComponents;
2749 aNorm = pow( aNorm, 0.5 );
2751 if( aGroupedList.isEmpty() )
2752 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2755 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2756 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2759 aGroupedList << aNorm;
2765 theFieldStepRangeMin = 0.0;
2766 theFieldStepRangeMax = 1.0;
2769 SUIT_Session* session = SUIT_Session::session();
2770 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2771 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2773 QListIterator<QVariant> anIter( aGroupedList );
2774 while( anIter.hasNext() )
2776 const QVariant& aVariant = anIter.next();
2778 aResultList << aVariant;
2782 Quantity_Color aColor;
2783 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2784 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2785 aResultList << aQColor;
2791 // Note: the method is copied from Aspect_ColorScale class
2792 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2793 const Standard_Integer aMin,
2794 const Standard_Integer aMax )
2796 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2798 Standard_Integer aHue = maxLimit;
2800 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2802 aHue = Min( Max( minLimit, aHue ), maxLimit );
2807 // Note: the method is copied from Aspect_ColorScale class
2808 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2809 const Standard_Real aMin,
2810 const Standard_Real aMax,
2811 const Standard_Integer ColorsCount,
2812 Quantity_Color& aColor )
2814 if( aValue<aMin || aValue>aMax || aMax<aMin )
2815 return Standard_False;
2819 Standard_Real IntervNumber = 0;
2822 else if( aValue>aMax )
2823 IntervNumber = ColorsCount-1;
2824 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2825 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2827 Standard_Integer Interv = Standard_Integer( IntervNumber );
2829 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2831 return Standard_True;
2835 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2837 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2841 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2845 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2846 if( aViewer.IsNull() )
2849 aViewer->InitActiveViews();
2850 if( !aViewer->MoreActiveViews() )
2853 Handle(V3d_View) aView = aViewer->ActiveView();
2854 if( aView.IsNull() )
2857 Standard_Boolean anIsDisplayColorScale = Standard_False;
2858 TCollection_AsciiString aColorScaleTitle;
2859 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2860 Standard_Boolean anIsBoolean = Standard_False;
2862 SALOME_ListIO aSelectedObjects;
2863 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2864 if( aSelectedObjects.Extent() == 1 )
2866 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2867 if( !anIO.IsNull() )
2869 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2872 AIS_ListOfInteractive aList;
2873 aPrs->GetObjects( aList );
2874 AIS_ListIteratorOfListOfInteractive anIter( aList );
2875 for( ; anIter.More(); anIter.Next() )
2877 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2878 if( !aShape.IsNull() )
2880 GEOM::field_data_type aFieldDataType;
2881 int aFieldDimension;
2882 QList<QVariant> aFieldStepData;
2883 TCollection_AsciiString aFieldStepName;
2884 double aFieldStepRangeMin, aFieldStepRangeMax;
2885 aShape->getFieldStepInfo( aFieldDataType,
2890 aFieldStepRangeMax );
2891 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2893 anIsDisplayColorScale = Standard_True;
2894 aColorScaleTitle = aFieldStepName;
2895 aColorScaleMin = aFieldStepRangeMin;
2896 aColorScaleMax = aFieldStepRangeMax;
2897 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2905 if( anIsDisplayColorScale )
2907 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2908 if( !aColorScale.IsNull() )
2910 SUIT_Session* session = SUIT_Session::session();
2911 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2913 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2914 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2915 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2916 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2917 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2918 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2920 aColorScale->SetXPosition( anXPos );
2921 aColorScale->SetYPosition( anYPos );
2922 aColorScale->SetWidth( aWidth );
2923 aColorScale->SetHeight( aHeight );
2925 aColorScale->SetTextHeight( aTextHeight );
2926 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2928 aColorScale->SetTitle( aColorScaleTitle );
2929 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2931 if( !aView->ColorScaleIsDisplayed() )
2932 aView->ColorScaleDisplay();
2936 if( aView->ColorScaleIsDisplayed() )
2937 aView->ColorScaleErase();
2940 if( theIsRedisplayFieldSteps )
2942 _PTR(Study) aStudyDS = aStudy->studyDS();
2943 QList<SUIT_ViewManager*> vmList;
2944 myApp->viewManagers( vmList );
2945 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2947 if( SUIT_ViewManager* aViewManager = *vmIt )
2949 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2950 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2952 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2955 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2956 if( !CORBA::is_nil( anObject ) )
2958 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2959 if( !aFieldStep->_is_nil() )
2961 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2962 Handle(SALOME_InteractiveObject) aStepIO =
2963 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2964 Redisplay( aStepIO, false, false );