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 );
528 vf->Display( this, prs );
529 vf->AfterDisplay( this, prs );
534 delete prs; // delete presentation because displayer is its owner
539 //=================================================================
541 * GEOM_Displayer::Display
542 * This overloaded Display() method can be useful for operations
543 * not using dialog boxes.
545 //=================================================================
546 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
548 if ( theObj->_is_nil() )
551 std::string entry = getEntry( theObj );
553 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
558 //=================================================================
560 * GEOM_Displayer::Erase
561 * Erase interactive object in the current viewer
563 //=================================================================
564 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
566 const bool updateViewer,
567 SALOME_View* theViewFrame )
569 if ( theIO.IsNull() )
572 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
575 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
577 vf->BeforeErase( this, prs );
578 vf->Erase( this, prs, forced );
579 vf->AfterErase( this, prs );
582 delete prs; // delete presentation because displayer is its owner
587 //=================================================================
589 * GEOM_Displayer::Erase
590 * Erase geometry object in the current viewer
592 //=================================================================
593 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
595 const bool updateViewer,
596 SALOME_View* theViewFrame)
598 std::string entry = getEntry( theObj );
601 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
602 forced, updateViewer, theViewFrame);
606 //=================================================================
608 * GEOM_Displayer::Redisplay
609 * Redisplay (erase and then display again) interactive object
610 * in the current viewer
612 //=================================================================
613 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
614 const bool updateViewer,
615 const bool checkActiveViewer )
617 // Remove the object permanently (<forced> == true)
618 SUIT_Session* ses = SUIT_Session::session();
619 SUIT_Application* app = ses->activeApplication();
622 SUIT_Desktop* desk = app->desktop();
623 QList<SUIT_ViewWindow*> wnds = desk->windows();
624 SUIT_ViewWindow* wnd;
625 QListIterator<SUIT_ViewWindow*> it( wnds );
626 while ( it.hasNext() && (wnd = it.next()) )
628 SUIT_ViewManager* vman = wnd->getViewManager();
631 SUIT_ViewModel* vmodel = vman->getViewModel();
634 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
637 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
639 Redisplay( theIO, updateViewer, view );
648 //=================================================================
650 * GEOM_Displayer::Redisplay
651 * Redisplay (erase and then display again) interactive object
652 * in the specified view
654 //=================================================================
655 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
656 const bool theUpdateViewer,
657 SALOME_View* theViewFrame )
659 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
665 Erase( theIO, true, false, theViewFrame );
666 Display( theIO, theUpdateViewer, theViewFrame );
669 //=================================================================
671 * GEOM_Displayer::Display
672 * Calls Display() method for each object in the given list
674 //=================================================================
675 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
677 SALOME_ListIteratorOfListIO Iter( theIOList );
678 for ( ; Iter.More(); Iter.Next() ) {
679 Display( Iter.Value(), false );
685 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
687 SalomeApp_Study* aStudy = getStudy();
689 if ( v ) vId = getViewManagerId( v );
692 QString entry = p->GetEntry();
693 if ( !entry.isEmpty() ) {
695 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
696 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
701 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
706 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
708 // VSR: this method can be improved in future:
709 // to improve performance, the default values from resource manager should be cached in the displayer
710 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
713 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
715 // VSR: this method can be improved in future:
716 // to improve performance, the default values from resource manager should be cached in the displayer
717 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
720 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
722 // check that shape is not null
723 if ( AISShape.IsNull() ) return;
725 // check that study is active
726 SalomeApp_Study* study = getStudy();
727 if ( !study ) return;
729 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
730 !TopoDS_Iterator(myShape).More() )
731 return; // NPAL15983 (Bug when displaying empty groups)
733 // set interactive object
735 Handle( SALOME_InteractiveObject ) anIO;
737 if ( !myIO.IsNull() ) {
738 AISShape->setIO( myIO );
739 AISShape->SetOwner( myIO );
742 else if ( !myName.empty() ) {
743 // workaround to allow selection of temporary objects
744 static int tempId = 0;
745 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
746 AISShape->setIO( anIO );
747 AISShape->SetOwner( anIO );
750 // flag: only vertex or compound of vertices is processed (specific handling)
751 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
752 // presentation study entry (empty for temporary objects like preview)
753 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
754 // flag: temporary object
755 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
756 // currently active view window's ID (-1 if no active view)
757 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
759 // get presentation properties
760 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
762 // Temporary staff: vertex must be infinite for correct visualization
763 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
766 Material_Model material;
767 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
769 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
770 // - set front material properties
771 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
772 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
773 // - set back material properties
774 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
775 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
776 // - switch to default (both sides) facing mode
777 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
783 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
784 // we set it to the shape not taking into account material properties
785 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
787 else if ( !material.isPhysical() ) {
788 // shading color from properties is used only for non-physical materials
789 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
793 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
794 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
795 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
796 AISShape->Attributes()->SetLineAspect( anAspect );
798 // - unfree boundaries color
799 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
800 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
801 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
802 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
804 // - free boundaries color
805 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
806 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
807 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
808 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
810 // - standalone edges color
811 anAspect = AISShape->Attributes()->WireAspect();
812 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
813 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
814 AISShape->Attributes()->SetWireAspect( anAspect );
816 // - color for edges in shading+edges mode
817 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
820 AISShape->SetDisplayMode( HasDisplayMode() ?
821 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
823 // display mode from properties
824 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
826 // - face boundaries color
827 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
828 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
829 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
830 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
831 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
833 // set display vectors flag
834 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
836 // set display vertices flag
837 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
838 AISShape->SetDisplayVertices( isVerticesMode );
841 if( HasTransparency() ) {
842 AISShape->SetTransparency( GetTransparency() );
844 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
847 // set iso properties
848 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
849 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
850 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
851 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
852 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
853 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
854 uIsoAspect->SetColor( isosColor );
855 uIsoAspect->SetWidth( isosWidth );
856 uIsoAspect->SetNumber( uIsos );
857 vIsoAspect->SetColor( isosColor );
858 vIsoAspect->SetWidth( isosWidth );
859 vIsoAspect->SetNumber( vIsos );
860 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
861 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
863 // set deflection coefficient
864 // ... to avoid to small values of the coefficient, its lower value is limited
865 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
869 if ( HasTexture() ) {
870 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
871 aImagePath = GetTexture().c_str();
872 if ( ! entry.isEmpty() ) {
873 // check that study is active
874 SalomeApp_Study* study = getActiveStudy();
876 // Store the texture in object properties for next displays
877 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
878 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
880 // Update propeties map
881 propMap = getObjectProperties( study, entry, myViewFrame );
886 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
889 #ifdef USE_TEXTURED_SHAPE
890 Handle(Image_PixMap) aPixmap;
891 if ( !aImagePath.isEmpty() )
892 aPixmap = cacheTextureFor( aImagePath, AISShape );
894 aPixmap = getDefaultTexture();
896 // apply image to shape
897 if ( !aPixmap.IsNull() ) {
898 AISShape->SetTexturePixMap( aPixmap );
899 AISShape->SetTextureMapOn();
900 AISShape->DisableTextureModulate();
903 AISShape->SetTextureMapOff();
908 AISShape->SetWidth( HasWidth() ?
909 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
911 // libe width from properties
912 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
914 // set top-level flag
915 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
917 // set point marker (for vertex / compound of vertices only)
918 if ( onlyVertex || isVerticesMode ) {
919 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
920 if ( aList.size() == 2 ) {
921 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
922 int aTypeOfMarker = aList[0].toInt();
923 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
924 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
925 anAspect->SetScale( aScaleOfMarker );
926 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
927 anAspect->SetColor( HasColor() ?
928 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
929 (Quantity_NameOfColor)GetColor() :
930 // color from properties
931 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
932 AISShape->Attributes()->SetPointAspect( anAspect );
934 else if ( aList.size() == 1 ) {
935 // custom marker string contains "IdOfTexture"
936 int textureId = aList[0].toInt();
937 Standard_Integer aWidth, aHeight;
938 Handle(TColStd_HArray1OfByte) aTexture =
939 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
940 if ( !aTexture.IsNull() ) {
941 Handle(Prs3d_PointAspect) aTextureAspect =
942 new Prs3d_PointAspect( HasColor() ?
943 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
944 (Quantity_NameOfColor)GetColor() :
945 // color from properties
946 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
949 AISShape->Attributes()->SetPointAspect( aTextureAspect );
954 // set field step data
955 AISShape->setFieldStepInfo( myFieldDataType,
960 myFieldStepRangeMax );
962 if ( create && !isTemporary && aMgrId != -1 ) {
963 // set properties to the study
964 study->setObjectProperties( aMgrId, entry, propMap );
967 // AISShape->SetName(???); ??? necessary to set name ???
970 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
972 // check that actor is not null
973 if ( !actor ) return;
975 // check that study is active
976 SalomeApp_Study* study = getStudy();
977 if ( !study ) return;
979 // set interactive object
981 Handle( SALOME_InteractiveObject ) anIO;
983 if ( !myIO.IsNull() ) {
984 actor->setIO( myIO );
987 else if ( !myName.empty() ) {
988 // workaround to allow selection of temporary objects
989 static int tempId = 0;
990 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
991 actor->setIO( anIO );
994 // presentation study entry (empty for temporary objects like preview)
995 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
996 // flag: temporary object
997 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
998 // currently active view window's ID (-1 if no active view)
999 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1001 // get presentation properties
1002 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1005 /////////////////////////////////////////////////////////////////////////
1006 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1007 // due to performance problem
1008 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1009 /////////////////////////////////////////////////////////////////////////
1010 if ( !actor->getTopo().IsSame( myShape ) )
1011 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1014 Material_Model material;
1015 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1016 std::vector<vtkProperty*> mprops;
1017 mprops.push_back( material.getMaterialVTKProperty( true ) );
1018 mprops.push_back( material.getMaterialVTKProperty( false) );
1019 actor->SetMaterial( mprops );
1021 // set iso-lines properties
1023 // - set number of iso-lines
1024 int nbIsos[2]= { 1, 1 };
1025 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1026 nbIsos[0] = isos[0].toInt();
1027 nbIsos[1] = isos[1].toInt();
1028 actor->SetNbIsos( nbIsos );
1030 // - set iso-lines width
1031 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1033 // - set iso-lines color
1034 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1035 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1040 // - same color for all sub-actors
1041 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1042 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1045 // shading color (for non-physical materials)
1046 if ( !material.isPhysical() ) {
1047 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1048 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1049 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1052 // - standalone edge color
1053 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1054 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1056 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1057 // - shared edges color ???
1058 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1060 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1061 // - free edges color ???
1062 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1065 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1066 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1069 // - color for edges in shading+edges mode
1070 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1071 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1074 if( HasTransparency() ) {
1075 actor->SetOpacity( 1.0 - GetTransparency() );
1077 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1081 actor->SetWidth( HasWidth() ?
1082 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1084 // libe width from properties
1085 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1087 // set display vectors flag
1088 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1090 // set display vertices flag
1091 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1094 int displayMode = HasDisplayMode() ?
1095 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1097 // display mode from properties
1098 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1100 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1101 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1102 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1103 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1105 if ( displayMode == 2 )
1106 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1107 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1109 actor->setDisplayMode( displayMode );
1112 actor->PickableOn();
1114 actor->PickableOff();
1116 if ( create && !isTemporary && aMgrId != -1 ) {
1117 // set properties to the study
1118 study->setObjectProperties( aMgrId, entry, propMap );
1122 //=================================================================
1124 * GEOM_Displayer::updateDimensions
1125 * Creates or renews dimension presentation for the IO.
1127 //=================================================================
1128 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1129 SALOME_OCCPrs* thePrs,
1130 const gp_Ax3& theShapeLCS )
1132 SalomeApp_Study* aStudy = getStudy();
1138 if ( theIO.IsNull() )
1143 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1145 AIS_ListOfInteractive aListOfIO;
1147 anOccPrs->GetObjects( aListOfIO );
1149 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1151 // remove outdated presentations of dimensions
1152 for ( ; aIterateIO.More(); aIterateIO.Next() )
1154 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1155 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1160 aListOfIO.Remove( aIterateIO );
1162 if ( !aIterateIO.More() )
1168 // prepare dimension styling
1169 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1171 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1172 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1173 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1174 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1175 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1176 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1177 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1179 // restore dimension presentation from saved attribute or property data
1180 AIS_ListOfInteractive aRestoredDimensions;
1182 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1184 GEOM::propertyName( GEOM::Dimensions ),
1187 GEOMGUI_DimensionProperty aRecords;
1189 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1191 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1195 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1198 // create up-to-date dimension presentations
1199 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1201 if ( !aRecords.IsVisible( aPrsIt ) )
1206 // init dimension by type
1207 Handle(AIS_Dimension) aPrs;
1208 switch( aRecords.GetType( aPrsIt ) )
1210 case GEOMGUI_DimensionProperty::DimensionType_Length :
1212 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1213 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1218 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1220 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1221 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1226 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1228 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1229 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1235 aPrs->SetOwner( theIO );
1237 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1239 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1241 aStyle->SetCommonColor( aColor );
1242 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1243 aStyle->MakeText3d( Standard_True );
1244 aStyle->MakeTextShaded( Standard_True );
1245 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1246 aStyle->TextAspect()->SetHeight( aFontHeight );
1247 aStyle->ArrowAspect()->SetLength( anArrowLength );
1248 aStyle->LineAspect()->SetWidth( aLineWidth );
1249 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1250 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1251 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1252 aPrs->SetDimensionAspect( aStyle );
1253 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1254 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1255 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1257 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1259 // show degree symbol for dimension instead of label "deg"
1260 if ( aUnitsAngle == "deg" )
1262 aPrs->SetSpecialSymbol(0xB0);
1263 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1264 aStyle->MakeUnitsDisplayed(Standard_False);
1268 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1269 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1274 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1277 aListOfIO.Append( aPrs );
1280 // update presentation
1283 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1285 anOccPrs->AddObject( aIterateIO.Value() );
1289 //=================================================================
1291 * GEOM_Displayer::Erase
1292 * Calls Erase() method for each object in the given list
1294 //=================================================================
1295 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1297 const bool updateViewer )
1299 SALOME_ListIteratorOfListIO Iter( theIOList );
1300 for ( ; Iter.More(); Iter.Next() )
1301 Erase( Iter.Value(), forced, false );
1307 //=================================================================
1309 * GEOM_Displayer::Redisplay
1310 * Calls Redisplay() method for each object in the given list
1312 //=================================================================
1313 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1314 const bool updateViewer,
1315 const bool checkActiveViewer )
1317 SALOME_ListIteratorOfListIO Iter( theIOList );
1318 for ( ; Iter.More(); Iter.Next() )
1319 Redisplay( Iter.Value(), false, checkActiveViewer );
1325 //=================================================================
1327 * GEOM_Displayer::Redisplay
1328 * Calls Redisplay() method for each object in the given list
1330 //=================================================================
1331 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1332 const bool theUpdateViewer,
1333 SALOME_View* theViewFrame )
1335 SALOME_ListIteratorOfListIO anIter( theIOList );
1336 for ( ; anIter.More(); anIter.Next() )
1338 Redisplay( anIter.Value(), false, theViewFrame );
1341 if ( theUpdateViewer )
1347 //=================================================================
1349 * GEOM_Displayer::Update
1350 * Update OCC presentaion
1351 * [ Reimplemented from SALOME_Displayer ]
1353 //=================================================================
1354 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1356 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1357 SalomeApp_Study* study = getStudy();
1359 if ( !occPrs || myShape.IsNull() || !study )
1362 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1365 // specific processing for local coordinate system presentation
1368 TopoDS_Face aFace = TopoDS::Face( myShape );
1369 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1370 if ( !aPlane.IsNull() )
1372 gp_Ax3 aPos = aPlane->Pln().Position();
1373 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1375 Handle(GEOM_AISTrihedron) aTrh;
1377 if ( occPrs->IsNull() )
1379 // new presentation is being created
1380 aTrh = new GEOM_AISTrihedron( aPlc );
1381 occPrs->AddObject( aTrh );
1385 // presentation is being updated
1386 AIS_ListOfInteractive aList;
1387 occPrs->GetObjects( aList );
1388 AIS_ListIteratorOfListOfInteractive anIter( aList );
1389 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1390 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1394 if ( !aTrh.IsNull() ) {
1395 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1397 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1398 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1400 aTrh->SetWidth( GetWidth() );
1402 if ( !myIO.IsNull() )
1404 aTrh->setIO( myIO );
1405 aTrh->SetOwner( myIO );
1407 aTrh->SetComponent( aPlc );
1408 aTrh->SetToUpdate();
1410 occPrs->SetToActivate( ToActivate() );
1416 // processing for usual geometry presentation
1419 // if presentation is empty we try to create new one
1420 if ( occPrs->IsNull() )
1422 // create presentation (specific for vectors)
1423 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1424 : new GEOM_AISShape ( myShape, "" );
1426 if( myType == GEOM_FIELD_STEP )
1427 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1428 // update shape properties
1429 updateShapeProperties( AISShape, true );
1431 // add shape to the presentation
1432 occPrs->AddObject( AISShape );
1434 // In accordance with ToActivate() value object will be activated/deactivated
1435 // when it will be displayed
1436 occPrs->SetToActivate( ToActivate() );
1438 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1439 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1441 // create additional wireframe shape
1442 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1443 aWirePrs->SetWidth(AISShape->Width());
1444 if ( !myIO.IsNull() ) {
1445 aWirePrs->setIO( myIO );
1446 aWirePrs->SetOwner( myIO );
1449 // add shape to the presentation
1450 occPrs->AddObject( aWirePrs );
1453 // if presentation is found -> set again shape for it
1456 AIS_ListOfInteractive IOList;
1457 occPrs->GetObjects( IOList );
1458 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1459 for ( ; Iter.More(); Iter.Next() )
1461 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1462 if ( AISShape.IsNull() )
1465 // re-set shape (it might be changed)
1466 if ( AISShape->Shape() != myShape )
1467 AISShape->Set( myShape );
1469 // update shape properties
1470 updateShapeProperties( AISShape, false );
1473 AISShape->UpdateSelection();
1474 AISShape->SetToUpdate();
1478 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1482 //=================================================================
1484 * GEOM_Displayer::Update
1485 * Update VTK presentaion
1486 * [ Reimplemented from SALOME_Displayer ]
1488 //=================================================================
1489 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1491 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1492 SalomeApp_Study* study = getStudy();
1494 if ( !vtkPrs || myShape.IsNull() || !study )
1497 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1500 // specific processing for local coordinate system presentation
1503 TopoDS_Face aFace = TopoDS::Face( myShape );
1504 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1505 if ( !aPlane.IsNull() ) {
1506 gp_Ax3 aPos = aPlane->Pln().Position();
1507 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1509 GEOM_VTKTrihedron* aTrh = 0;
1511 if ( vtkPrs->IsNull() ) {
1512 // new presentation is being created
1513 aTrh = GEOM_VTKTrihedron::New();
1514 vtkPrs->AddObject( aTrh );
1517 // presentation is being updated
1518 vtkActorCollection* actors = vtkPrs->GetObjects();
1520 actors->InitTraversal();
1521 vtkActor* a = actors->GetNextActor();
1522 while ( a && !aTrh ) {
1523 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1524 a = actors->GetNextActor();
1530 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1532 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1533 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1535 #ifdef VTK_TRIHEDRON_WIDTH
1537 // VSR: currently isn't supported
1539 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1541 aTrh->SetWidth( GetWidth() );
1544 if ( !myIO.IsNull() )
1545 aTrh->setIO( myIO );
1547 aTrh->SetPlacement( aPlc );
1554 // processing for usual geometry presentation
1557 // if presentation is empty we try to create new one
1558 if ( vtkPrs->IsNull() )
1561 GEOM_Actor* actor = GEOM_Actor::New();
1562 // update actor properties
1563 updateActorProperties( actor, true );
1564 // add actor to the presentation
1565 vtkPrs->AddObject( actor );
1568 // presentation is being updated
1569 vtkActorCollection* actors = vtkPrs->GetObjects();
1571 actors->InitTraversal();
1572 vtkActor* a = actors->GetNextActor();
1574 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1576 // update actor properties
1577 updateActorProperties( actor, false );
1578 a = actors->GetNextActor();
1586 //=================================================================
1588 * GEOM_Displayer::BuildPrs
1589 * Build presentation accordint to the current viewer type
1591 //=================================================================
1592 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1594 if ( theObj->_is_nil() )
1597 myViewFrame = GetActiveView();
1598 if ( myViewFrame == 0 )
1601 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1606 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1607 myType = theObj->GetType();
1609 // Update presentation
1615 //=================================================================
1617 * GEOM_Displayer::BuildPrs
1618 * Build presentation accordint to the current viewer type
1620 //=================================================================
1621 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1623 myViewFrame = GetActiveView();
1624 if ( theShape.IsNull() || myViewFrame == 0 )
1627 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1632 setShape( theShape );
1640 //=================================================================
1642 * GEOM_Displayer::buildPresentation
1643 * Builds/finds object's presentation for the current viewer
1644 * Calls corresponding Update() method by means of double dispatch
1647 //=================================================================
1648 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1649 SALOME_View* theViewFrame )
1651 SALOME_Prs* prs = 0;
1654 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1658 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1661 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1662 theIO->setEntry( entry.toLatin1().constData() );
1663 if ( !theIO.IsNull() )
1665 // set interactive object
1667 // Find SOBject (because shape should be published previously)
1668 SUIT_Session* session = SUIT_Session::session();
1669 SUIT_Application* app = session->activeApplication();
1672 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1675 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1678 // get CORBA reference to data object
1679 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1680 if ( !CORBA::is_nil( object ) )
1682 // downcast to GEOM base object
1683 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1684 if ( !GeomBaseObject->_is_nil() )
1686 myType = GeomBaseObject->GetType();
1688 // downcast to GEOM object
1689 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1690 if ( myType == GEOM_FIELD_STEP )
1692 // get the GEOM object from the field's shape
1693 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1694 if ( !GeomFieldStep->_is_nil() )
1696 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1697 if ( !GeomField->_is_nil() )
1698 GeomObject = GeomField->GetShape();
1701 // read the field step information
1702 readFieldStepInfo( GeomFieldStep );
1705 if ( !GeomObject->_is_nil() )
1707 // finally set shape
1708 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1716 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1722 //=================================================================
1724 * GEOM_Displayer::buildSubshapePresentation
1725 * Builds/finds object's presentation for the current viewer
1726 * Calls corresponding Update() method by means of double dispatch
1727 * For not published objects (for Mantis issue 0020435)
1729 //=================================================================
1730 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1731 const QString& entry,
1732 SALOME_View* theViewFrame)
1734 SALOME_Prs* prs = 0;
1737 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1741 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1744 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1745 theIO->setEntry(entry.toLatin1().constData());
1746 if (!theIO.IsNull())
1748 // set interactive object
1750 // finally set shape
1752 myType = GEOM_SUBSHAPE;
1754 UpdatePrs(prs); // Update presentation by using of the double dispatch
1760 //=================================================================
1762 * GEOM_Displayer::internalReset
1763 * Resets internal data
1766 //=================================================================
1767 void GEOM_Displayer::internalReset()
1772 myFieldDataType = GEOM::FDT_Double;
1773 myFieldDimension = 0;
1774 myFieldStepData.clear();
1775 myFieldStepName.Clear();
1776 myFieldStepRangeMin = 0;
1777 myFieldStepRangeMax = 0;
1780 //=================================================================
1782 * GEOM_Displayer::LocalSelection
1783 * Activate selection of CAD shapes with activisation of selection
1784 * of their sub-shapes (with opened local context for OCC viewer)
1786 //=================================================================
1787 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1789 SUIT_Session* session = SUIT_Session::session();
1790 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1794 LightApp_SelectionMgr* sm = app->selectionMgr();
1796 // remove all filters from selection
1799 SALOME_View* vf = GetActiveView();
1801 if (!theIO.IsNull() && !vf->isVisible(theIO))
1803 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1804 vf->LocalSelection( prs, theMode );
1805 delete prs; // delete presentation because displayer is its owner
1809 //=================================================================
1811 * GEOM_Displayer::globalSelection
1812 * Activate selection of CAD shapes without activisation of selection
1813 * of their sub-shapes (without opened local context for OCC viewer)
1815 //=================================================================
1816 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1818 TColStd_MapOfInteger aModes;
1819 aModes.Add( theMode );
1820 GlobalSelection( aModes, update );
1823 //=================================================================
1825 * GEOM_Displayer::globalSelection
1826 * Activate selection of CAD shapes without activisation of selection
1827 * of their sub-shapes (without opened local context for OCC viewer)
1829 //=================================================================
1830 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1831 const bool update, const QList<int>* theSubShapes )
1833 SUIT_Session* session = SUIT_Session::session();
1834 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1838 SALOME_View* vf = GetActiveView();
1842 // Close local context
1843 vf->GlobalSelection( update );
1845 // Set selection filters in accordance with current mode
1846 LightApp_SelectionMgr* sm = app->selectionMgr();
1850 // Remove from selection temporary objects if necessary
1851 if ( !theModes.Contains( GEOM_PREVIEW ) )
1852 clearTemporary( sm );
1854 //@ aSel->ClearIndex();
1858 // Remove filters from AIS_InteractiveContext
1859 Handle(AIS_InteractiveContext) ic;
1860 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1863 ic = viewer->getAISContext();
1865 ic->RemoveFilters();
1868 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1871 SUIT_SelectionFilter* aFilter;
1872 if ( theModes.Extent() == 1 )
1874 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1876 if ( aMode == GEOM_COMPOUNDFILTER )
1877 aFilter = getComplexFilter( theSubShapes );
1879 aFilter = getFilter( aMode );
1881 else if ( theModes.Extent() > 1 )
1883 TColStd_MapOfInteger aTopAbsModes;
1884 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1885 QList<SUIT_SelectionFilter*> aListOfFilters;
1886 for ( ; anIter.More(); anIter.Next() )
1888 SUIT_SelectionFilter* aFilter;
1889 int aMode = anIter.Key();
1890 if ( aMode == GEOM_COMPOUNDFILTER )
1891 aFilter = getComplexFilter( theSubShapes );
1893 aFilter = getFilter( aMode );
1896 aListOfFilters.append( aFilter );
1899 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1906 sm->installFilter( aFilter );
1909 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1910 ic->AddFilter( anOCCFilter );
1915 //=================================================================
1917 * GEOM_Displayer::LocalSelection
1918 * Activate selection of CAD shapes with activisation of selection
1919 * of their sub-shapes (with opened local context for OCC viewer)
1921 //=================================================================
1922 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1924 SALOME_ListIteratorOfListIO Iter( theIOList );
1925 for ( ; Iter.More(); Iter.Next() )
1926 LocalSelection( Iter.Value(), theMode );
1929 //=================================================================
1931 * GEOM_Displayer::BeforeDisplay
1932 * Called before displaying of pars. Close local context
1933 * [ Reimplemented from SALOME_Displayer ]
1935 //=================================================================
1936 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1938 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1941 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1944 if ( ic->HasOpenedContext() )
1945 ic->CloseAllContexts();
1950 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1952 UpdateColorScale(false,false);
1955 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1957 LightApp_Displayer::BeforeErase( v, p );
1958 releaseTextures( p );
1961 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1963 LightApp_Displayer::AfterErase( v, p );
1964 UpdateColorScale(false,false);
1967 //=================================================================
1969 * GEOM_Displayer::SetColor
1970 * Set color for shape displaying. If it is equal -1 then default color is used.
1971 * Available values are from Quantity_NameOfColor enumeration
1973 //=================================================================
1974 void GEOM_Displayer::SetColor( const int color )
1981 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1985 int GEOM_Displayer::GetColor() const
1990 bool GEOM_Displayer::HasColor() const
1992 return myColor != -1;
1995 void GEOM_Displayer::UnsetColor()
1999 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2000 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2001 myShadingColor = SalomeApp_Tools::color( col );
2004 //=================================================================
2006 * GEOM_Displayer::SetTransparency
2007 * Set transparency for shape displaying.
2009 //=================================================================
2010 double GEOM_Displayer::SetTransparency( const double transparency )
2012 double aPrevTransparency = myTransparency;
2013 if ( transparency < 0 ) {
2014 UnsetTransparency();
2017 myTransparency = transparency;
2018 myHasTransparency = true;
2020 return aPrevTransparency;
2023 //=================================================================
2025 * GEOM_Displayer::GetTransparency
2026 * Get transparency for shape displaying.
2028 //=================================================================
2029 double GEOM_Displayer::GetTransparency() const
2031 return myTransparency;
2034 //=================================================================
2036 * GEOM_Displayer::HasTransparency
2037 * Check if transparency for shape displaying is set.
2039 //=================================================================
2040 bool GEOM_Displayer::HasTransparency() const
2042 return myHasTransparency;
2045 //=================================================================
2047 * GEOM_Displayer::UnsetTransparency
2048 * Unset transparency for shape displaying.
2050 //=================================================================
2051 double GEOM_Displayer::UnsetTransparency()
2053 double aPrevTransparency = myTransparency;
2054 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2055 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
2056 myHasTransparency = false;
2057 return aPrevTransparency;
2061 //=================================================================
2063 * GEOM_Displayer::SetTexture
2064 * Set color for shape displaying. If it is equal -1 then default color is used.
2065 * Available values are from Quantity_NameOfColor enumeration
2067 //=================================================================
2068 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2070 if(texureFileName!="")
2072 myTexture = texureFileName;
2076 bool GEOM_Displayer::HasTexture() const
2078 return myTexture != "";
2081 std::string GEOM_Displayer::GetTexture() const
2086 //=================================================================
2088 * GEOM_Displayer::SetWidth
2089 * Set width of shape displaying. If it is equal -1 then default width is used.
2091 //=================================================================
2092 void GEOM_Displayer::SetWidth( const double width )
2097 double GEOM_Displayer::GetWidth() const
2102 bool GEOM_Displayer::HasWidth() const
2104 return myWidth != -1;
2107 void GEOM_Displayer::UnsetWidth()
2113 int GEOM_Displayer::GetIsosWidth() const
2118 void GEOM_Displayer::SetIsosWidth(const int width)
2120 myIsosWidth = width;
2123 bool GEOM_Displayer::HasIsosWidth() const
2125 return myIsosWidth != -1;
2129 //=================================================================
2131 * GEOM_Displayer::SetToActivate
2132 * This method is used for activisation/deactivisation of objects to be displayed
2134 //=================================================================
2135 void GEOM_Displayer::SetToActivate( const bool toActivate )
2137 myToActivate = toActivate;
2139 bool GEOM_Displayer::ToActivate() const
2141 return myToActivate;
2144 //=================================================================
2146 * GEOM_Displayer::clearTemporary
2147 * Removes from selection temporary objects
2149 //=================================================================
2150 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2152 SALOME_ListIO selected, toSelect;
2153 theSelMgr->selectedObjects( selected );
2155 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2156 Handle(SALOME_InteractiveObject) io = it.Value();
2157 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2158 toSelect.Append( it.Value() );
2161 theSelMgr->setSelectedObjects( toSelect, true );
2164 void GEOM_Displayer::SetName( const char* theName )
2169 void GEOM_Displayer::UnsetName()
2174 SalomeApp_Study* GEOM_Displayer::getStudy() const
2176 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2179 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2184 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2189 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2190 const int theFieldDimension,
2191 const QList<QVariant>& theFieldStepData,
2192 const TCollection_AsciiString& theFieldStepName,
2193 const double theFieldStepRangeMin,
2194 const double theFieldStepRangeMax )
2196 myFieldDataType = theFieldDataType;
2197 myFieldDimension = theFieldDimension;
2198 myFieldStepData = theFieldStepData;
2199 myFieldStepName = theFieldStepName;
2200 myFieldStepRangeMin = theFieldStepRangeMin;
2201 myFieldStepRangeMax = theFieldStepRangeMax;
2204 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2206 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2207 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2208 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2209 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2210 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2211 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2214 int GEOM_Displayer::SetDisplayMode( const int theMode )
2216 int aPrevMode = myDisplayMode;
2217 if ( theMode != -1 ) {
2218 myDisplayMode = theMode;
2219 myHasDisplayMode = true;
2227 int GEOM_Displayer::GetDisplayMode() const
2229 return myDisplayMode;
2232 int GEOM_Displayer::UnsetDisplayMode()
2234 int aPrevMode = myDisplayMode;
2235 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2236 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2237 myHasDisplayMode = false;
2241 bool GEOM_Displayer::HasDisplayMode() const
2243 return myHasDisplayMode;
2246 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2248 static QList<QColor> colors;
2250 if ( colors.isEmpty() ) {
2252 for (int s = 0; s < 2 ; s++)
2254 for (int v = 100; v >= 40; v = v - 20)
2256 for (int h = 0; h < 359 ; h = h + 60)
2258 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2264 static int currentColor = 0;
2266 SALOMEDS::Color color;
2267 color.R = (double)colors[currentColor].red() / 255.0;
2268 color.G = (double)colors[currentColor].green() / 255.0;
2269 color.B = (double)colors[currentColor].blue() / 255.0;
2271 currentColor = (currentColor+1) % colors.count();
2276 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2279 int aTolerance = 64;
2280 int anIterations = 0;
2286 if( anIterations % aPeriod == 0 )
2289 if( aTolerance < 1 )
2292 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2294 aHue = (int)( 360.0 * rand() / RAND_MAX );
2295 //std::cout << "Hue = " << aHue << std::endl;
2297 //std::cout << "Auto colors : ";
2299 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2300 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2301 for( ; it != itEnd; ++it )
2303 SALOMEDS::Color anAutoColor = *it;
2304 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2307 aQColor.getHsv( &h, &s, &v );
2308 //std::cout << h << " ";
2309 if( abs( h - aHue ) < aTolerance )
2312 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2316 //std::cout << std::endl;
2322 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2324 aColor.setHsv( aHue, 255, 255 );
2326 SALOMEDS::Color aSColor;
2327 aSColor.R = (double)aColor.red() / 255.0;
2328 aSColor.G = (double)aColor.green() / 255.0;
2329 aSColor.B = (double)aColor.blue() / 255.0;
2334 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2335 const QString& entry,
2338 // get default properties for the explicitly specified default view type
2339 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2341 if ( study && view ) {
2342 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2343 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2344 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2346 if ( viewModel && viewId != -1 ) {
2347 // get properties from the study
2348 PropMap storedMap = study->getObjectProperties( viewId, entry );
2349 // overwrite default properties from stored ones (that are specified)
2350 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2351 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2352 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2353 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2355 // ... specific processing for color
2356 // ... current implementation is to use same stored color for all aspects
2357 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2358 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2359 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2360 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2361 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2362 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2363 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2366 if ( !entry.isEmpty() ) {
2367 // get CORBA reference to geom object
2368 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2370 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2371 if ( !CORBA::is_nil( object ) ) {
2372 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2373 if ( !CORBA::is_nil( geomObject ) ) { // to check
2374 // check that geom object has color properly set
2375 bool hasColor = false;
2376 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2377 // set color from geometry object (only once, if it is not yet set in GUI)
2378 // current implementation is to use same color for all aspects
2379 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2380 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2381 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2382 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2383 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2384 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2385 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2386 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2388 // check that object has point marker properly set
2389 GEOM::marker_type mType = geomObject->GetMarkerType();
2390 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2391 int mTextureId = geomObject->GetMarkerTexture();
2392 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2393 ( mType == GEOM::MT_USER && mTextureId > 0 );
2394 // set point marker from geometry object (only once, if it is not yet set in GUI)
2395 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2396 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2398 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2399 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2401 else if ( mType == GEOM::MT_USER ) {
2403 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2415 PropMap GEOM_Displayer::getDefaultPropertyMap()
2419 // get resource manager
2420 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2422 // fill in the properties map with default values
2424 // - visibility (false by default)
2425 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2427 // - nb isos (take default value from preferences)
2428 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2429 QString( "%1%2%3" ).
2430 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2431 arg( GEOM::subSectionSeparator() ).
2432 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2434 // - transparency (opacity = 1-transparency)
2435 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2436 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2438 // - display mode (take default value from preferences)
2439 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2440 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2442 // - show edges direction flag (false by default)
2443 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2445 // - show vertices flag (false by default)
2446 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2448 // - shading color (take default value from preferences)
2449 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2450 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2452 // - wireframe color (take default value from preferences)
2453 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2454 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2456 // - standalone edges color (take default value from preferences)
2457 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2458 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2460 // - free boundaries color (take default value from preferences)
2461 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2462 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2464 // - points color (take default value from preferences)
2465 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2466 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2468 // - isos color (take default value from preferences)
2469 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2470 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2472 // - outlines color (take default value from preferences)
2473 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2474 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2476 // - deflection coefficient (take default value from preferences)
2477 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2478 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2480 // - material (take default value from preferences)
2481 Material_Model material;
2482 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2483 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2485 // - edge width (take default value from preferences)
2486 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2487 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2489 // - isos width (take default value from preferences)
2490 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2491 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2493 // - point marker (take default value from preferences)
2494 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2495 QString( "%1%2%3" ).
2496 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2497 arg( GEOM::subSectionSeparator() ).
2498 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2500 // - top-level flag (false by default)
2501 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2506 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2507 SALOMEDS::Color aSColor;
2510 SUIT_Session* session = SUIT_Session::session();
2511 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2513 if ( app && !theGeomObject->_is_nil()) {
2514 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2517 _PTR(Study) aStudy = study->studyDS();
2518 aSColor = theGeomObject->GetColor();
2519 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2521 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2522 bool general_autocolor = true;
2523 #else // auto-color for groups only
2524 bool general_autocolor = false;
2525 #endif // GENERAL_AUTOCOLOR
2526 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2527 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2528 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2529 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2530 aSColor = getPredefinedUniqueColor();
2532 #else // old algorithm for auto-colors
2533 QList<SALOMEDS::Color> aReservedColors;
2534 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2535 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2536 if ( aMainSObject ) {
2537 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2538 for ( ; it->More(); it->Next() ) {
2539 _PTR(SObject) aChildSObject( it->Value() );
2540 GEOM::GEOM_Object_var aChildObject =
2541 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2542 if ( CORBA::is_nil( aChildObject ) )
2545 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2546 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2547 aReservedColors.append( aReservedColor );
2550 aSColor = getUniqueColor( aReservedColors );
2552 #endif // SIMPLE_AUTOCOLOR
2562 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2563 const bool eraseOnlyChildren) {
2564 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2568 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2572 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2577 // Erase from all views
2578 QList<SALOME_View*> views;
2580 ViewManagerList vmans = app->viewManagers();
2581 SUIT_ViewManager* vman;
2582 foreach ( vman, vmans ) {
2583 SUIT_ViewModel* vmod = vman->getViewModel();
2584 view = dynamic_cast<SALOME_View*> ( vmod );
2586 views.append( view );
2589 if( views.count() == 0 )
2592 //Erase childrens w/o update views
2593 DataObjectList listObj = parent->children( true );
2594 SUIT_DataObject* obj;
2595 foreach( obj, listObj ) {
2596 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2598 foreach ( view, views ) {
2599 Handle(SALOME_InteractiveObject) anIO =
2600 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2601 Erase(anIO, false, false, view);
2605 //Erase parent with view update or repaint views
2606 foreach ( view, views ) {
2607 if(!eraseOnlyChildren)
2608 Erase(theIO, false, true, view);
2614 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2616 if( theGeomFieldStep->_is_nil() )
2619 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2620 if( aGeomField->_is_nil() )
2623 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2624 if( aGeomFieldShape->_is_nil() )
2627 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2628 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2629 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2631 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2633 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2635 int aFieldDimension = aGeomField->GetDimension();
2637 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2638 int aFieldNbComponents = aFieldComponents->length();
2640 QList<QVariant> aFieldStepData;
2641 if( aFieldDataType == GEOM::FDT_Bool )
2643 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2644 if ( !aGeomBoolFieldStep->_is_nil() )
2646 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2647 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2648 aFieldStepData << (bool)aValues[i];
2651 else if( aFieldDataType == GEOM::FDT_Int )
2653 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2654 if ( !aGeomIntFieldStep->_is_nil() )
2656 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2657 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2658 aFieldStepData << (qlonglong)aValues[i];
2661 else if( aFieldDataType == GEOM::FDT_Double )
2663 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2664 if ( !aGeomDoubleFieldStep->_is_nil() )
2666 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2667 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2668 aFieldStepData << (double)aValues[i];
2671 else if( aFieldDataType == GEOM::FDT_String )
2673 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2674 if ( !aGeomStringFieldStep->_is_nil() )
2676 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2677 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2678 aFieldStepData << QString( aValues[i] );
2682 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2683 aFieldStepData = groupFieldData( aFieldStepData,
2685 aFieldDataType == GEOM::FDT_String,
2687 aFieldStepRangeMax );
2689 setFieldStepInfo( aFieldDataType,
2694 aFieldStepRangeMax );
2697 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2698 const int theFieldNbComponents,
2699 const bool theIsString,
2700 double& theFieldStepRangeMin,
2701 double& theFieldStepRangeMax )
2703 QList<QVariant> aResultList;
2704 theFieldStepRangeMin = 0;
2705 theFieldStepRangeMax = 0;
2707 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2710 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2712 QList<QVariant> aGroupedList;
2714 bool anIsBoolean = false;
2715 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2718 QStringList aStringList;
2720 int aBaseIndex = aSubShape * theFieldNbComponents;
2721 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2723 int anIndex = aComponent + aBaseIndex;
2725 const QVariant& aVariant = theFieldStepData[ anIndex ];
2728 if( aVariant.type() == QVariant::String )
2729 aStringList << aVariant.toString();
2734 if( aVariant.type() == QVariant::Bool )
2736 aValue = aVariant.toBool() ? 1.0 : 0.0;
2742 if( aVariant.type() == QVariant::LongLong )
2743 aValue = double( aVariant.toLongLong() );
2744 else if( aVariant.type() == QVariant::Double )
2745 aValue = aVariant.toDouble();
2746 aNorm += aValue * aValue;
2752 aGroupedList << aStringList.join( "\n" );
2756 aNorm /= theFieldNbComponents;
2758 aNorm = pow( aNorm, 0.5 );
2760 if( aGroupedList.isEmpty() )
2761 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2764 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2765 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2768 aGroupedList << aNorm;
2774 theFieldStepRangeMin = 0.0;
2775 theFieldStepRangeMax = 1.0;
2778 SUIT_Session* session = SUIT_Session::session();
2779 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2780 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2782 QListIterator<QVariant> anIter( aGroupedList );
2783 while( anIter.hasNext() )
2785 const QVariant& aVariant = anIter.next();
2787 aResultList << aVariant;
2791 Quantity_Color aColor;
2792 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2793 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2794 aResultList << aQColor;
2800 // Note: the method is copied from Aspect_ColorScale class
2801 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2802 const Standard_Integer aMin,
2803 const Standard_Integer aMax )
2805 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2807 Standard_Integer aHue = maxLimit;
2809 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2811 aHue = Min( Max( minLimit, aHue ), maxLimit );
2816 // Note: the method is copied from Aspect_ColorScale class
2817 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2818 const Standard_Real aMin,
2819 const Standard_Real aMax,
2820 const Standard_Integer ColorsCount,
2821 Quantity_Color& aColor )
2823 if( aValue<aMin || aValue>aMax || aMax<aMin )
2824 return Standard_False;
2828 Standard_Real IntervNumber = 0;
2831 else if( aValue>aMax )
2832 IntervNumber = ColorsCount-1;
2833 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2834 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2836 Standard_Integer Interv = Standard_Integer( IntervNumber );
2838 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2840 return Standard_True;
2844 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2846 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2850 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2854 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2855 if( aViewer.IsNull() )
2858 aViewer->InitActiveViews();
2859 if( !aViewer->MoreActiveViews() )
2862 Handle(V3d_View) aView = aViewer->ActiveView();
2863 if( aView.IsNull() )
2866 Standard_Boolean anIsDisplayColorScale = Standard_False;
2867 TCollection_AsciiString aColorScaleTitle;
2868 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2869 Standard_Boolean anIsBoolean = Standard_False;
2871 SALOME_ListIO aSelectedObjects;
2872 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2873 if( aSelectedObjects.Extent() == 1 )
2875 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2876 if( !anIO.IsNull() )
2878 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2881 AIS_ListOfInteractive aList;
2882 aPrs->GetObjects( aList );
2883 AIS_ListIteratorOfListOfInteractive anIter( aList );
2884 for( ; anIter.More(); anIter.Next() )
2886 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2887 if( !aShape.IsNull() )
2889 GEOM::field_data_type aFieldDataType;
2890 int aFieldDimension;
2891 QList<QVariant> aFieldStepData;
2892 TCollection_AsciiString aFieldStepName;
2893 double aFieldStepRangeMin, aFieldStepRangeMax;
2894 aShape->getFieldStepInfo( aFieldDataType,
2899 aFieldStepRangeMax );
2900 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2902 anIsDisplayColorScale = Standard_True;
2903 aColorScaleTitle = aFieldStepName;
2904 aColorScaleMin = aFieldStepRangeMin;
2905 aColorScaleMax = aFieldStepRangeMax;
2906 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2914 if( anIsDisplayColorScale )
2916 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2917 if( !aColorScale.IsNull() )
2919 SUIT_Session* session = SUIT_Session::session();
2920 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2922 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2923 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2924 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2925 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2926 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2927 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2929 aColorScale->SetXPosition( anXPos );
2930 aColorScale->SetYPosition( anYPos );
2931 aColorScale->SetWidth( aWidth );
2932 aColorScale->SetHeight( aHeight );
2934 aColorScale->SetTextHeight( aTextHeight );
2935 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2937 aColorScale->SetTitle( aColorScaleTitle );
2938 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2940 if( !aView->ColorScaleIsDisplayed() )
2941 aView->ColorScaleDisplay();
2945 if( aView->ColorScaleIsDisplayed() )
2946 aView->ColorScaleErase();
2949 if( theIsRedisplayFieldSteps )
2951 _PTR(Study) aStudyDS = aStudy->studyDS();
2952 QList<SUIT_ViewManager*> vmList;
2953 myApp->viewManagers( vmList );
2954 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2956 if( SUIT_ViewManager* aViewManager = *vmIt )
2958 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
2959 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2961 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2964 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2965 if( !CORBA::is_nil( anObject ) )
2967 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2968 if( !aFieldStep->_is_nil() )
2970 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2971 Handle(SALOME_InteractiveObject) aStepIO =
2972 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2973 Redisplay( aStepIO, false, false );