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>
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 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
126 #include <TColStd_HArray1OfByte.hxx>
128 #include <Graphic3d_HArray1OfBytes.hxx>
131 // If the next macro is defined, autocolor feature works for all sub-shapes;
132 // if it is undefined, autocolor feature works for groups only
133 #define GENERAL_AUTOCOLOR
134 // Below macro, when uncommented, switches on simplified (more performant) algorithm
135 // of auto-color picking up
136 #define SIMPLE_AUTOCOLOR
138 // Hard-coded value of shape deflection coefficient for VTK viewer
139 const double VTK_MIN_DEFLECTION = 0.001;
141 #if OCC_VERSION_LARGE > 0x06070000
142 // Pixmap caching support
145 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
146 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
147 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
149 static inline PixmapUsageMap& getPixmapUsageMap()
151 static PixmapUsageMap aMap;
155 static inline PixmapCacheMap& getPixmapCacheMap()
157 static PixmapCacheMap aMap;
161 //===========================================================================
162 // Function : cacheTextureFor
163 // Purpose : Load and cache image for the specified presentation.
164 //===========================================================================
165 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
166 const Handle(GEOM_AISShape)& theShape )
168 if ( thePath.isEmpty() )
171 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
172 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
174 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
175 if ( !aPixmap.IsNull() ) {
176 // point that the texture is used by the presentation
177 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
178 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
180 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
185 // convert texture to compatible image format
186 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
187 if ( anImage.isNull() )
190 aPixmap = new Image_PixMap();
191 aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() );
192 aPixmap->SetTopDown( Standard_True );
194 const uchar* aImageBytes = anImage.bits();
196 for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) {
197 Image_ColorBGRA* aPixmapBytes = aPixmap->EditData<Image_ColorBGRA>().ChangeRow(aLine);
\r
199 // convert pixels from ARGB to renderer-compatible RGBA
\r
200 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
201 aPixmapBytes->b() = (Standard_Byte) *aImageBytes++;
202 aPixmapBytes->g() = (Standard_Byte) *aImageBytes++;
203 aPixmapBytes->r() = (Standard_Byte) *aImageBytes++;
204 aPixmapBytes->a() = (Standard_Byte) *aImageBytes++;
209 aPixmapCacheMap.insert( thePath, aPixmap );
211 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
212 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
214 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
219 //===========================================================================
220 // Function : releaseTextures
221 // Purpose : Releases cached textures found for the specified presentation.
222 //===========================================================================
223 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
225 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
227 AIS_ListOfInteractive aListOfIO;
229 anOccPrs->GetObjects( aListOfIO );
231 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
233 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
234 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
236 for ( ; aIterateIO.More(); aIterateIO.Next() )
238 Handle(GEOM_AISShape) aAISShape =
239 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
241 if ( aAISShape.IsNull() )
244 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
245 if ( aPixmap.IsNull() )
248 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
251 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
253 aUsersShapes.Remove( aAISShape );
255 if ( aUsersShapes.IsEmpty() ) {
256 aPixmapUsersMap.UnBind( aPixmap );
257 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
264 //================================================================
265 // Function : getActiveStudy
266 // Purpose : Get active study, returns 0 if no open study frame
267 //================================================================
268 static inline SalomeApp_Study* getActiveStudy()
270 SUIT_Session* session = SUIT_Session::session();
271 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
273 return ( SalomeApp_Study* )app->activeStudy();
277 static inline int getViewManagerId( SALOME_View* theViewFrame) {
278 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
279 SUIT_ViewManager* aViewMgr = 0;
281 aViewMgr = aModel->getViewManager();
282 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
285 //================================================================
286 // Function : getTopAbsMode
287 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
288 // one from GEOMImpl_Types.h
289 //================================================================
290 static inline int getTopAbsMode( const int implType )
294 case GEOM_COMPOUND : return TopAbs_COMPOUND;
295 case GEOM_SOLID : return TopAbs_SOLID;
296 case GEOM_SHELL : return TopAbs_SHELL;
297 case GEOM_FACE : return TopAbs_FACE;
298 case GEOM_WIRE : return TopAbs_WIRE;
299 case GEOM_EDGE : return TopAbs_EDGE;
300 case GEOM_POINT : return TopAbs_VERTEX;
305 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
307 if ( shape.IsNull() )
310 int ret = shape.ShapeType();
312 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
313 TopoDS_Iterator it(shape, Standard_True, Standard_False);
314 for (; it.More(); it.Next()) {
315 TopoDS_Shape sub_shape = it.Value();
316 if ( sub_shape.IsNull() ) continue;
317 int stype = getMinMaxShapeType( sub_shape, ismin );
318 if ( stype == TopAbs_SHAPE ) continue;
319 if ( ismin && stype > ret )
321 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
329 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
331 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
334 //================================================================
335 // Function : getFilter
336 // Purpose : Get filter corresponding to the type of object
337 // from GEOMImpl_Types.h
338 //================================================================
339 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
341 SUIT_SelectionFilter* aFilter;
343 int aTopAbsMode = getTopAbsMode( theMode );
344 if ( aTopAbsMode != -1 )
345 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
349 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
350 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
352 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
353 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
354 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
355 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
356 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
357 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
359 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
361 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
362 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
364 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
370 //================================================================
371 // Function : getComplexFilter
372 // Purpose : Get compound filter corresponding to the type of
373 // object from GEOMImpl_Types.h
374 //================================================================
375 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
377 GEOM_CompoundFilter* aFilter;
379 if(aSubShapes != NULL ) {
380 aFilter = new GEOM_CompoundFilter(getStudy());
381 QList<int> aTopAbsTypes;
382 QList<int>::const_iterator it;
383 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
384 int topAbsMode = getTopAbsMode(*it);
385 if(topAbsMode != -1 )
386 aTopAbsTypes.append(topAbsMode);
388 aFilter->addSubTypes(aTopAbsTypes);
394 //================================================================
395 // Function : getEntry
397 //================================================================
398 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
400 SUIT_Session* session = SUIT_Session::session();
401 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
404 CORBA::String_var IOR = app->orb()->object_to_string( object );
405 if ( strcmp(IOR.in(), "") != 0 )
407 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
408 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
416 //================================================================
417 // Function : getName
419 //================================================================
420 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
422 SUIT_Session* session = SUIT_Session::session();
423 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
426 CORBA::String_var IOR = app->orb()->object_to_string( object );
427 if ( strcmp(IOR.in(), "") != 0 )
429 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
430 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
432 _PTR(GenericAttribute) anAttr;
434 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
436 _PTR(AttributeName) aNameAttr( anAttr );
437 return aNameAttr->Value();
445 //=================================================================
447 * GEOM_Displayer::GEOM_Displayer
450 //=================================================================
451 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
454 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
459 SUIT_Session* session = SUIT_Session::session();
460 SUIT_ResourceMgr* resMgr = session->resourceMgr();
462 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
463 myShadingColor = SalomeApp_Tools::color( col );
465 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
466 myHasDisplayMode = false;
468 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
469 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
470 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
472 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
473 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
474 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
477 // This color is used for shape displaying. If it is equal -1 then
478 // default color is used.
483 myTransparency = -1.0;
485 // This parameter is used for activisation/deactivisation of objects to be displayed
487 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
488 // Activate parallel vizualisation only for testing purpose
489 // and if the corresponding env variable is set to 1
490 char* parallel_visu = getenv("PARALLEL_VISU");
491 if (parallel_visu && atoi(parallel_visu))
493 MESSAGE("Parallel visualisation on");
494 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
500 myFieldDataType = GEOM::FDT_Double;
501 myFieldDimension = 0;
502 myFieldStepRangeMin = 0;
503 myFieldStepRangeMax = 0;
506 //=================================================================
508 * GEOM_Displayer::~GEOM_Displayer
511 //=================================================================
512 GEOM_Displayer::~GEOM_Displayer()
516 //=================================================================
518 * GEOM_Displayer::Display
519 * Display interactive object in the current viewer
521 //=================================================================
522 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
523 const bool updateViewer,
524 SALOME_View* theViewFrame )
526 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
529 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
533 vf->BeforeDisplay( this, prs );
535 vf->AfterDisplay( this, prs );
540 int aMgrId = getViewManagerId(vf);
541 SalomeApp_Study* aStudy = getStudy();
542 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
544 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
546 delete prs; // delete presentation because displayer is its owner
551 //=================================================================
553 * GEOM_Displayer::Display
554 * This overloaded Display() method can be useful for operations
555 * not using dialog boxes.
557 //=================================================================
558 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
560 if ( theObj->_is_nil() )
563 std::string entry = getEntry( theObj );
565 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
570 //=================================================================
572 * GEOM_Displayer::Erase
573 * Erase interactive object in the current viewer
575 //=================================================================
576 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
578 const bool updateViewer,
579 SALOME_View* theViewFrame )
581 if ( theIO.IsNull() )
584 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
587 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
589 vf->BeforeErase( this, prs );
590 vf->Erase( prs, forced );
591 vf->AfterErase( this, prs );
594 delete prs; // delete presentation because displayer is its owner
596 int aMgrId = getViewManagerId(vf);
597 SalomeApp_Study* aStudy = getStudy();
598 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
600 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
605 //=================================================================
607 * GEOM_Displayer::Erase
608 * Erase geometry object in the current viewer
610 //=================================================================
611 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
613 const bool updateViewer,
614 SALOME_View* theViewFrame)
616 std::string entry = getEntry( theObj );
619 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
620 forced, updateViewer, theViewFrame);
624 //=================================================================
626 * GEOM_Displayer::Redisplay
627 * Redisplay (erase and then display again) interactive object
628 * in the current viewer
630 //=================================================================
631 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
632 const bool updateViewer,
633 const bool checkActiveViewer )
635 // Remove the object permanently (<forced> == true)
636 SUIT_Session* ses = SUIT_Session::session();
637 SUIT_Application* app = ses->activeApplication();
640 SUIT_Desktop* desk = app->desktop();
641 QList<SUIT_ViewWindow*> wnds = desk->windows();
642 SUIT_ViewWindow* wnd;
643 QListIterator<SUIT_ViewWindow*> it( wnds );
644 while ( it.hasNext() && (wnd = it.next()) )
646 SUIT_ViewManager* vman = wnd->getViewManager();
649 SUIT_ViewModel* vmodel = vman->getViewModel();
652 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
655 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
657 Redisplay( theIO, updateViewer, view );
666 //=================================================================
668 * GEOM_Displayer::Redisplay
669 * Redisplay (erase and then display again) interactive object
670 * in the specified view
672 //=================================================================
673 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
674 const bool theUpdateViewer,
675 SALOME_View* theViewFrame )
677 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
683 Erase( theIO, true, false, theViewFrame );
684 Display( theIO, theUpdateViewer, theViewFrame );
687 //=================================================================
689 * GEOM_Displayer::Display
690 * Calls Display() method for each object in the given list
692 //=================================================================
693 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
695 SALOME_ListIteratorOfListIO Iter( theIOList );
696 for ( ; Iter.More(); Iter.Next() ) {
697 Display( Iter.Value(), false );
703 Quantity_Color GEOM_Displayer::qColorFromResources( 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 SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
710 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
712 // VSR: this method can be improved in future:
713 // to improve performance, the default values from resource manager should be cached in the displayer
714 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
717 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
719 // check that shape is not null
720 if ( AISShape.IsNull() ) return;
722 // check that study is active
723 SalomeApp_Study* study = getStudy();
724 if ( !study ) return;
726 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
727 !TopoDS_Iterator(myShape).More() )
728 return; // NPAL15983 (Bug when displaying empty groups)
730 // set interactive object
732 Handle( SALOME_InteractiveObject ) anIO;
734 if ( !myIO.IsNull() ) {
735 AISShape->setIO( myIO );
736 AISShape->SetOwner( myIO );
739 else if ( !myName.empty() ) {
740 // workaround to allow selection of temporary objects
741 static int tempId = 0;
742 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
743 AISShape->setIO( anIO );
744 AISShape->SetOwner( anIO );
747 // flag: only vertex or compound of vertices is processed (specific handling)
748 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
749 // presentation study entry (empty for temporary objects like preview)
750 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
751 // flag: temporary object
752 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
753 // currently active view window's ID (-1 if no active view)
754 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
756 // get presentation properties
757 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
759 // Temporary staff: vertex must be infinite for correct visualization
760 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
763 Material_Model material;
764 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
766 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
767 // - set front material properties
768 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
769 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
770 // - set back material properties
771 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
772 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
773 // - switch to default (both sides) facing mode
774 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
780 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
781 // we set it to the shape not taking into account material properties
782 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
784 else if ( !material.isPhysical() ) {
785 // shading color from properties is used only for non-physical materials
786 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
790 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
791 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
792 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
793 AISShape->Attributes()->SetLineAspect( anAspect );
795 // - unfree boundaries color
796 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
797 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
798 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
799 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
801 // - free boundaries color
802 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
803 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
804 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
805 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
807 // - standalone edges color
808 anAspect = AISShape->Attributes()->WireAspect();
809 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
810 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
811 AISShape->Attributes()->SetWireAspect( anAspect );
813 // - color for edges in shading+edges mode
814 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
817 AISShape->storeBoundaryColors();
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 // set display vectors flag
827 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
830 if( HasTransparency() ) {
831 AISShape->SetTransparency( GetTransparency() );
833 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
836 // set iso properties
837 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
838 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
839 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
840 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
841 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
842 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
843 uIsoAspect->SetColor( isosColor );
844 uIsoAspect->SetWidth( isosWidth );
845 uIsoAspect->SetNumber( uIsos );
846 vIsoAspect->SetColor( isosColor );
847 vIsoAspect->SetWidth( isosWidth );
848 vIsoAspect->SetNumber( vIsos );
849 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
850 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
852 // set deflection coefficient
853 // ... to avoid to small values of the coefficient, its lower value is limited
854 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
858 if ( HasTexture() ) {
859 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
860 aImagePath = GetTexture().c_str();
861 if ( ! entry.isEmpty() ) {
862 // check that study is active
863 SalomeApp_Study* study = getActiveStudy();
865 // Store the texture in object properties for next displays
866 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
867 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
869 // Update porpeties map
870 propMap = getObjectProperties( study, entry, myViewFrame );
875 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
878 if ( !aImagePath.isEmpty() ) {
879 #if OCC_VERSION_LARGE > 0x06070000
880 Handle(Image_PixMap) aPixmap = cacheTextureFor( aImagePath, AISShape );
882 // apply image to shape
883 if ( !aPixmap.IsNull() ) {
884 AISShape->SetTexturePixMap( aPixmap );
885 AISShape->SetTextureMapOn();
886 AISShape->DisableTextureModulate();
889 AISShape->SetTextureMapOff();
891 AISShape->SetTextureFileName( TCollection_AsciiString( aImagePath.toUtf8().constData() ) );
892 AISShape->SetTextureMapOn();
893 AISShape->DisableTextureModulate();
897 AISShape->SetTextureMapOff();
900 AISShape->SetWidth( HasWidth() ?
901 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
903 // libe width from properties
904 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
906 // set top-level flag
907 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
909 // set point marker (for vertex / compound of vertices only)
911 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
912 if ( aList.size() == 2 ) {
913 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
914 int aTypeOfMarker = aList[0].toInt();
915 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
916 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
917 anAspect->SetScale( aScaleOfMarker );
918 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
919 anAspect->SetColor( HasColor() ?
920 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
921 (Quantity_NameOfColor)GetColor() :
922 // color from properties
923 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
924 AISShape->Attributes()->SetPointAspect( anAspect );
926 else if ( aList.size() == 1 ) {
927 // custom marker string contains "IdOfTexture"
928 int textureId = aList[0].toInt();
929 Standard_Integer aWidth, aHeight;
930 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
931 Handle(TColStd_HArray1OfByte) aTexture =
933 Handle(Graphic3d_HArray1OfBytes) aTexture =
935 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
936 if ( !aTexture.IsNull() ) {
937 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
938 Handle(Prs3d_PointAspect) aTextureAspect =
939 new Prs3d_PointAspect( HasColor() ?
940 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
941 (Quantity_NameOfColor)GetColor() :
942 // color from properties
943 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
948 Handle(Prs3d_PointAspect) aTextureAspect =
949 new Prs3d_PointAspect( HasColor() ?
950 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
951 (Quantity_NameOfColor)GetColor() :
952 // color from properties
953 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
958 AISShape->Attributes()->SetPointAspect( aTextureAspect );
963 // set field step data
964 AISShape->setFieldStepInfo( myFieldDataType,
969 myFieldStepRangeMax );
971 if ( create && !isTemporary && aMgrId != -1 ) {
972 // set properties to the study
973 study->setObjectPropMap( aMgrId, entry, propMap );
976 // AISShape->SetName(???); ??? necessary to set name ???
979 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
981 // check that actor is not null
982 if ( !actor ) return;
984 // check that study is active
985 SalomeApp_Study* study = getStudy();
986 if ( !study ) return;
988 // set interactive object
990 Handle( SALOME_InteractiveObject ) anIO;
992 if ( !myIO.IsNull() ) {
993 actor->setIO( myIO );
996 else if ( !myName.empty() ) {
997 // workaround to allow selection of temporary objects
998 static int tempId = 0;
999 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1000 actor->setIO( anIO );
1003 // presentation study entry (empty for temporary objects like preview)
1004 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1005 // flag: temporary object
1006 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1007 // currently active view window's ID (-1 if no active view)
1008 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1010 // get presentation properties
1011 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1014 /////////////////////////////////////////////////////////////////////////
1015 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1016 // due to performance problem
1017 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1018 /////////////////////////////////////////////////////////////////////////
1019 if ( !actor->getTopo().IsSame( myShape ) )
1020 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1023 Material_Model material;
1024 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1025 std::vector<vtkProperty*> mprops;
1026 mprops.push_back( material.getMaterialVTKProperty( true ) );
1027 mprops.push_back( material.getMaterialVTKProperty( false) );
1028 actor->SetMaterial( mprops );
1030 // set iso-lines properties
1032 // - set number of iso-lines
1033 int nbIsos[2]= { 1, 1 };
1034 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1035 nbIsos[0] = isos[0].toInt();
1036 nbIsos[1] = isos[1].toInt();
1037 actor->SetNbIsos( nbIsos );
1039 // - set iso-lines width
1040 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1042 // - set iso-lines color
1043 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1044 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1049 // - same color for all sub-actors
1050 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1051 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1054 // shading color (for non-physical materials)
1055 if ( !material.isPhysical() ) {
1056 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1057 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1058 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1061 // - standalone edge color
1062 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1063 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1065 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1066 // - shared edges color ???
1067 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1069 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1070 // - free edges color ???
1071 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1074 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1075 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1078 // - color for edges in shading+edges mode
1079 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1080 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1083 if( HasTransparency() ) {
1084 actor->SetOpacity( 1.0 - GetTransparency() );
1086 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1090 actor->SetWidth( HasWidth() ?
1091 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1093 // libe width from properties
1094 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1096 // set display vectors flag
1097 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1100 int displayMode = HasDisplayMode() ?
1101 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1103 // display mode from properties
1104 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1106 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1107 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1108 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1109 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1111 if ( displayMode == 2 )
1112 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1113 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1115 actor->setDisplayMode( displayMode );
1118 actor->PickableOn();
1120 actor->PickableOff();
1122 if ( create && !isTemporary && aMgrId != -1 ) {
1123 // set properties to the study
1124 study->setObjectPropMap( aMgrId, entry, propMap );
1128 //=================================================================
1130 * GEOM_Displayer::updateDimensions
1131 * Creates or renews dimension presentation for the IO.
1133 //=================================================================
1134 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1135 SALOME_OCCPrs* thePrs,
1136 const gp_Ax3& theShapeLCS )
1138 SalomeApp_Study* aStudy = getStudy();
1144 if ( theIO.IsNull() )
1149 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1151 AIS_ListOfInteractive aListOfIO;
1153 anOccPrs->GetObjects( aListOfIO );
1155 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1157 // remove outdated presentations of dimensions
1158 for ( ; aIterateIO.More(); aIterateIO.Next() )
1160 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1161 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1166 aListOfIO.Remove( aIterateIO );
1168 if ( !aIterateIO.More() )
1174 // prepare dimension styling
1175 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1177 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1178 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1179 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1180 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1181 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1182 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1183 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1185 // restore dimension presentation from saved attribute or property data
1186 AIS_ListOfInteractive aRestoredDimensions;
1188 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1190 GEOM::propertyName( GEOM::Dimensions ),
1193 GEOMGUI_DimensionProperty aRecords;
1195 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1197 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1201 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1204 // create up-to-date dimension presentations
1205 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1207 if ( !aRecords.IsVisible( aPrsIt ) )
1212 // init dimension by type
1213 Handle(AIS_Dimension) aPrs;
1214 switch( aRecords.GetType( aPrsIt ) )
1216 case GEOMGUI_DimensionProperty::DimensionType_Length :
1218 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1219 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1224 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1226 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1227 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1232 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1234 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1235 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1241 aPrs->SetOwner( theIO );
1243 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1245 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1247 aStyle->SetCommonColor( aColor );
1248 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1249 aStyle->MakeText3d( Standard_True );
1250 aStyle->MakeTextShaded( Standard_True );
1251 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1252 aStyle->TextAspect()->SetHeight( aFontHeight );
1253 aStyle->ArrowAspect()->SetLength( anArrowLength );
1254 aStyle->LineAspect()->SetWidth( aLineWidth );
1255 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1256 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1257 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1258 aPrs->SetDimensionAspect( aStyle );
1259 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1260 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1261 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1263 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1265 // show degree symbol for dimension instead of label "deg"
1266 if ( aUnitsAngle == "deg" )
1268 aPrs->SetSpecialSymbol(0xB0);
1269 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1270 aStyle->MakeUnitsDisplayed(Standard_False);
1274 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1275 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1280 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1283 aListOfIO.Append( aPrs );
1286 // update presentation
1289 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1291 anOccPrs->AddObject( aIterateIO.Value() );
1295 //=================================================================
1297 * GEOM_Displayer::Erase
1298 * Calls Erase() method for each object in the given list
1300 //=================================================================
1301 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1303 const bool updateViewer )
1305 SALOME_ListIteratorOfListIO Iter( theIOList );
1306 for ( ; Iter.More(); Iter.Next() )
1307 Erase( Iter.Value(), forced, false );
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 updateViewer,
1321 const bool checkActiveViewer )
1323 SALOME_ListIteratorOfListIO Iter( theIOList );
1324 for ( ; Iter.More(); Iter.Next() )
1325 Redisplay( Iter.Value(), false, checkActiveViewer );
1331 //=================================================================
1333 * GEOM_Displayer::Redisplay
1334 * Calls Redisplay() method for each object in the given list
1336 //=================================================================
1337 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1338 const bool theUpdateViewer,
1339 SALOME_View* theViewFrame )
1341 SALOME_ListIteratorOfListIO anIter( theIOList );
1342 for ( ; anIter.More(); anIter.Next() )
1344 Redisplay( anIter.Value(), false, theViewFrame );
1347 if ( theUpdateViewer )
1353 //=================================================================
1355 * GEOM_Displayer::Update
1356 * Update OCC presentaion
1357 * [ Reimplemented from SALOME_Displayer ]
1359 //=================================================================
1360 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1362 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1363 SalomeApp_Study* study = getStudy();
1365 if ( !occPrs || myShape.IsNull() || !study )
1368 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1371 // specific processing for local coordinate system presentation
1374 TopoDS_Face aFace = TopoDS::Face( myShape );
1375 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1376 if ( !aPlane.IsNull() )
1378 gp_Ax3 aPos = aPlane->Pln().Position();
1379 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1381 Handle(GEOM_AISTrihedron) aTrh;
1383 if ( occPrs->IsNull() )
1385 // new presentation is being created
1386 aTrh = new GEOM_AISTrihedron( aPlc );
1387 occPrs->AddObject( aTrh );
1391 // presentation is being updated
1392 AIS_ListOfInteractive aList;
1393 occPrs->GetObjects( aList );
1394 AIS_ListIteratorOfListOfInteractive anIter( aList );
1395 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1396 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1400 if ( !aTrh.IsNull() ) {
1401 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1403 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1404 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1406 aTrh->SetWidth( GetWidth() );
1408 if ( !myIO.IsNull() )
1410 aTrh->setIO( myIO );
1411 aTrh->SetOwner( myIO );
1413 aTrh->SetComponent( aPlc );
1414 aTrh->SetToUpdate();
1416 occPrs->SetToActivate( ToActivate() );
1422 // processing for usual geometry presentation
1425 // if presentation is empty we try to create new one
1426 if ( occPrs->IsNull() )
1428 // create presentation (specific for vectors)
1429 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1430 : new GEOM_AISShape ( myShape, "" );
1432 if( myType == GEOM_FIELD_STEP )
1433 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1434 // update shape properties
1435 updateShapeProperties( AISShape, true );
1437 // add shape to the presentation
1438 occPrs->AddObject( AISShape );
1440 // In accordance with ToActivate() value object will be activated/deactivated
1441 // when it will be displayed
1442 occPrs->SetToActivate( ToActivate() );
1444 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1445 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1447 // create additional wireframe shape
1448 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1449 aWirePrs->SetWidth(AISShape->Width());
1450 if ( !myIO.IsNull() ) {
1451 aWirePrs->setIO( myIO );
1452 aWirePrs->SetOwner( myIO );
1455 // add shape to the presentation
1456 occPrs->AddObject( aWirePrs );
1459 // if presentation is found -> set again shape for it
1462 AIS_ListOfInteractive IOList;
1463 occPrs->GetObjects( IOList );
1464 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1465 for ( ; Iter.More(); Iter.Next() )
1467 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1468 if ( AISShape.IsNull() )
1471 // re-set shape (it might be changed)
1472 if ( AISShape->Shape() != myShape )
1473 AISShape->Set( myShape );
1475 // update shape properties
1476 updateShapeProperties( AISShape, false );
1479 AISShape->UpdateSelection();
1480 AISShape->SetToUpdate();
1484 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1488 //=================================================================
1490 * GEOM_Displayer::Update
1491 * Update VTK presentaion
1492 * [ Reimplemented from SALOME_Displayer ]
1494 //=================================================================
1495 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1497 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1498 SalomeApp_Study* study = getStudy();
1500 if ( !vtkPrs || myShape.IsNull() || !study )
1503 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1506 // specific processing for local coordinate system presentation
1509 TopoDS_Face aFace = TopoDS::Face( myShape );
1510 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1511 if ( !aPlane.IsNull() ) {
1512 gp_Ax3 aPos = aPlane->Pln().Position();
1513 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1515 GEOM_VTKTrihedron* aTrh = 0;
1517 if ( vtkPrs->IsNull() ) {
1518 // new presentation is being created
1519 aTrh = GEOM_VTKTrihedron::New();
1520 vtkPrs->AddObject( aTrh );
1523 // presentation is being updated
1524 vtkActorCollection* actors = vtkPrs->GetObjects();
1526 actors->InitTraversal();
1527 vtkActor* a = actors->GetNextActor();
1528 while ( a && !aTrh ) {
1529 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1530 a = actors->GetNextActor();
1536 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1538 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1539 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1541 #ifdef VTK_TRIHEDRON_WIDTH
1543 // VSR: currently isn't supported
1545 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1547 aTrh->SetWidth( GetWidth() );
1550 if ( !myIO.IsNull() )
1551 aTrh->setIO( myIO );
1553 aTrh->SetPlacement( aPlc );
1560 // processing for usual geometry presentation
1563 // if presentation is empty we try to create new one
1564 if ( vtkPrs->IsNull() )
1567 GEOM_Actor* actor = GEOM_Actor::New();
1568 // update actor properties
1569 updateActorProperties( actor, true );
1570 // add actor to the presentation
1571 vtkPrs->AddObject( actor );
1574 // presentation is being updated
1575 vtkActorCollection* actors = vtkPrs->GetObjects();
1577 actors->InitTraversal();
1578 vtkActor* a = actors->GetNextActor();
1580 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1582 // update actor properties
1583 updateActorProperties( actor, false );
1584 a = actors->GetNextActor();
1592 //=================================================================
1594 * GEOM_Displayer::BuildPrs
1595 * Build presentation accordint to the current viewer type
1597 //=================================================================
1598 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1600 if ( theObj->_is_nil() )
1603 myViewFrame = GetActiveView();
1604 if ( myViewFrame == 0 )
1607 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1612 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1613 myType = theObj->GetType();
1615 // Update presentation
1621 //=================================================================
1623 * GEOM_Displayer::BuildPrs
1624 * Build presentation accordint to the current viewer type
1626 //=================================================================
1627 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1629 myViewFrame = GetActiveView();
1630 if ( theShape.IsNull() || myViewFrame == 0 )
1633 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1638 setShape( theShape );
1646 //=================================================================
1648 * GEOM_Displayer::buildPresentation
1649 * Builds/finds object's presentation for the current viewer
1650 * Calls corresponding Update() method by means of double dispatch
1653 //=================================================================
1654 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1655 SALOME_View* theViewFrame )
1657 SALOME_Prs* prs = 0;
1660 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1664 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1667 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1668 theIO->setEntry( entry.toLatin1().constData() );
1669 if ( !theIO.IsNull() )
1671 // set interactive object
1673 // Find SOBject (because shape should be published previously)
1674 SUIT_Session* session = SUIT_Session::session();
1675 SUIT_Application* app = session->activeApplication();
1678 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1681 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1684 // get CORBA reference to data object
1685 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1686 if ( !CORBA::is_nil( object ) )
1688 // downcast to GEOM base object
1689 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1690 if ( !GeomBaseObject->_is_nil() )
1692 myType = GeomBaseObject->GetType();
1694 // downcast to GEOM object
1695 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1696 if ( myType == GEOM_FIELD_STEP )
1698 // get the GEOM object from the field's shape
1699 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1700 if ( !GeomFieldStep->_is_nil() )
1702 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1703 if ( !GeomField->_is_nil() )
1704 GeomObject = GeomField->GetShape();
1707 // read the field step information
1708 readFieldStepInfo( GeomFieldStep );
1711 if ( !GeomObject->_is_nil() )
1713 // finally set shape
1714 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1722 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1728 //=================================================================
1730 * GEOM_Displayer::buildSubshapePresentation
1731 * Builds/finds object's presentation for the current viewer
1732 * Calls corresponding Update() method by means of double dispatch
1733 * For not published objects (for Mantis issue 0020435)
1735 //=================================================================
1736 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1737 const QString& entry,
1738 SALOME_View* theViewFrame)
1740 SALOME_Prs* prs = 0;
1743 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1747 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1750 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1751 theIO->setEntry(entry.toLatin1().constData());
1752 if (!theIO.IsNull())
1754 // set interactive object
1756 // finally set shape
1758 myType = GEOM_SUBSHAPE;
1760 UpdatePrs(prs); // Update presentation by using of the double dispatch
1766 //=================================================================
1768 * GEOM_Displayer::internalReset
1769 * Resets internal data
1772 //=================================================================
1773 void GEOM_Displayer::internalReset()
1778 myFieldDataType = GEOM::FDT_Double;
1779 myFieldDimension = 0;
1780 myFieldStepData.clear();
1781 myFieldStepName.Clear();
1782 myFieldStepRangeMin = 0;
1783 myFieldStepRangeMax = 0;
1786 //=================================================================
1788 * GEOM_Displayer::LocalSelection
1789 * Activate selection of CAD shapes with activisation of selection
1790 * of their sub-shapes (with opened local context for OCC viewer)
1792 //=================================================================
1793 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1795 SUIT_Session* session = SUIT_Session::session();
1796 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1800 LightApp_SelectionMgr* sm = app->selectionMgr();
1802 // remove all filters from selection
1805 SALOME_View* vf = GetActiveView();
1807 if (!theIO.IsNull() && !vf->isVisible(theIO))
1809 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1810 vf->LocalSelection( prs, theMode );
1811 delete prs; // delete presentation because displayer is its owner
1815 //=================================================================
1817 * GEOM_Displayer::globalSelection
1818 * Activate selection of CAD shapes without activisation of selection
1819 * of their sub-shapes (without opened local context for OCC viewer)
1821 //=================================================================
1822 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1824 TColStd_MapOfInteger aModes;
1825 aModes.Add( theMode );
1826 GlobalSelection( aModes, update );
1829 //=================================================================
1831 * GEOM_Displayer::globalSelection
1832 * Activate selection of CAD shapes without activisation of selection
1833 * of their sub-shapes (without opened local context for OCC viewer)
1835 //=================================================================
1836 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1837 const bool update, const QList<int>* theSubShapes )
1839 SUIT_Session* session = SUIT_Session::session();
1840 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1844 SALOME_View* vf = GetActiveView();
1848 // Close local context
1849 vf->GlobalSelection( update );
1851 // Set selection filters in accordance with current mode
1852 LightApp_SelectionMgr* sm = app->selectionMgr();
1856 // Remove from selection temporary objects if necessary
1857 if ( !theModes.Contains( GEOM_PREVIEW ) )
1858 clearTemporary( sm );
1860 //@ aSel->ClearIndex();
1864 // Remove filters from AIS_InteractiveContext
1865 Handle(AIS_InteractiveContext) ic;
1866 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1869 ic = viewer->getAISContext();
1871 ic->RemoveFilters();
1874 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1877 SUIT_SelectionFilter* aFilter;
1878 if ( theModes.Extent() == 1 )
1880 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1882 if ( aMode == GEOM_COMPOUNDFILTER )
1883 aFilter = getComplexFilter( theSubShapes );
1885 aFilter = getFilter( aMode );
1887 else if ( theModes.Extent() > 1 )
1889 TColStd_MapOfInteger aTopAbsModes;
1890 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1891 QList<SUIT_SelectionFilter*> aListOfFilters;
1892 for ( ; anIter.More(); anIter.Next() )
1894 SUIT_SelectionFilter* aFilter;
1895 int aMode = anIter.Key();
1896 if ( aMode == GEOM_COMPOUNDFILTER )
1897 aFilter = getComplexFilter( theSubShapes );
1899 aFilter = getFilter( aMode );
1902 aListOfFilters.append( aFilter );
1905 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1912 sm->installFilter( aFilter );
1915 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1916 ic->AddFilter( anOCCFilter );
1921 //=================================================================
1923 * GEOM_Displayer::LocalSelection
1924 * Activate selection of CAD shapes with activisation of selection
1925 * of their sub-shapes (with opened local context for OCC viewer)
1927 //=================================================================
1928 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1930 SALOME_ListIteratorOfListIO Iter( theIOList );
1931 for ( ; Iter.More(); Iter.Next() )
1932 LocalSelection( Iter.Value(), theMode );
1935 //=================================================================
1937 * GEOM_Displayer::BeforeDisplay
1938 * Called before displaying of pars. Close local context
1939 * [ Reimplemented from SALOME_Displayer ]
1941 //=================================================================
1942 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1944 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1947 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1950 if ( ic->HasOpenedContext() )
1951 ic->CloseAllContexts();
1956 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1958 UpdateColorScale(false,false);
1961 #if OCC_VERSION_LARGE > 0x06070000
1962 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1964 LightApp_Displayer::BeforeErase( v, p );
1965 releaseTextures( p );
1969 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1971 LightApp_Displayer::AfterErase( v, p );
1972 UpdateColorScale(false,false);
1975 //=================================================================
1977 * GEOM_Displayer::SetColor
1978 * Set color for shape displaying. If it is equal -1 then default color is used.
1979 * Available values are from Quantity_NameOfColor enumeration
1981 //=================================================================
1982 void GEOM_Displayer::SetColor( const int color )
1989 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1993 int GEOM_Displayer::GetColor() const
1998 bool GEOM_Displayer::HasColor() const
2000 return myColor != -1;
2003 void GEOM_Displayer::UnsetColor()
2007 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2008 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2009 myShadingColor = SalomeApp_Tools::color( col );
2012 //=================================================================
2014 * GEOM_Displayer::SetTransparency
2015 * Set transparency for shape displaying.
2017 //=================================================================
2018 void GEOM_Displayer::SetTransparency( const double transparency )
2020 myTransparency = transparency;
2023 double GEOM_Displayer::GetTransparency() const
2025 return myTransparency;
2028 bool GEOM_Displayer::HasTransparency() const
2030 return myTransparency != -1.0;
2033 void GEOM_Displayer::UnsetTransparency()
2035 myTransparency = -1.0;
2039 //=================================================================
2041 * GEOM_Displayer::SetTexture
2042 * Set color for shape displaying. If it is equal -1 then default color is used.
2043 * Available values are from Quantity_NameOfColor enumeration
2045 //=================================================================
2046 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2048 if(texureFileName!="")
2050 myTexture = texureFileName;
2054 bool GEOM_Displayer::HasTexture() const
2056 return myTexture != "";
2059 std::string GEOM_Displayer::GetTexture() const
2064 //=================================================================
2066 * GEOM_Displayer::SetWidth
2067 * Set width of shape displaying. If it is equal -1 then default width is used.
2069 //=================================================================
2070 void GEOM_Displayer::SetWidth( const double width )
2075 double GEOM_Displayer::GetWidth() const
2080 bool GEOM_Displayer::HasWidth() const
2082 return myWidth != -1;
2085 void GEOM_Displayer::UnsetWidth()
2091 int GEOM_Displayer::GetIsosWidth() const
2096 void GEOM_Displayer::SetIsosWidth(const int width)
2098 myIsosWidth = width;
2101 bool GEOM_Displayer::HasIsosWidth() const
2103 return myIsosWidth != -1;
2107 //=================================================================
2109 * GEOM_Displayer::SetToActivate
2110 * This method is used for activisation/deactivisation of objects to be displayed
2112 //=================================================================
2113 void GEOM_Displayer::SetToActivate( const bool toActivate )
2115 myToActivate = toActivate;
2117 bool GEOM_Displayer::ToActivate() const
2119 return myToActivate;
2122 //=================================================================
2124 * GEOM_Displayer::clearTemporary
2125 * Removes from selection temporary objects
2127 //=================================================================
2128 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2130 SALOME_ListIO selected, toSelect;
2131 theSelMgr->selectedObjects( selected );
2133 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2134 Handle(SALOME_InteractiveObject) io = it.Value();
2135 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2136 toSelect.Append( it.Value() );
2139 theSelMgr->setSelectedObjects( toSelect, true );
2142 void GEOM_Displayer::SetName( const char* theName )
2147 void GEOM_Displayer::UnsetName()
2152 SalomeApp_Study* GEOM_Displayer::getStudy() const
2154 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2157 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2162 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2167 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2168 const int theFieldDimension,
2169 const QList<QVariant>& theFieldStepData,
2170 const TCollection_AsciiString& theFieldStepName,
2171 const double theFieldStepRangeMin,
2172 const double theFieldStepRangeMax )
2174 myFieldDataType = theFieldDataType;
2175 myFieldDimension = theFieldDimension;
2176 myFieldStepData = theFieldStepData;
2177 myFieldStepName = theFieldStepName;
2178 myFieldStepRangeMin = theFieldStepRangeMin;
2179 myFieldStepRangeMax = theFieldStepRangeMax;
2182 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2184 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2185 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2186 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2187 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2188 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2189 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2192 int GEOM_Displayer::SetDisplayMode( const int theMode )
2194 int aPrevMode = myDisplayMode;
2195 if ( theMode != -1 ) {
2196 myDisplayMode = theMode;
2197 myHasDisplayMode = true;
2205 int GEOM_Displayer::GetDisplayMode() const
2207 return myDisplayMode;
2210 int GEOM_Displayer::UnsetDisplayMode()
2212 int aPrevMode = myDisplayMode;
2213 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2214 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2215 myHasDisplayMode = false;
2219 bool GEOM_Displayer::HasDisplayMode() const
2221 return myHasDisplayMode;
2224 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2226 static QList<QColor> colors;
2228 if ( colors.isEmpty() ) {
2230 for (int s = 0; s < 2 ; s++)
2232 for (int v = 100; v >= 40; v = v - 20)
2234 for (int h = 0; h < 359 ; h = h + 60)
2236 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2242 static int currentColor = 0;
2244 SALOMEDS::Color color;
2245 color.R = (double)colors[currentColor].red() / 255.0;
2246 color.G = (double)colors[currentColor].green() / 255.0;
2247 color.B = (double)colors[currentColor].blue() / 255.0;
2249 currentColor = (currentColor+1) % colors.count();
2254 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2257 int aTolerance = 64;
2258 int anIterations = 0;
2264 if( anIterations % aPeriod == 0 )
2267 if( aTolerance < 1 )
2270 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2272 aHue = (int)( 360.0 * rand() / RAND_MAX );
2273 //std::cout << "Hue = " << aHue << std::endl;
2275 //std::cout << "Auto colors : ";
2277 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2278 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2279 for( ; it != itEnd; ++it )
2281 SALOMEDS::Color anAutoColor = *it;
2282 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2285 aQColor.getHsv( &h, &s, &v );
2286 //std::cout << h << " ";
2287 if( abs( h - aHue ) < aTolerance )
2290 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2294 //std::cout << std::endl;
2300 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2302 aColor.setHsv( aHue, 255, 255 );
2304 SALOMEDS::Color aSColor;
2305 aSColor.R = (double)aColor.red() / 255.0;
2306 aSColor.G = (double)aColor.green() / 255.0;
2307 aSColor.B = (double)aColor.blue() / 255.0;
2312 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2313 const QString& entry,
2316 // get default properties for the explicitly specified default view type
2317 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2319 if ( study && view ) {
2320 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2321 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2322 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2324 if ( viewModel && viewId != -1 ) {
2325 // get properties from the study
2326 PropMap storedMap = study->getObjectPropMap( viewId, entry );
2327 // overwrite default properties from stored ones (that are specified)
2328 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2329 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2330 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2331 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2333 // ... specific processing for color
2334 // ... current implementation is to use same stored color for all aspects
2335 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2336 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2337 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2338 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2339 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2340 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2341 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2344 if ( !entry.isEmpty() ) {
2345 // get CORBA reference to geom object
2346 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2348 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2349 if ( !CORBA::is_nil( object ) ) {
2350 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2351 if ( !CORBA::is_nil( geomObject ) ) { // to check
2352 // check that geom object has color properly set
2353 bool hasColor = false;
2354 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2355 // set color from geometry object (only once, if it is not yet set in GUI)
2356 // current implementation is to use same color for all aspects
2357 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2358 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2359 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2360 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2361 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2362 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2363 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2364 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2366 // check that object has point marker properly set
2367 GEOM::marker_type mType = geomObject->GetMarkerType();
2368 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2369 int mTextureId = geomObject->GetMarkerTexture();
2370 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2371 ( mType == GEOM::MT_USER && mTextureId > 0 );
2372 // set point marker from geometry object (only once, if it is not yet set in GUI)
2373 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2374 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2376 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2377 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2379 else if ( mType == GEOM::MT_USER ) {
2381 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2393 PropMap GEOM_Displayer::getDefaultPropertyMap()
2397 // get resource manager
2398 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2400 // fill in the properties map with default values
2402 // - visibility (false by default)
2403 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2405 // - nb isos (take default value from preferences)
2406 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2407 QString( "%1%2%3" ).
2408 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2409 arg( GEOM::subSectionSeparator() ).
2410 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2412 // - transparency (opacity = 1-transparency)
2413 propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2415 // - display mode (take default value from preferences)
2416 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2417 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2419 // - show edges direction flag (false by default)
2420 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2422 // - shading color (take default value from preferences)
2423 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2424 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2426 // - wireframe color (take default value from preferences)
2427 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2428 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2430 // - standalone edges color (take default value from preferences)
2431 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2432 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2434 // - free boundaries color (take default value from preferences)
2435 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2436 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2438 // - points color (take default value from preferences)
2439 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2440 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2442 // - isos color (take default value from preferences)
2443 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2444 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2446 // - outlines color (take default value from preferences)
2447 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2448 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2450 // - deflection coefficient (take default value from preferences)
2451 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2452 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2454 // - material (take default value from preferences)
2455 Material_Model material;
2456 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2457 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2459 // - edge width (take default value from preferences)
2460 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2461 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2463 // - isos width (take default value from preferences)
2464 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2465 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2467 // - point marker (take default value from preferences)
2468 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2469 QString( "%1%2%3" ).
2470 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2471 arg( GEOM::subSectionSeparator() ).
2472 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2474 // - top-level flag (false by default)
2475 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2480 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2481 SALOMEDS::Color aSColor;
2484 SUIT_Session* session = SUIT_Session::session();
2485 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2487 if ( app && !theGeomObject->_is_nil()) {
2488 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2491 _PTR(Study) aStudy = study->studyDS();
2492 aSColor = theGeomObject->GetColor();
2493 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2495 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2496 bool general_autocolor = true;
2497 #else // auto-color for groups only
2498 bool general_autocolor = false;
2499 #endif // GENERAL_AUTOCOLOR
2500 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2501 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2502 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2503 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2504 aSColor = getPredefinedUniqueColor();
2506 #else // old algorithm for auto-colors
2507 QList<SALOMEDS::Color> aReservedColors;
2508 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2509 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2510 if ( aMainSObject ) {
2511 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2512 for ( ; it->More(); it->Next() ) {
2513 _PTR(SObject) aChildSObject( it->Value() );
2514 GEOM::GEOM_Object_var aChildObject =
2515 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2516 if ( CORBA::is_nil( aChildObject ) )
2519 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2520 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2521 aReservedColors.append( aReservedColor );
2524 aSColor = getUniqueColor( aReservedColors );
2526 #endif // SIMPLE_AUTOCOLOR
2536 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2537 const bool eraseOnlyChildren) {
2538 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2542 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2546 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2551 // Erase from all views
2552 QList<SALOME_View*> views;
2554 ViewManagerList vmans = app->viewManagers();
2555 SUIT_ViewManager* vman;
2556 foreach ( vman, vmans ) {
2557 SUIT_ViewModel* vmod = vman->getViewModel();
2558 view = dynamic_cast<SALOME_View*> ( vmod );
2560 views.append( view );
2563 if( views.count() == 0 )
2566 //Erase childrens w/o update views
2567 DataObjectList listObj = parent->children( true );
2568 SUIT_DataObject* obj;
2569 foreach( obj, listObj ) {
2570 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2572 foreach ( view, views ) {
2573 Handle(SALOME_InteractiveObject) anIO =
2574 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2575 Erase(anIO, false, false, view);
2579 //Erase parent with view update or repaint views
2580 foreach ( view, views ) {
2581 if(!eraseOnlyChildren)
2582 Erase(theIO, false, true, view);
2588 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2590 if( theGeomFieldStep->_is_nil() )
2593 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2594 if( aGeomField->_is_nil() )
2597 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2598 if( aGeomFieldShape->_is_nil() )
2601 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2602 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2603 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2605 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2607 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2609 int aFieldDimension = aGeomField->GetDimension();
2611 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2612 int aFieldNbComponents = aFieldComponents->length();
2614 QList<QVariant> aFieldStepData;
2615 if( aFieldDataType == GEOM::FDT_Bool )
2617 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2618 if ( !aGeomBoolFieldStep->_is_nil() )
2620 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2621 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2622 aFieldStepData << (bool)aValues[i];
2625 else if( aFieldDataType == GEOM::FDT_Int )
2627 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2628 if ( !aGeomIntFieldStep->_is_nil() )
2630 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2631 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2632 aFieldStepData << (qlonglong)aValues[i];
2635 else if( aFieldDataType == GEOM::FDT_Double )
2637 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2638 if ( !aGeomDoubleFieldStep->_is_nil() )
2640 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2641 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2642 aFieldStepData << (double)aValues[i];
2645 else if( aFieldDataType == GEOM::FDT_String )
2647 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2648 if ( !aGeomStringFieldStep->_is_nil() )
2650 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2651 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2652 aFieldStepData << QString( aValues[i] );
2656 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2657 aFieldStepData = groupFieldData( aFieldStepData,
2659 aFieldDataType == GEOM::FDT_String,
2661 aFieldStepRangeMax );
2663 setFieldStepInfo( aFieldDataType,
2668 aFieldStepRangeMax );
2671 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2672 const int theFieldNbComponents,
2673 const bool theIsString,
2674 double& theFieldStepRangeMin,
2675 double& theFieldStepRangeMax )
2677 QList<QVariant> aResultList;
2678 theFieldStepRangeMin = 0;
2679 theFieldStepRangeMax = 0;
2681 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2684 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2686 QList<QVariant> aGroupedList;
2688 bool anIsBoolean = false;
2689 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2692 QStringList aStringList;
2694 int aBaseIndex = aSubShape * theFieldNbComponents;
2695 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2697 int anIndex = aComponent + aBaseIndex;
2699 const QVariant& aVariant = theFieldStepData[ anIndex ];
2702 if( aVariant.type() == QVariant::String )
2703 aStringList << aVariant.toString();
2708 if( aVariant.type() == QVariant::Bool )
2710 aValue = aVariant.toBool() ? 1.0 : 0.0;
2716 if( aVariant.type() == QVariant::LongLong )
2717 aValue = double( aVariant.toLongLong() );
2718 else if( aVariant.type() == QVariant::Double )
2719 aValue = aVariant.toDouble();
2720 aNorm += aValue * aValue;
2726 aGroupedList << aStringList.join( "\n" );
2730 aNorm /= theFieldNbComponents;
2732 aNorm = pow( aNorm, 0.5 );
2734 if( aGroupedList.isEmpty() )
2735 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2738 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2739 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2742 aGroupedList << aNorm;
2748 theFieldStepRangeMin = 0.0;
2749 theFieldStepRangeMax = 1.0;
2752 SUIT_Session* session = SUIT_Session::session();
2753 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2754 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2756 QListIterator<QVariant> anIter( aGroupedList );
2757 while( anIter.hasNext() )
2759 const QVariant& aVariant = anIter.next();
2761 aResultList << aVariant;
2765 Quantity_Color aColor;
2766 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2767 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2768 aResultList << aQColor;
2774 // Note: the method is copied from Aspect_ColorScale class
2775 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2776 const Standard_Integer aMin,
2777 const Standard_Integer aMax )
2779 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2781 Standard_Integer aHue = maxLimit;
2783 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2785 aHue = Min( Max( minLimit, aHue ), maxLimit );
2790 // Note: the method is copied from Aspect_ColorScale class
2791 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2792 const Standard_Real aMin,
2793 const Standard_Real aMax,
2794 const Standard_Integer ColorsCount,
2795 Quantity_Color& aColor )
2797 if( aValue<aMin || aValue>aMax || aMax<aMin )
2798 return Standard_False;
2802 Standard_Real IntervNumber = 0;
2805 else if( aValue>aMax )
2806 IntervNumber = ColorsCount-1;
2807 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2808 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2810 Standard_Integer Interv = Standard_Integer( IntervNumber );
2812 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2814 return Standard_True;
2818 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2820 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2824 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2828 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2829 if( aViewer.IsNull() )
2832 aViewer->InitActiveViews();
2833 if( !aViewer->MoreActiveViews() )
2836 Handle(V3d_View) aView = aViewer->ActiveView();
2837 if( aView.IsNull() )
2840 Standard_Boolean anIsDisplayColorScale = Standard_False;
2841 TCollection_AsciiString aColorScaleTitle;
2842 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2843 Standard_Boolean anIsBoolean = Standard_False;
2845 SALOME_ListIO aSelectedObjects;
2846 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2847 if( aSelectedObjects.Extent() == 1 )
2849 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2850 if( !anIO.IsNull() )
2852 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2855 AIS_ListOfInteractive aList;
2856 aPrs->GetObjects( aList );
2857 AIS_ListIteratorOfListOfInteractive anIter( aList );
2858 for( ; anIter.More(); anIter.Next() )
2860 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2861 if( !aShape.IsNull() )
2863 GEOM::field_data_type aFieldDataType;
2864 int aFieldDimension;
2865 QList<QVariant> aFieldStepData;
2866 TCollection_AsciiString aFieldStepName;
2867 double aFieldStepRangeMin, aFieldStepRangeMax;
2868 aShape->getFieldStepInfo( aFieldDataType,
2873 aFieldStepRangeMax );
2874 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2876 anIsDisplayColorScale = Standard_True;
2877 aColorScaleTitle = aFieldStepName;
2878 aColorScaleMin = aFieldStepRangeMin;
2879 aColorScaleMax = aFieldStepRangeMax;
2880 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2888 if( anIsDisplayColorScale )
2890 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2891 if( !aColorScale.IsNull() )
2893 SUIT_Session* session = SUIT_Session::session();
2894 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2896 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2897 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2898 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2899 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2900 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2901 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2903 aColorScale->SetXPosition( anXPos );
2904 aColorScale->SetYPosition( anYPos );
2905 aColorScale->SetWidth( aWidth );
2906 aColorScale->SetHeight( aHeight );
2908 aColorScale->SetTextHeight( aTextHeight );
2909 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2911 aColorScale->SetTitle( aColorScaleTitle );
2912 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2914 if( !aView->ColorScaleIsDisplayed() )
2915 aView->ColorScaleDisplay();
2919 if( aView->ColorScaleIsDisplayed() )
2920 aView->ColorScaleErase();
2923 if( theIsRedisplayFieldSteps )
2925 _PTR(Study) aStudyDS = aStudy->studyDS();
2926 QList<SUIT_ViewManager*> vmList;
2927 myApp->viewManagers( vmList );
2928 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2930 if( SUIT_ViewManager* aViewManager = *vmIt )
2932 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2933 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2935 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2938 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2939 if( !CORBA::is_nil( anObject ) )
2941 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2942 if( !aFieldStep->_is_nil() )
2944 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2945 Handle(SALOME_InteractiveObject) aStepIO =
2946 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2947 Redisplay( aStepIO, false, false );