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_ListIteratorOfListIO.hxx>
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
73 #include <SOCC_ViewModel.h>
76 #include <SVTK_ViewModel.h>
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
80 #include <OCCViewer_Utilities.h>
83 #include <AIS_Drawer.hxx>
84 #include <AIS_Dimension.hxx>
85 #include <AIS_LengthDimension.hxx>
86 #include <AIS_DiameterDimension.hxx>
87 #include <AIS_AngleDimension.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <Aspect_PolygonOffsetMode.hxx>
90 #include <Aspect_ColorScale.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <StdSelect_TypeOfEdge.hxx>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <StdSelect_DisplayMode.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <BRep_Tool.hxx>
98 #include <Geom_Plane.hxx>
99 #include <Geom_Axis2Placement.hxx>
100 #include <Graphic3d_AspectFillArea3d.hxx>
101 #include <gp_Pln.hxx>
102 #include <TColStd_MapOfInteger.hxx>
103 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
104 #include <TopoDS_Iterator.hxx>
105 #include <Graphic3d_AspectMarker3d.hxx>
106 #include <TopTools_MapOfShape.hxx>
107 #include <TopTools_ListOfShape.hxx>
108 #include <TopTools_ListIteratorOfListOfShape.hxx>
109 #include <TopoDS.hxx>
110 #include <NCollection_DataMap.hxx>
111 #include <NCollection_Map.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #include <TColStd_HArray1OfByte.hxx>
128 // If the next macro is defined, autocolor feature works for all sub-shapes;
129 // if it is undefined, autocolor feature works for groups only
130 #define GENERAL_AUTOCOLOR
131 // Below macro, when uncommented, switches on simplified (more performant) algorithm
132 // of auto-color picking up
133 #define SIMPLE_AUTOCOLOR
135 // Hard-coded value of shape deflection coefficient for VTK viewer
136 const double VTK_MIN_DEFLECTION = 0.001;
138 // Pixmap caching support
141 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
142 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
143 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
145 static inline PixmapUsageMap& getPixmapUsageMap()
147 static PixmapUsageMap aMap;
151 static inline PixmapCacheMap& getPixmapCacheMap()
153 static PixmapCacheMap aMap;
157 //===========================================================================
158 // Function : getDefaultTexture
159 // Purpose : Get default texture
160 //===========================================================================
161 static inline Handle(Image_PixMap) getDefaultTexture()
163 static Handle(Image_PixMap) aPixmap;
164 if ( aPixmap.IsNull() ) {
165 QPixmap px(":images/default_texture.png");
167 aPixmap = imageToPixmap( px.toImage() );
172 //===========================================================================
173 // Function : cacheTextureFor
174 // Purpose : Load and cache image for the specified presentation.
175 //===========================================================================
176 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
177 const Handle(GEOM_AISShape)& theShape )
179 if ( thePath.isEmpty() )
182 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
183 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
185 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
186 if ( !aPixmap.IsNull() ) {
187 // point that the texture is used by the presentation
188 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
189 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
191 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
196 // convert texture to compatible image format
197 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
198 if ( anImage.isNull() )
201 aPixmap = imageToPixmap( anImage );
203 aPixmapCacheMap.insert( thePath, aPixmap );
205 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
206 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
208 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
213 //===========================================================================
214 // Function : releaseTextures
215 // Purpose : Releases cached textures found for the specified presentation.
216 //===========================================================================
217 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
219 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
221 AIS_ListOfInteractive aListOfIO;
223 anOccPrs->GetObjects( aListOfIO );
225 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
227 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
228 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
230 for ( ; aIterateIO.More(); aIterateIO.Next() )
232 Handle(GEOM_AISShape) aAISShape =
233 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
235 if ( aAISShape.IsNull() )
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 ) );
257 //================================================================
258 // Function : getActiveStudy
259 // Purpose : Get active study, returns 0 if no open study frame
260 //================================================================
261 static inline SalomeApp_Study* getActiveStudy()
263 SUIT_Session* session = SUIT_Session::session();
264 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
266 return ( SalomeApp_Study* )app->activeStudy();
270 static inline int getViewManagerId( SALOME_View* theViewFrame) {
271 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
272 SUIT_ViewManager* aViewMgr = 0;
274 aViewMgr = aModel->getViewManager();
275 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
278 //================================================================
279 // Function : getTopAbsMode
280 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
281 // one from GEOMImpl_Types.h
282 //================================================================
283 static inline int getTopAbsMode( const int implType )
287 case GEOM_COMPOUND : return TopAbs_COMPOUND;
288 case GEOM_SOLID : return TopAbs_SOLID;
289 case GEOM_SHELL : return TopAbs_SHELL;
290 case GEOM_FACE : return TopAbs_FACE;
291 case GEOM_WIRE : return TopAbs_WIRE;
292 case GEOM_EDGE : return TopAbs_EDGE;
293 case GEOM_POINT : return TopAbs_VERTEX;
298 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
300 if ( shape.IsNull() )
303 int ret = shape.ShapeType();
305 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
306 TopoDS_Iterator it(shape, Standard_True, Standard_False);
307 for (; it.More(); it.Next()) {
308 TopoDS_Shape sub_shape = it.Value();
309 if ( sub_shape.IsNull() ) continue;
310 int stype = getMinMaxShapeType( sub_shape, ismin );
311 if ( stype == TopAbs_SHAPE ) continue;
312 if ( ismin && stype > ret )
314 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
322 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
324 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
327 //================================================================
328 // Function : getFilter
329 // Purpose : Get filter corresponding to the type of object
330 // from GEOMImpl_Types.h
331 //================================================================
332 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
334 SUIT_SelectionFilter* aFilter;
336 int aTopAbsMode = getTopAbsMode( theMode );
337 if ( aTopAbsMode != -1 )
338 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
342 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
343 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
345 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
346 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
347 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
348 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
349 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
350 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
352 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
354 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
355 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
357 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
363 //================================================================
364 // Function : getComplexFilter
365 // Purpose : Get compound filter corresponding to the type of
366 // object from GEOMImpl_Types.h
367 //================================================================
368 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
370 GEOM_CompoundFilter* aFilter;
372 if(aSubShapes != NULL ) {
373 aFilter = new GEOM_CompoundFilter(getStudy());
374 QList<int> aTopAbsTypes;
375 QList<int>::const_iterator it;
376 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
377 int topAbsMode = getTopAbsMode(*it);
378 if(topAbsMode != -1 )
379 aTopAbsTypes.append(topAbsMode);
381 aFilter->addSubTypes(aTopAbsTypes);
387 //================================================================
388 // Function : getEntry
390 //================================================================
391 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
393 SUIT_Session* session = SUIT_Session::session();
394 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
397 CORBA::String_var IOR = app->orb()->object_to_string( object );
398 if ( strcmp(IOR.in(), "") != 0 )
400 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
401 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
409 //================================================================
410 // Function : getName
412 //================================================================
413 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
415 SUIT_Session* session = SUIT_Session::session();
416 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
419 CORBA::String_var IOR = app->orb()->object_to_string( object );
420 if ( strcmp(IOR.in(), "") != 0 )
422 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
423 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
425 _PTR(GenericAttribute) anAttr;
427 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
429 _PTR(AttributeName) aNameAttr( anAttr );
430 return aNameAttr->Value();
438 //=================================================================
440 * GEOM_Displayer::GEOM_Displayer
443 //=================================================================
444 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
447 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
452 SUIT_Session* session = SUIT_Session::session();
453 SUIT_ResourceMgr* resMgr = session->resourceMgr();
455 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
456 myShadingColor = SalomeApp_Tools::color( col );
458 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
459 myHasDisplayMode = false;
461 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
462 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
463 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
465 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
466 myHasTransparency = false;
468 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
469 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
470 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
473 // This color is used for shape displaying. If it is equal -1 then
474 // default color is used.
480 // This parameter is used for activisation/deactivisation of objects to be displayed
482 // Activate parallel vizualisation only for testing purpose
483 // and if the corresponding env variable is set to 1
484 char* parallel_visu = getenv("PARALLEL_VISU");
485 if (parallel_visu && atoi(parallel_visu))
487 MESSAGE("Parallel visualisation on");
488 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
493 myFieldDataType = GEOM::FDT_Double;
494 myFieldDimension = 0;
495 myFieldStepRangeMin = 0;
496 myFieldStepRangeMax = 0;
499 //=================================================================
501 * GEOM_Displayer::~GEOM_Displayer
504 //=================================================================
505 GEOM_Displayer::~GEOM_Displayer()
509 //=================================================================
511 * GEOM_Displayer::Display
512 * Display interactive object in the current viewer
514 //=================================================================
515 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
516 const bool updateViewer,
517 SALOME_View* theViewFrame )
519 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
522 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
526 vf->BeforeDisplay( this, prs );
528 vf->AfterDisplay( this, prs );
533 int aMgrId = getViewManagerId(vf);
534 SalomeApp_Study* aStudy = getStudy();
535 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
537 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
539 delete prs; // delete presentation because displayer is its owner
544 //=================================================================
546 * GEOM_Displayer::Display
547 * This overloaded Display() method can be useful for operations
548 * not using dialog boxes.
550 //=================================================================
551 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
553 if ( theObj->_is_nil() )
556 std::string entry = getEntry( theObj );
558 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
563 //=================================================================
565 * GEOM_Displayer::Erase
566 * Erase interactive object in the current viewer
568 //=================================================================
569 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
571 const bool updateViewer,
572 SALOME_View* theViewFrame )
574 if ( theIO.IsNull() )
577 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
580 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
582 vf->BeforeErase( this, prs );
583 vf->Erase( prs, forced );
584 vf->AfterErase( this, prs );
587 delete prs; // delete presentation because displayer is its owner
589 int aMgrId = getViewManagerId(vf);
590 SalomeApp_Study* aStudy = getStudy();
591 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
593 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
598 //=================================================================
600 * GEOM_Displayer::Erase
601 * Erase geometry object in the current viewer
603 //=================================================================
604 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
606 const bool updateViewer,
607 SALOME_View* theViewFrame)
609 std::string entry = getEntry( theObj );
612 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
613 forced, updateViewer, theViewFrame);
617 //=================================================================
619 * GEOM_Displayer::Redisplay
620 * Redisplay (erase and then display again) interactive object
621 * in the current viewer
623 //=================================================================
624 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
625 const bool updateViewer,
626 const bool checkActiveViewer )
628 // Remove the object permanently (<forced> == true)
629 SUIT_Session* ses = SUIT_Session::session();
630 SUIT_Application* app = ses->activeApplication();
633 SUIT_Desktop* desk = app->desktop();
634 QList<SUIT_ViewWindow*> wnds = desk->windows();
635 SUIT_ViewWindow* wnd;
636 QListIterator<SUIT_ViewWindow*> it( wnds );
637 while ( it.hasNext() && (wnd = it.next()) )
639 SUIT_ViewManager* vman = wnd->getViewManager();
642 SUIT_ViewModel* vmodel = vman->getViewModel();
645 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
648 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
650 Redisplay( theIO, updateViewer, view );
659 //=================================================================
661 * GEOM_Displayer::Redisplay
662 * Redisplay (erase and then display again) interactive object
663 * in the specified view
665 //=================================================================
666 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
667 const bool theUpdateViewer,
668 SALOME_View* theViewFrame )
670 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
676 Erase( theIO, true, false, theViewFrame );
677 Display( theIO, theUpdateViewer, theViewFrame );
680 //=================================================================
682 * GEOM_Displayer::Display
683 * Calls Display() method for each object in the given list
685 //=================================================================
686 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
688 SALOME_ListIteratorOfListIO Iter( theIOList );
689 for ( ; Iter.More(); Iter.Next() ) {
690 Display( Iter.Value(), false );
696 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
698 // VSR: this method can be improved in future:
699 // to improve performance, the default values from resource manager should be cached in the displayer
700 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
703 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
705 // VSR: this method can be improved in future:
706 // to improve performance, the default values from resource manager should be cached in the displayer
707 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
710 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
712 // check that shape is not null
713 if ( AISShape.IsNull() ) return;
715 // check that study is active
716 SalomeApp_Study* study = getStudy();
717 if ( !study ) return;
719 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
720 !TopoDS_Iterator(myShape).More() )
721 return; // NPAL15983 (Bug when displaying empty groups)
723 // set interactive object
725 Handle( SALOME_InteractiveObject ) anIO;
727 if ( !myIO.IsNull() ) {
728 AISShape->setIO( myIO );
729 AISShape->SetOwner( myIO );
732 else if ( !myName.empty() ) {
733 // workaround to allow selection of temporary objects
734 static int tempId = 0;
735 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
736 AISShape->setIO( anIO );
737 AISShape->SetOwner( anIO );
740 // flag: only vertex or compound of vertices is processed (specific handling)
741 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
742 // presentation study entry (empty for temporary objects like preview)
743 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
744 // flag: temporary object
745 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
746 // currently active view window's ID (-1 if no active view)
747 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
749 // get presentation properties
750 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
752 // Temporary staff: vertex must be infinite for correct visualization
753 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
756 Material_Model material;
757 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
759 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
760 // - set front material properties
761 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
762 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
763 // - set back material properties
764 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
765 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
766 // - switch to default (both sides) facing mode
767 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
773 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
774 // we set it to the shape not taking into account material properties
775 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
777 else if ( !material.isPhysical() ) {
778 // shading color from properties is used only for non-physical materials
779 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
783 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
784 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
785 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
786 AISShape->Attributes()->SetLineAspect( anAspect );
788 // - unfree boundaries color
789 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
790 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
791 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
792 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
794 // - free boundaries color
795 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
796 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
797 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
798 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
800 // - standalone edges color
801 anAspect = AISShape->Attributes()->WireAspect();
802 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
803 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
804 AISShape->Attributes()->SetWireAspect( anAspect );
806 // - color for edges in shading+edges mode
807 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
810 AISShape->SetDisplayMode( HasDisplayMode() ?
811 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
813 // display mode from properties
814 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
816 // - face boundaries color
817 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
818 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
819 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
820 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
821 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
823 // set display vectors flag
824 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
826 // set display vertices flag
827 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
828 AISShape->SetDisplayVertices( isVerticesMode );
831 if( HasTransparency() ) {
832 AISShape->SetTransparency( GetTransparency() );
834 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
837 // set iso properties
838 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
839 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
840 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
841 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
842 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
843 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
844 uIsoAspect->SetColor( isosColor );
845 uIsoAspect->SetWidth( isosWidth );
846 uIsoAspect->SetNumber( uIsos );
847 vIsoAspect->SetColor( isosColor );
848 vIsoAspect->SetWidth( isosWidth );
849 vIsoAspect->SetNumber( vIsos );
850 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
851 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
853 // set deflection coefficient
854 // ... to avoid to small values of the coefficient, its lower value is limited
855 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
859 if ( HasTexture() ) {
860 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
861 aImagePath = GetTexture().c_str();
862 if ( ! entry.isEmpty() ) {
863 // check that study is active
864 SalomeApp_Study* study = getActiveStudy();
866 // Store the texture in object properties for next displays
867 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
868 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
870 // Update propeties map
871 propMap = getObjectProperties( study, entry, myViewFrame );
876 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
879 Handle(Image_PixMap) aPixmap;
880 if ( !aImagePath.isEmpty() )
881 aPixmap = cacheTextureFor( aImagePath, AISShape );
883 aPixmap = getDefaultTexture();
885 // apply image to shape
886 if ( !aPixmap.IsNull() ) {
887 AISShape->SetTexturePixMap( aPixmap );
888 AISShape->SetTextureMapOn();
889 AISShape->DisableTextureModulate();
892 AISShape->SetTextureMapOff();
896 AISShape->SetWidth( HasWidth() ?
897 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
899 // libe width from properties
900 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
902 // set top-level flag
903 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
905 // set point marker (for vertex / compound of vertices only)
906 if ( onlyVertex || isVerticesMode ) {
907 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
908 if ( aList.size() == 2 ) {
909 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
910 int aTypeOfMarker = aList[0].toInt();
911 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
912 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
913 anAspect->SetScale( aScaleOfMarker );
914 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
915 anAspect->SetColor( HasColor() ?
916 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
917 (Quantity_NameOfColor)GetColor() :
918 // color from properties
919 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
920 AISShape->Attributes()->SetPointAspect( anAspect );
922 else if ( aList.size() == 1 ) {
923 // custom marker string contains "IdOfTexture"
924 int textureId = aList[0].toInt();
925 Standard_Integer aWidth, aHeight;
926 Handle(TColStd_HArray1OfByte) aTexture =
927 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
928 if ( !aTexture.IsNull() ) {
929 Handle(Prs3d_PointAspect) aTextureAspect =
930 new Prs3d_PointAspect( HasColor() ?
931 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
932 (Quantity_NameOfColor)GetColor() :
933 // color from properties
934 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
937 AISShape->Attributes()->SetPointAspect( aTextureAspect );
942 // set field step data
943 AISShape->setFieldStepInfo( myFieldDataType,
948 myFieldStepRangeMax );
950 if ( create && !isTemporary && aMgrId != -1 ) {
951 // set properties to the study
952 study->setObjectPropMap( aMgrId, entry, propMap );
955 // AISShape->SetName(???); ??? necessary to set name ???
958 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
960 // check that actor is not null
961 if ( !actor ) return;
963 // check that study is active
964 SalomeApp_Study* study = getStudy();
965 if ( !study ) return;
967 // set interactive object
969 Handle( SALOME_InteractiveObject ) anIO;
971 if ( !myIO.IsNull() ) {
972 actor->setIO( myIO );
975 else if ( !myName.empty() ) {
976 // workaround to allow selection of temporary objects
977 static int tempId = 0;
978 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
979 actor->setIO( anIO );
982 // presentation study entry (empty for temporary objects like preview)
983 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
984 // flag: temporary object
985 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
986 // currently active view window's ID (-1 if no active view)
987 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
989 // get presentation properties
990 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
993 /////////////////////////////////////////////////////////////////////////
994 // VSR: for VTK viewer currently deflection coefficient is hardcoded
995 // due to performance problem
996 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
997 /////////////////////////////////////////////////////////////////////////
998 if ( !actor->getTopo().IsSame( myShape ) )
999 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1002 Material_Model material;
1003 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1004 std::vector<vtkProperty*> mprops;
1005 mprops.push_back( material.getMaterialVTKProperty( true ) );
1006 mprops.push_back( material.getMaterialVTKProperty( false) );
1007 actor->SetMaterial( mprops );
1009 // set iso-lines properties
1011 // - set number of iso-lines
1012 int nbIsos[2]= { 1, 1 };
1013 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1014 nbIsos[0] = isos[0].toInt();
1015 nbIsos[1] = isos[1].toInt();
1016 actor->SetNbIsos( nbIsos );
1018 // - set iso-lines width
1019 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1021 // - set iso-lines color
1022 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1023 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1028 // - same color for all sub-actors
1029 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1030 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1033 // shading color (for non-physical materials)
1034 if ( !material.isPhysical() ) {
1035 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1036 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1037 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1040 // - standalone edge color
1041 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1042 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1044 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1045 // - shared edges color ???
1046 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1048 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1049 // - free edges color ???
1050 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1053 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1054 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1057 // - color for edges in shading+edges mode
1058 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1059 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1062 if( HasTransparency() ) {
1063 actor->SetOpacity( 1.0 - GetTransparency() );
1065 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1069 actor->SetWidth( HasWidth() ?
1070 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1072 // libe width from properties
1073 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1075 // set display vectors flag
1076 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1078 // set display vertices flag
1079 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1082 int displayMode = HasDisplayMode() ?
1083 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1085 // display mode from properties
1086 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1088 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1089 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1090 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1091 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1093 if ( displayMode == 2 )
1094 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1095 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1097 actor->setDisplayMode( displayMode );
1100 actor->PickableOn();
1102 actor->PickableOff();
1104 if ( create && !isTemporary && aMgrId != -1 ) {
1105 // set properties to the study
1106 study->setObjectPropMap( aMgrId, entry, propMap );
1110 //=================================================================
1112 * GEOM_Displayer::updateDimensions
1113 * Creates or renews dimension presentation for the IO.
1115 //=================================================================
1116 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1117 SALOME_OCCPrs* thePrs,
1118 const gp_Ax3& theShapeLCS )
1120 SalomeApp_Study* aStudy = getStudy();
1126 if ( theIO.IsNull() )
1131 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1133 AIS_ListOfInteractive aListOfIO;
1135 anOccPrs->GetObjects( aListOfIO );
1137 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1139 // remove outdated presentations of dimensions
1140 for ( ; aIterateIO.More(); aIterateIO.Next() )
1142 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1143 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1148 aListOfIO.Remove( aIterateIO );
1150 if ( !aIterateIO.More() )
1156 // prepare dimension styling
1157 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1159 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1160 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1161 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1162 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1163 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1164 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1165 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1167 // restore dimension presentation from saved attribute or property data
1168 AIS_ListOfInteractive aRestoredDimensions;
1170 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1172 GEOM::propertyName( GEOM::Dimensions ),
1175 GEOMGUI_DimensionProperty aRecords;
1177 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1179 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1183 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1186 // create up-to-date dimension presentations
1187 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1189 if ( !aRecords.IsVisible( aPrsIt ) )
1194 // init dimension by type
1195 Handle(AIS_Dimension) aPrs;
1196 switch( aRecords.GetType( aPrsIt ) )
1198 case GEOMGUI_DimensionProperty::DimensionType_Length :
1200 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1201 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1206 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1208 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1209 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1214 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1216 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1217 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1223 aPrs->SetOwner( theIO );
1225 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1227 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1229 aStyle->SetCommonColor( aColor );
1230 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1231 aStyle->MakeText3d( Standard_True );
1232 aStyle->MakeTextShaded( Standard_True );
1233 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1234 aStyle->TextAspect()->SetHeight( aFontHeight );
1235 aStyle->ArrowAspect()->SetLength( anArrowLength );
1236 aStyle->LineAspect()->SetWidth( aLineWidth );
1237 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1238 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1239 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1240 aPrs->SetDimensionAspect( aStyle );
1241 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1242 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1243 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1245 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1247 // show degree symbol for dimension instead of label "deg"
1248 if ( aUnitsAngle == "deg" )
1250 aPrs->SetSpecialSymbol(0xB0);
1251 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1252 aStyle->MakeUnitsDisplayed(Standard_False);
1256 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1257 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1262 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1265 aListOfIO.Append( aPrs );
1268 // update presentation
1271 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1273 anOccPrs->AddObject( aIterateIO.Value() );
1277 //=================================================================
1279 * GEOM_Displayer::Erase
1280 * Calls Erase() method for each object in the given list
1282 //=================================================================
1283 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1285 const bool updateViewer )
1287 SALOME_ListIteratorOfListIO Iter( theIOList );
1288 for ( ; Iter.More(); Iter.Next() )
1289 Erase( Iter.Value(), forced, false );
1295 //=================================================================
1297 * GEOM_Displayer::Redisplay
1298 * Calls Redisplay() method for each object in the given list
1300 //=================================================================
1301 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1302 const bool updateViewer,
1303 const bool checkActiveViewer )
1305 SALOME_ListIteratorOfListIO Iter( theIOList );
1306 for ( ; Iter.More(); Iter.Next() )
1307 Redisplay( Iter.Value(), false, checkActiveViewer );
1313 //=================================================================
1315 * GEOM_Displayer::Redisplay
1316 * Calls Redisplay() method for each object in the given list
1318 //=================================================================
1319 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1320 const bool theUpdateViewer,
1321 SALOME_View* theViewFrame )
1323 SALOME_ListIteratorOfListIO anIter( theIOList );
1324 for ( ; anIter.More(); anIter.Next() )
1326 Redisplay( anIter.Value(), false, theViewFrame );
1329 if ( theUpdateViewer )
1335 //=================================================================
1337 * GEOM_Displayer::Update
1338 * Update OCC presentaion
1339 * [ Reimplemented from SALOME_Displayer ]
1341 //=================================================================
1342 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1344 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1345 SalomeApp_Study* study = getStudy();
1347 if ( !occPrs || myShape.IsNull() || !study )
1350 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1353 // specific processing for local coordinate system presentation
1356 TopoDS_Face aFace = TopoDS::Face( myShape );
1357 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1358 if ( !aPlane.IsNull() )
1360 gp_Ax3 aPos = aPlane->Pln().Position();
1361 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1363 Handle(GEOM_AISTrihedron) aTrh;
1365 if ( occPrs->IsNull() )
1367 // new presentation is being created
1368 aTrh = new GEOM_AISTrihedron( aPlc );
1369 occPrs->AddObject( aTrh );
1373 // presentation is being updated
1374 AIS_ListOfInteractive aList;
1375 occPrs->GetObjects( aList );
1376 AIS_ListIteratorOfListOfInteractive anIter( aList );
1377 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1378 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1382 if ( !aTrh.IsNull() ) {
1383 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1385 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1386 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1388 aTrh->SetWidth( GetWidth() );
1390 if ( !myIO.IsNull() )
1392 aTrh->setIO( myIO );
1393 aTrh->SetOwner( myIO );
1395 aTrh->SetComponent( aPlc );
1396 aTrh->SetToUpdate();
1398 occPrs->SetToActivate( ToActivate() );
1404 // processing for usual geometry presentation
1407 // if presentation is empty we try to create new one
1408 if ( occPrs->IsNull() )
1410 // create presentation (specific for vectors)
1411 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1412 : new GEOM_AISShape ( myShape, "" );
1414 if( myType == GEOM_FIELD_STEP )
1415 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1416 // update shape properties
1417 updateShapeProperties( AISShape, true );
1419 // add shape to the presentation
1420 occPrs->AddObject( AISShape );
1422 // In accordance with ToActivate() value object will be activated/deactivated
1423 // when it will be displayed
1424 occPrs->SetToActivate( ToActivate() );
1426 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1427 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1429 // create additional wireframe shape
1430 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1431 aWirePrs->SetWidth(AISShape->Width());
1432 if ( !myIO.IsNull() ) {
1433 aWirePrs->setIO( myIO );
1434 aWirePrs->SetOwner( myIO );
1437 // add shape to the presentation
1438 occPrs->AddObject( aWirePrs );
1441 // if presentation is found -> set again shape for it
1444 AIS_ListOfInteractive IOList;
1445 occPrs->GetObjects( IOList );
1446 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1447 for ( ; Iter.More(); Iter.Next() )
1449 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1450 if ( AISShape.IsNull() )
1453 // re-set shape (it might be changed)
1454 if ( AISShape->Shape() != myShape )
1455 AISShape->Set( myShape );
1457 // update shape properties
1458 updateShapeProperties( AISShape, false );
1461 AISShape->UpdateSelection();
1462 AISShape->SetToUpdate();
1466 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1470 //=================================================================
1472 * GEOM_Displayer::Update
1473 * Update VTK presentaion
1474 * [ Reimplemented from SALOME_Displayer ]
1476 //=================================================================
1477 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1479 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1480 SalomeApp_Study* study = getStudy();
1482 if ( !vtkPrs || myShape.IsNull() || !study )
1485 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1488 // specific processing for local coordinate system presentation
1491 TopoDS_Face aFace = TopoDS::Face( myShape );
1492 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1493 if ( !aPlane.IsNull() ) {
1494 gp_Ax3 aPos = aPlane->Pln().Position();
1495 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1497 GEOM_VTKTrihedron* aTrh = 0;
1499 if ( vtkPrs->IsNull() ) {
1500 // new presentation is being created
1501 aTrh = GEOM_VTKTrihedron::New();
1502 vtkPrs->AddObject( aTrh );
1505 // presentation is being updated
1506 vtkActorCollection* actors = vtkPrs->GetObjects();
1508 actors->InitTraversal();
1509 vtkActor* a = actors->GetNextActor();
1510 while ( a && !aTrh ) {
1511 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1512 a = actors->GetNextActor();
1518 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1520 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1521 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1523 #ifdef VTK_TRIHEDRON_WIDTH
1525 // VSR: currently isn't supported
1527 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1529 aTrh->SetWidth( GetWidth() );
1532 if ( !myIO.IsNull() )
1533 aTrh->setIO( myIO );
1535 aTrh->SetPlacement( aPlc );
1542 // processing for usual geometry presentation
1545 // if presentation is empty we try to create new one
1546 if ( vtkPrs->IsNull() )
1549 GEOM_Actor* actor = GEOM_Actor::New();
1550 // update actor properties
1551 updateActorProperties( actor, true );
1552 // add actor to the presentation
1553 vtkPrs->AddObject( actor );
1556 // presentation is being updated
1557 vtkActorCollection* actors = vtkPrs->GetObjects();
1559 actors->InitTraversal();
1560 vtkActor* a = actors->GetNextActor();
1562 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1564 // update actor properties
1565 updateActorProperties( actor, false );
1566 a = actors->GetNextActor();
1574 //=================================================================
1576 * GEOM_Displayer::BuildPrs
1577 * Build presentation accordint to the current viewer type
1579 //=================================================================
1580 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1582 if ( theObj->_is_nil() )
1585 myViewFrame = GetActiveView();
1586 if ( myViewFrame == 0 )
1589 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1594 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1595 myType = theObj->GetType();
1597 // Update presentation
1603 //=================================================================
1605 * GEOM_Displayer::BuildPrs
1606 * Build presentation accordint to the current viewer type
1608 //=================================================================
1609 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1611 myViewFrame = GetActiveView();
1612 if ( theShape.IsNull() || myViewFrame == 0 )
1615 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1620 setShape( theShape );
1628 //=================================================================
1630 * GEOM_Displayer::buildPresentation
1631 * Builds/finds object's presentation for the current viewer
1632 * Calls corresponding Update() method by means of double dispatch
1635 //=================================================================
1636 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1637 SALOME_View* theViewFrame )
1639 SALOME_Prs* prs = 0;
1642 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1646 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1649 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1650 theIO->setEntry( entry.toLatin1().constData() );
1651 if ( !theIO.IsNull() )
1653 // set interactive object
1655 // Find SOBject (because shape should be published previously)
1656 SUIT_Session* session = SUIT_Session::session();
1657 SUIT_Application* app = session->activeApplication();
1660 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1663 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1666 // get CORBA reference to data object
1667 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1668 if ( !CORBA::is_nil( object ) )
1670 // downcast to GEOM base object
1671 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1672 if ( !GeomBaseObject->_is_nil() )
1674 myType = GeomBaseObject->GetType();
1676 // downcast to GEOM object
1677 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1678 if ( myType == GEOM_FIELD_STEP )
1680 // get the GEOM object from the field's shape
1681 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1682 if ( !GeomFieldStep->_is_nil() )
1684 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1685 if ( !GeomField->_is_nil() )
1686 GeomObject = GeomField->GetShape();
1689 // read the field step information
1690 readFieldStepInfo( GeomFieldStep );
1693 if ( !GeomObject->_is_nil() )
1695 // finally set shape
1696 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1704 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1710 //=================================================================
1712 * GEOM_Displayer::buildSubshapePresentation
1713 * Builds/finds object's presentation for the current viewer
1714 * Calls corresponding Update() method by means of double dispatch
1715 * For not published objects (for Mantis issue 0020435)
1717 //=================================================================
1718 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1719 const QString& entry,
1720 SALOME_View* theViewFrame)
1722 SALOME_Prs* prs = 0;
1725 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1729 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1732 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1733 theIO->setEntry(entry.toLatin1().constData());
1734 if (!theIO.IsNull())
1736 // set interactive object
1738 // finally set shape
1740 myType = GEOM_SUBSHAPE;
1742 UpdatePrs(prs); // Update presentation by using of the double dispatch
1748 //=================================================================
1750 * GEOM_Displayer::internalReset
1751 * Resets internal data
1754 //=================================================================
1755 void GEOM_Displayer::internalReset()
1760 myFieldDataType = GEOM::FDT_Double;
1761 myFieldDimension = 0;
1762 myFieldStepData.clear();
1763 myFieldStepName.Clear();
1764 myFieldStepRangeMin = 0;
1765 myFieldStepRangeMax = 0;
1768 //=================================================================
1770 * GEOM_Displayer::LocalSelection
1771 * Activate selection of CAD shapes with activisation of selection
1772 * of their sub-shapes (with opened local context for OCC viewer)
1774 //=================================================================
1775 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1777 SUIT_Session* session = SUIT_Session::session();
1778 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1782 LightApp_SelectionMgr* sm = app->selectionMgr();
1784 // remove all filters from selection
1787 SALOME_View* vf = GetActiveView();
1789 if (!theIO.IsNull() && !vf->isVisible(theIO))
1791 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1792 vf->LocalSelection( prs, theMode );
1793 delete prs; // delete presentation because displayer is its owner
1797 //=================================================================
1799 * GEOM_Displayer::globalSelection
1800 * Activate selection of CAD shapes without activisation of selection
1801 * of their sub-shapes (without opened local context for OCC viewer)
1803 //=================================================================
1804 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1806 TColStd_MapOfInteger aModes;
1807 aModes.Add( theMode );
1808 GlobalSelection( aModes, update );
1811 //=================================================================
1813 * GEOM_Displayer::globalSelection
1814 * Activate selection of CAD shapes without activisation of selection
1815 * of their sub-shapes (without opened local context for OCC viewer)
1817 //=================================================================
1818 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1819 const bool update, const QList<int>* theSubShapes )
1821 SUIT_Session* session = SUIT_Session::session();
1822 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1826 SALOME_View* vf = GetActiveView();
1830 // Close local context
1831 vf->GlobalSelection( update );
1833 // Set selection filters in accordance with current mode
1834 LightApp_SelectionMgr* sm = app->selectionMgr();
1838 // Remove from selection temporary objects if necessary
1839 if ( !theModes.Contains( GEOM_PREVIEW ) )
1840 clearTemporary( sm );
1842 //@ aSel->ClearIndex();
1846 // Remove filters from AIS_InteractiveContext
1847 Handle(AIS_InteractiveContext) ic;
1848 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1851 ic = viewer->getAISContext();
1853 ic->RemoveFilters();
1856 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1859 SUIT_SelectionFilter* aFilter;
1860 if ( theModes.Extent() == 1 )
1862 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1864 if ( aMode == GEOM_COMPOUNDFILTER )
1865 aFilter = getComplexFilter( theSubShapes );
1867 aFilter = getFilter( aMode );
1869 else if ( theModes.Extent() > 1 )
1871 TColStd_MapOfInteger aTopAbsModes;
1872 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1873 QList<SUIT_SelectionFilter*> aListOfFilters;
1874 for ( ; anIter.More(); anIter.Next() )
1876 SUIT_SelectionFilter* aFilter;
1877 int aMode = anIter.Key();
1878 if ( aMode == GEOM_COMPOUNDFILTER )
1879 aFilter = getComplexFilter( theSubShapes );
1881 aFilter = getFilter( aMode );
1884 aListOfFilters.append( aFilter );
1887 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1894 sm->installFilter( aFilter );
1897 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1898 ic->AddFilter( anOCCFilter );
1903 //=================================================================
1905 * GEOM_Displayer::LocalSelection
1906 * Activate selection of CAD shapes with activisation of selection
1907 * of their sub-shapes (with opened local context for OCC viewer)
1909 //=================================================================
1910 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1912 SALOME_ListIteratorOfListIO Iter( theIOList );
1913 for ( ; Iter.More(); Iter.Next() )
1914 LocalSelection( Iter.Value(), theMode );
1917 //=================================================================
1919 * GEOM_Displayer::BeforeDisplay
1920 * Called before displaying of pars. Close local context
1921 * [ Reimplemented from SALOME_Displayer ]
1923 //=================================================================
1924 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1926 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1929 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1932 if ( ic->HasOpenedContext() )
1933 ic->CloseAllContexts();
1938 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1940 UpdateColorScale(false,false);
1943 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1945 LightApp_Displayer::BeforeErase( v, p );
1946 releaseTextures( p );
1949 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1951 LightApp_Displayer::AfterErase( v, p );
1952 UpdateColorScale(false,false);
1955 //=================================================================
1957 * GEOM_Displayer::SetColor
1958 * Set color for shape displaying. If it is equal -1 then default color is used.
1959 * Available values are from Quantity_NameOfColor enumeration
1961 //=================================================================
1962 void GEOM_Displayer::SetColor( const int color )
1969 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1973 int GEOM_Displayer::GetColor() const
1978 bool GEOM_Displayer::HasColor() const
1980 return myColor != -1;
1983 void GEOM_Displayer::UnsetColor()
1987 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1988 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1989 myShadingColor = SalomeApp_Tools::color( col );
1992 //=================================================================
1994 * GEOM_Displayer::SetTransparency
1995 * Set transparency for shape displaying.
1997 //=================================================================
1998 double GEOM_Displayer::SetTransparency( const double transparency )
2000 double aPrevTransparency = myTransparency;
2001 if ( transparency < 0 ) {
2002 UnsetTransparency();
2005 myTransparency = transparency;
2006 myHasTransparency = true;
2008 return aPrevTransparency;
2011 //=================================================================
2013 * GEOM_Displayer::GetTransparency
2014 * Get transparency for shape displaying.
2016 //=================================================================
2017 double GEOM_Displayer::GetTransparency() const
2019 return myTransparency;
2022 //=================================================================
2024 * GEOM_Displayer::HasTransparency
2025 * Check if transparency for shape displaying is set.
2027 //=================================================================
2028 bool GEOM_Displayer::HasTransparency() const
2030 return myHasTransparency;
2033 //=================================================================
2035 * GEOM_Displayer::UnsetTransparency
2036 * Unset transparency for shape displaying.
2038 //=================================================================
2039 double GEOM_Displayer::UnsetTransparency()
2041 double aPrevTransparency = myTransparency;
2042 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2043 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
2044 myHasTransparency = false;
2045 return aPrevTransparency;
2049 //=================================================================
2051 * GEOM_Displayer::SetTexture
2052 * Set color for shape displaying. If it is equal -1 then default color is used.
2053 * Available values are from Quantity_NameOfColor enumeration
2055 //=================================================================
2056 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2058 if(texureFileName!="")
2060 myTexture = texureFileName;
2064 bool GEOM_Displayer::HasTexture() const
2066 return myTexture != "";
2069 std::string GEOM_Displayer::GetTexture() const
2074 //=================================================================
2076 * GEOM_Displayer::SetWidth
2077 * Set width of shape displaying. If it is equal -1 then default width is used.
2079 //=================================================================
2080 void GEOM_Displayer::SetWidth( const double width )
2085 double GEOM_Displayer::GetWidth() const
2090 bool GEOM_Displayer::HasWidth() const
2092 return myWidth != -1;
2095 void GEOM_Displayer::UnsetWidth()
2101 int GEOM_Displayer::GetIsosWidth() const
2106 void GEOM_Displayer::SetIsosWidth(const int width)
2108 myIsosWidth = width;
2111 bool GEOM_Displayer::HasIsosWidth() const
2113 return myIsosWidth != -1;
2117 //=================================================================
2119 * GEOM_Displayer::SetToActivate
2120 * This method is used for activisation/deactivisation of objects to be displayed
2122 //=================================================================
2123 void GEOM_Displayer::SetToActivate( const bool toActivate )
2125 myToActivate = toActivate;
2127 bool GEOM_Displayer::ToActivate() const
2129 return myToActivate;
2132 //=================================================================
2134 * GEOM_Displayer::clearTemporary
2135 * Removes from selection temporary objects
2137 //=================================================================
2138 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2140 SALOME_ListIO selected, toSelect;
2141 theSelMgr->selectedObjects( selected );
2143 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2144 Handle(SALOME_InteractiveObject) io = it.Value();
2145 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2146 toSelect.Append( it.Value() );
2149 theSelMgr->setSelectedObjects( toSelect, true );
2152 void GEOM_Displayer::SetName( const char* theName )
2157 void GEOM_Displayer::UnsetName()
2162 SalomeApp_Study* GEOM_Displayer::getStudy() const
2164 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2167 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2172 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2177 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2178 const int theFieldDimension,
2179 const QList<QVariant>& theFieldStepData,
2180 const TCollection_AsciiString& theFieldStepName,
2181 const double theFieldStepRangeMin,
2182 const double theFieldStepRangeMax )
2184 myFieldDataType = theFieldDataType;
2185 myFieldDimension = theFieldDimension;
2186 myFieldStepData = theFieldStepData;
2187 myFieldStepName = theFieldStepName;
2188 myFieldStepRangeMin = theFieldStepRangeMin;
2189 myFieldStepRangeMax = theFieldStepRangeMax;
2192 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2194 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2195 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2196 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2197 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2198 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2199 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2202 int GEOM_Displayer::SetDisplayMode( const int theMode )
2204 int aPrevMode = myDisplayMode;
2205 if ( theMode != -1 ) {
2206 myDisplayMode = theMode;
2207 myHasDisplayMode = true;
2215 int GEOM_Displayer::GetDisplayMode() const
2217 return myDisplayMode;
2220 int GEOM_Displayer::UnsetDisplayMode()
2222 int aPrevMode = myDisplayMode;
2223 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2224 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2225 myHasDisplayMode = false;
2229 bool GEOM_Displayer::HasDisplayMode() const
2231 return myHasDisplayMode;
2234 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2236 static QList<QColor> colors;
2238 if ( colors.isEmpty() ) {
2240 for (int s = 0; s < 2 ; s++)
2242 for (int v = 100; v >= 40; v = v - 20)
2244 for (int h = 0; h < 359 ; h = h + 60)
2246 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2252 static int currentColor = 0;
2254 SALOMEDS::Color color;
2255 color.R = (double)colors[currentColor].red() / 255.0;
2256 color.G = (double)colors[currentColor].green() / 255.0;
2257 color.B = (double)colors[currentColor].blue() / 255.0;
2259 currentColor = (currentColor+1) % colors.count();
2264 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2267 int aTolerance = 64;
2268 int anIterations = 0;
2274 if( anIterations % aPeriod == 0 )
2277 if( aTolerance < 1 )
2280 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2282 aHue = (int)( 360.0 * rand() / RAND_MAX );
2283 //std::cout << "Hue = " << aHue << std::endl;
2285 //std::cout << "Auto colors : ";
2287 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2288 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2289 for( ; it != itEnd; ++it )
2291 SALOMEDS::Color anAutoColor = *it;
2292 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2295 aQColor.getHsv( &h, &s, &v );
2296 //std::cout << h << " ";
2297 if( abs( h - aHue ) < aTolerance )
2300 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2304 //std::cout << std::endl;
2310 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2312 aColor.setHsv( aHue, 255, 255 );
2314 SALOMEDS::Color aSColor;
2315 aSColor.R = (double)aColor.red() / 255.0;
2316 aSColor.G = (double)aColor.green() / 255.0;
2317 aSColor.B = (double)aColor.blue() / 255.0;
2322 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2323 const QString& entry,
2326 // get default properties for the explicitly specified default view type
2327 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2329 if ( study && view ) {
2330 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2331 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2332 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2334 if ( viewModel && viewId != -1 ) {
2335 // get properties from the study
2336 PropMap storedMap = study->getObjectPropMap( viewId, entry );
2337 // overwrite default properties from stored ones (that are specified)
2338 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2339 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2340 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2341 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2343 // ... specific processing for color
2344 // ... current implementation is to use same stored color for all aspects
2345 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2346 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2347 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2348 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2349 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2350 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2351 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2354 if ( !entry.isEmpty() ) {
2355 // get CORBA reference to geom object
2356 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2358 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2359 if ( !CORBA::is_nil( object ) ) {
2360 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2361 if ( !CORBA::is_nil( geomObject ) ) { // to check
2362 // check that geom object has color properly set
2363 bool hasColor = false;
2364 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2365 // set color from geometry object (only once, if it is not yet set in GUI)
2366 // current implementation is to use same color for all aspects
2367 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2368 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2369 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2370 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2371 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2372 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2373 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2374 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2376 // check that object has point marker properly set
2377 GEOM::marker_type mType = geomObject->GetMarkerType();
2378 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2379 int mTextureId = geomObject->GetMarkerTexture();
2380 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2381 ( mType == GEOM::MT_USER && mTextureId > 0 );
2382 // set point marker from geometry object (only once, if it is not yet set in GUI)
2383 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2384 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2386 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2387 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2389 else if ( mType == GEOM::MT_USER ) {
2391 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2403 PropMap GEOM_Displayer::getDefaultPropertyMap()
2407 // get resource manager
2408 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2410 // fill in the properties map with default values
2412 // - visibility (false by default)
2413 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2415 // - nb isos (take default value from preferences)
2416 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2417 QString( "%1%2%3" ).
2418 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2419 arg( GEOM::subSectionSeparator() ).
2420 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2422 // - transparency (opacity = 1-transparency)
2423 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2424 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2426 // - display mode (take default value from preferences)
2427 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2428 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2430 // - show edges direction flag (false by default)
2431 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2433 // - show vertices flag (false by default)
2434 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2436 // - shading color (take default value from preferences)
2437 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2438 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2440 // - wireframe color (take default value from preferences)
2441 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2442 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2444 // - standalone edges color (take default value from preferences)
2445 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2446 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2448 // - free boundaries color (take default value from preferences)
2449 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2450 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2452 // - points color (take default value from preferences)
2453 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2454 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2456 // - isos color (take default value from preferences)
2457 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2458 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2460 // - outlines color (take default value from preferences)
2461 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2462 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2464 // - deflection coefficient (take default value from preferences)
2465 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2466 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2468 // - material (take default value from preferences)
2469 Material_Model material;
2470 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2471 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2473 // - edge width (take default value from preferences)
2474 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2475 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2477 // - isos width (take default value from preferences)
2478 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2479 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2481 // - point marker (take default value from preferences)
2482 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2483 QString( "%1%2%3" ).
2484 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2485 arg( GEOM::subSectionSeparator() ).
2486 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2488 // - top-level flag (false by default)
2489 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2494 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2495 SALOMEDS::Color aSColor;
2498 SUIT_Session* session = SUIT_Session::session();
2499 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2501 if ( app && !theGeomObject->_is_nil()) {
2502 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2505 _PTR(Study) aStudy = study->studyDS();
2506 aSColor = theGeomObject->GetColor();
2507 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2509 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2510 bool general_autocolor = true;
2511 #else // auto-color for groups only
2512 bool general_autocolor = false;
2513 #endif // GENERAL_AUTOCOLOR
2514 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2515 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2516 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2517 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2518 aSColor = getPredefinedUniqueColor();
2520 #else // old algorithm for auto-colors
2521 QList<SALOMEDS::Color> aReservedColors;
2522 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2523 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2524 if ( aMainSObject ) {
2525 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2526 for ( ; it->More(); it->Next() ) {
2527 _PTR(SObject) aChildSObject( it->Value() );
2528 GEOM::GEOM_Object_var aChildObject =
2529 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2530 if ( CORBA::is_nil( aChildObject ) )
2533 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2534 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2535 aReservedColors.append( aReservedColor );
2538 aSColor = getUniqueColor( aReservedColors );
2540 #endif // SIMPLE_AUTOCOLOR
2550 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2551 const bool eraseOnlyChildren) {
2552 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2556 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2560 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2565 // Erase from all views
2566 QList<SALOME_View*> views;
2568 ViewManagerList vmans = app->viewManagers();
2569 SUIT_ViewManager* vman;
2570 foreach ( vman, vmans ) {
2571 SUIT_ViewModel* vmod = vman->getViewModel();
2572 view = dynamic_cast<SALOME_View*> ( vmod );
2574 views.append( view );
2577 if( views.count() == 0 )
2580 //Erase childrens w/o update views
2581 DataObjectList listObj = parent->children( true );
2582 SUIT_DataObject* obj;
2583 foreach( obj, listObj ) {
2584 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2586 foreach ( view, views ) {
2587 Handle(SALOME_InteractiveObject) anIO =
2588 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2589 Erase(anIO, false, false, view);
2593 //Erase parent with view update or repaint views
2594 foreach ( view, views ) {
2595 if(!eraseOnlyChildren)
2596 Erase(theIO, false, true, view);
2602 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2604 if( theGeomFieldStep->_is_nil() )
2607 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2608 if( aGeomField->_is_nil() )
2611 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2612 if( aGeomFieldShape->_is_nil() )
2615 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2616 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2617 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2619 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2621 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2623 int aFieldDimension = aGeomField->GetDimension();
2625 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2626 int aFieldNbComponents = aFieldComponents->length();
2628 QList<QVariant> aFieldStepData;
2629 if( aFieldDataType == GEOM::FDT_Bool )
2631 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2632 if ( !aGeomBoolFieldStep->_is_nil() )
2634 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2635 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2636 aFieldStepData << (bool)aValues[i];
2639 else if( aFieldDataType == GEOM::FDT_Int )
2641 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2642 if ( !aGeomIntFieldStep->_is_nil() )
2644 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2645 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2646 aFieldStepData << (qlonglong)aValues[i];
2649 else if( aFieldDataType == GEOM::FDT_Double )
2651 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2652 if ( !aGeomDoubleFieldStep->_is_nil() )
2654 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2655 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2656 aFieldStepData << (double)aValues[i];
2659 else if( aFieldDataType == GEOM::FDT_String )
2661 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2662 if ( !aGeomStringFieldStep->_is_nil() )
2664 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2665 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2666 aFieldStepData << QString( aValues[i] );
2670 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2671 aFieldStepData = groupFieldData( aFieldStepData,
2673 aFieldDataType == GEOM::FDT_String,
2675 aFieldStepRangeMax );
2677 setFieldStepInfo( aFieldDataType,
2682 aFieldStepRangeMax );
2685 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2686 const int theFieldNbComponents,
2687 const bool theIsString,
2688 double& theFieldStepRangeMin,
2689 double& theFieldStepRangeMax )
2691 QList<QVariant> aResultList;
2692 theFieldStepRangeMin = 0;
2693 theFieldStepRangeMax = 0;
2695 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2698 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2700 QList<QVariant> aGroupedList;
2702 bool anIsBoolean = false;
2703 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2706 QStringList aStringList;
2708 int aBaseIndex = aSubShape * theFieldNbComponents;
2709 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2711 int anIndex = aComponent + aBaseIndex;
2713 const QVariant& aVariant = theFieldStepData[ anIndex ];
2716 if( aVariant.type() == QVariant::String )
2717 aStringList << aVariant.toString();
2722 if( aVariant.type() == QVariant::Bool )
2724 aValue = aVariant.toBool() ? 1.0 : 0.0;
2730 if( aVariant.type() == QVariant::LongLong )
2731 aValue = double( aVariant.toLongLong() );
2732 else if( aVariant.type() == QVariant::Double )
2733 aValue = aVariant.toDouble();
2734 aNorm += aValue * aValue;
2740 aGroupedList << aStringList.join( "\n" );
2744 aNorm /= theFieldNbComponents;
2746 aNorm = pow( aNorm, 0.5 );
2748 if( aGroupedList.isEmpty() )
2749 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2752 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2753 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2756 aGroupedList << aNorm;
2762 theFieldStepRangeMin = 0.0;
2763 theFieldStepRangeMax = 1.0;
2766 SUIT_Session* session = SUIT_Session::session();
2767 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2768 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2770 QListIterator<QVariant> anIter( aGroupedList );
2771 while( anIter.hasNext() )
2773 const QVariant& aVariant = anIter.next();
2775 aResultList << aVariant;
2779 Quantity_Color aColor;
2780 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2781 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2782 aResultList << aQColor;
2788 // Note: the method is copied from Aspect_ColorScale class
2789 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2790 const Standard_Integer aMin,
2791 const Standard_Integer aMax )
2793 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2795 Standard_Integer aHue = maxLimit;
2797 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2799 aHue = Min( Max( minLimit, aHue ), maxLimit );
2804 // Note: the method is copied from Aspect_ColorScale class
2805 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2806 const Standard_Real aMin,
2807 const Standard_Real aMax,
2808 const Standard_Integer ColorsCount,
2809 Quantity_Color& aColor )
2811 if( aValue<aMin || aValue>aMax || aMax<aMin )
2812 return Standard_False;
2816 Standard_Real IntervNumber = 0;
2819 else if( aValue>aMax )
2820 IntervNumber = ColorsCount-1;
2821 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2822 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2824 Standard_Integer Interv = Standard_Integer( IntervNumber );
2826 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2828 return Standard_True;
2832 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2834 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2838 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2842 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2843 if( aViewer.IsNull() )
2846 aViewer->InitActiveViews();
2847 if( !aViewer->MoreActiveViews() )
2850 Handle(V3d_View) aView = aViewer->ActiveView();
2851 if( aView.IsNull() )
2854 Standard_Boolean anIsDisplayColorScale = Standard_False;
2855 TCollection_AsciiString aColorScaleTitle;
2856 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2857 Standard_Boolean anIsBoolean = Standard_False;
2859 SALOME_ListIO aSelectedObjects;
2860 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2861 if( aSelectedObjects.Extent() == 1 )
2863 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2864 if( !anIO.IsNull() )
2866 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2869 AIS_ListOfInteractive aList;
2870 aPrs->GetObjects( aList );
2871 AIS_ListIteratorOfListOfInteractive anIter( aList );
2872 for( ; anIter.More(); anIter.Next() )
2874 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2875 if( !aShape.IsNull() )
2877 GEOM::field_data_type aFieldDataType;
2878 int aFieldDimension;
2879 QList<QVariant> aFieldStepData;
2880 TCollection_AsciiString aFieldStepName;
2881 double aFieldStepRangeMin, aFieldStepRangeMax;
2882 aShape->getFieldStepInfo( aFieldDataType,
2887 aFieldStepRangeMax );
2888 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2890 anIsDisplayColorScale = Standard_True;
2891 aColorScaleTitle = aFieldStepName;
2892 aColorScaleMin = aFieldStepRangeMin;
2893 aColorScaleMax = aFieldStepRangeMax;
2894 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2902 if( anIsDisplayColorScale )
2904 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2905 if( !aColorScale.IsNull() )
2907 SUIT_Session* session = SUIT_Session::session();
2908 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2910 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2911 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2912 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2913 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2914 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2915 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2917 aColorScale->SetXPosition( anXPos );
2918 aColorScale->SetYPosition( anYPos );
2919 aColorScale->SetWidth( aWidth );
2920 aColorScale->SetHeight( aHeight );
2922 aColorScale->SetTextHeight( aTextHeight );
2923 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2925 aColorScale->SetTitle( aColorScaleTitle );
2926 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2928 if( !aView->ColorScaleIsDisplayed() )
2929 aView->ColorScaleDisplay();
2933 if( aView->ColorScaleIsDisplayed() )
2934 aView->ColorScaleErase();
2937 if( theIsRedisplayFieldSteps )
2939 _PTR(Study) aStudyDS = aStudy->studyDS();
2940 QList<SUIT_ViewManager*> vmList;
2941 myApp->viewManagers( vmList );
2942 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2944 if( SUIT_ViewManager* aViewManager = *vmIt )
2946 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2947 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2949 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2952 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2953 if( !CORBA::is_nil( anObject ) )
2955 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2956 if( !aFieldStep->_is_nil() )
2958 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2959 Handle(SALOME_InteractiveObject) aStepIO =
2960 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2961 Redisplay( aStepIO, false, false );