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 : imageToPixmap
163 // Purpose : Concert QImage to OCCT pixmap
164 //===========================================================================
165 static inline Handle(Image_PixMap) imageToPixmap( const QImage& anImage )
167 Handle(Image_PixMap) aPixmap = new Image_PixMap();
168 if ( !anImage.isNull() ) {
169 aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() );
170 aPixmap->SetTopDown( Standard_True );
172 const uchar* aImageBytes = anImage.bits();
174 for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) {
175 Image_ColorBGRA* aPixmapBytes = aPixmap->EditData<Image_ColorBGRA>().ChangeRow(aLine);
177 // convert pixels from ARGB to renderer-compatible RGBA
178 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
179 aPixmapBytes->b() = (Standard_Byte) *aImageBytes++;
180 aPixmapBytes->g() = (Standard_Byte) *aImageBytes++;
181 aPixmapBytes->r() = (Standard_Byte) *aImageBytes++;
182 aPixmapBytes->a() = (Standard_Byte) *aImageBytes++;
190 //===========================================================================
191 // Function : getDefaultTexture
192 // Purpose : Get default texture
193 //===========================================================================
194 static inline Handle(Image_PixMap) getDefaultTexture()
196 static Handle(Image_PixMap) aPixmap;
197 if ( aPixmap.IsNull() ) {
198 QPixmap px(":images/default_texture.png");
200 aPixmap = imageToPixmap( px.toImage() );
205 //===========================================================================
206 // Function : cacheTextureFor
207 // Purpose : Load and cache image for the specified presentation.
208 //===========================================================================
209 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
210 const Handle(GEOM_AISShape)& theShape )
212 if ( thePath.isEmpty() )
215 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
216 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
218 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
219 if ( !aPixmap.IsNull() ) {
220 // point that the texture is used by the presentation
221 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
222 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
224 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
229 // convert texture to compatible image format
230 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
231 if ( anImage.isNull() )
234 aPixmap = imageToPixmap( anImage );
236 aPixmapCacheMap.insert( thePath, aPixmap );
238 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
239 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
241 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
246 //===========================================================================
247 // Function : releaseTextures
248 // Purpose : Releases cached textures found for the specified presentation.
249 //===========================================================================
250 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
252 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
254 AIS_ListOfInteractive aListOfIO;
256 anOccPrs->GetObjects( aListOfIO );
258 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
260 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
261 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
263 for ( ; aIterateIO.More(); aIterateIO.Next() )
265 Handle(GEOM_AISShape) aAISShape =
266 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
268 if ( aAISShape.IsNull() )
271 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
272 if ( aPixmap.IsNull() )
275 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
278 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
280 aUsersShapes.Remove( aAISShape );
282 if ( aUsersShapes.IsEmpty() ) {
283 aPixmapUsersMap.UnBind( aPixmap );
284 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
291 //================================================================
292 // Function : getActiveStudy
293 // Purpose : Get active study, returns 0 if no open study frame
294 //================================================================
295 static inline SalomeApp_Study* getActiveStudy()
297 SUIT_Session* session = SUIT_Session::session();
298 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
300 return ( SalomeApp_Study* )app->activeStudy();
304 static inline int getViewManagerId( SALOME_View* theViewFrame) {
305 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
306 SUIT_ViewManager* aViewMgr = 0;
308 aViewMgr = aModel->getViewManager();
309 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
312 //================================================================
313 // Function : getTopAbsMode
314 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
315 // one from GEOMImpl_Types.h
316 //================================================================
317 static inline int getTopAbsMode( const int implType )
321 case GEOM_COMPOUND : return TopAbs_COMPOUND;
322 case GEOM_SOLID : return TopAbs_SOLID;
323 case GEOM_SHELL : return TopAbs_SHELL;
324 case GEOM_FACE : return TopAbs_FACE;
325 case GEOM_WIRE : return TopAbs_WIRE;
326 case GEOM_EDGE : return TopAbs_EDGE;
327 case GEOM_POINT : return TopAbs_VERTEX;
332 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
334 if ( shape.IsNull() )
337 int ret = shape.ShapeType();
339 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
340 TopoDS_Iterator it(shape, Standard_True, Standard_False);
341 for (; it.More(); it.Next()) {
342 TopoDS_Shape sub_shape = it.Value();
343 if ( sub_shape.IsNull() ) continue;
344 int stype = getMinMaxShapeType( sub_shape, ismin );
345 if ( stype == TopAbs_SHAPE ) continue;
346 if ( ismin && stype > ret )
348 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
356 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
358 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
361 //================================================================
362 // Function : getFilter
363 // Purpose : Get filter corresponding to the type of object
364 // from GEOMImpl_Types.h
365 //================================================================
366 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
368 SUIT_SelectionFilter* aFilter;
370 int aTopAbsMode = getTopAbsMode( theMode );
371 if ( aTopAbsMode != -1 )
372 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
376 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
377 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
379 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
380 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
381 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
382 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
383 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
384 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
386 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
388 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
389 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
391 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
397 //================================================================
398 // Function : getComplexFilter
399 // Purpose : Get compound filter corresponding to the type of
400 // object from GEOMImpl_Types.h
401 //================================================================
402 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
404 GEOM_CompoundFilter* aFilter;
406 if(aSubShapes != NULL ) {
407 aFilter = new GEOM_CompoundFilter(getStudy());
408 QList<int> aTopAbsTypes;
409 QList<int>::const_iterator it;
410 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
411 int topAbsMode = getTopAbsMode(*it);
412 if(topAbsMode != -1 )
413 aTopAbsTypes.append(topAbsMode);
415 aFilter->addSubTypes(aTopAbsTypes);
421 //================================================================
422 // Function : getEntry
424 //================================================================
425 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
427 SUIT_Session* session = SUIT_Session::session();
428 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
431 CORBA::String_var IOR = app->orb()->object_to_string( object );
432 if ( strcmp(IOR.in(), "") != 0 )
434 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
435 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
443 //================================================================
444 // Function : getName
446 //================================================================
447 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
449 SUIT_Session* session = SUIT_Session::session();
450 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
453 CORBA::String_var IOR = app->orb()->object_to_string( object );
454 if ( strcmp(IOR.in(), "") != 0 )
456 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
457 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
459 _PTR(GenericAttribute) anAttr;
461 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
463 _PTR(AttributeName) aNameAttr( anAttr );
464 return aNameAttr->Value();
472 //=================================================================
474 * GEOM_Displayer::GEOM_Displayer
477 //=================================================================
478 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
481 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
486 SUIT_Session* session = SUIT_Session::session();
487 SUIT_ResourceMgr* resMgr = session->resourceMgr();
489 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
490 myShadingColor = SalomeApp_Tools::color( col );
492 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
493 myHasDisplayMode = false;
495 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
496 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
497 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
499 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
500 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
501 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
504 // This color is used for shape displaying. If it is equal -1 then
505 // default color is used.
510 myTransparency = -1.0;
512 // This parameter is used for activisation/deactivisation of objects to be displayed
514 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
515 // Activate parallel vizualisation only for testing purpose
516 // and if the corresponding env variable is set to 1
517 char* parallel_visu = getenv("PARALLEL_VISU");
518 if (parallel_visu && atoi(parallel_visu))
520 MESSAGE("Parallel visualisation on");
521 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
527 myFieldDataType = GEOM::FDT_Double;
528 myFieldDimension = 0;
529 myFieldStepRangeMin = 0;
530 myFieldStepRangeMax = 0;
533 //=================================================================
535 * GEOM_Displayer::~GEOM_Displayer
538 //=================================================================
539 GEOM_Displayer::~GEOM_Displayer()
543 //=================================================================
545 * GEOM_Displayer::Display
546 * Display interactive object in the current viewer
548 //=================================================================
549 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
550 const bool updateViewer,
551 SALOME_View* theViewFrame )
553 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
556 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
560 vf->BeforeDisplay( this, prs );
562 vf->AfterDisplay( this, prs );
567 int aMgrId = getViewManagerId(vf);
568 SalomeApp_Study* aStudy = getStudy();
569 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
571 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
573 delete prs; // delete presentation because displayer is its owner
578 //=================================================================
580 * GEOM_Displayer::Display
581 * This overloaded Display() method can be useful for operations
582 * not using dialog boxes.
584 //=================================================================
585 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
587 if ( theObj->_is_nil() )
590 std::string entry = getEntry( theObj );
592 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
597 //=================================================================
599 * GEOM_Displayer::Erase
600 * Erase interactive object in the current viewer
602 //=================================================================
603 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
605 const bool updateViewer,
606 SALOME_View* theViewFrame )
608 if ( theIO.IsNull() )
611 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
614 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
616 vf->BeforeErase( this, prs );
617 vf->Erase( prs, forced );
618 vf->AfterErase( this, prs );
621 delete prs; // delete presentation because displayer is its owner
623 int aMgrId = getViewManagerId(vf);
624 SalomeApp_Study* aStudy = getStudy();
625 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
627 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
632 //=================================================================
634 * GEOM_Displayer::Erase
635 * Erase geometry object in the current viewer
637 //=================================================================
638 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
640 const bool updateViewer,
641 SALOME_View* theViewFrame)
643 std::string entry = getEntry( theObj );
646 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
647 forced, updateViewer, theViewFrame);
651 //=================================================================
653 * GEOM_Displayer::Redisplay
654 * Redisplay (erase and then display again) interactive object
655 * in the current viewer
657 //=================================================================
658 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
659 const bool updateViewer,
660 const bool checkActiveViewer )
662 // Remove the object permanently (<forced> == true)
663 SUIT_Session* ses = SUIT_Session::session();
664 SUIT_Application* app = ses->activeApplication();
667 SUIT_Desktop* desk = app->desktop();
668 QList<SUIT_ViewWindow*> wnds = desk->windows();
669 SUIT_ViewWindow* wnd;
670 QListIterator<SUIT_ViewWindow*> it( wnds );
671 while ( it.hasNext() && (wnd = it.next()) )
673 SUIT_ViewManager* vman = wnd->getViewManager();
676 SUIT_ViewModel* vmodel = vman->getViewModel();
679 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
682 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
684 Redisplay( theIO, updateViewer, view );
693 //=================================================================
695 * GEOM_Displayer::Redisplay
696 * Redisplay (erase and then display again) interactive object
697 * in the specified view
699 //=================================================================
700 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
701 const bool theUpdateViewer,
702 SALOME_View* theViewFrame )
704 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
710 Erase( theIO, true, false, theViewFrame );
711 Display( theIO, theUpdateViewer, theViewFrame );
714 //=================================================================
716 * GEOM_Displayer::Display
717 * Calls Display() method for each object in the given list
719 //=================================================================
720 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
722 SALOME_ListIteratorOfListIO Iter( theIOList );
723 for ( ; Iter.More(); Iter.Next() ) {
724 Display( Iter.Value(), false );
730 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
732 // VSR: this method can be improved in future:
733 // to improve performance, the default values from resource manager should be cached in the displayer
734 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
737 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
739 // VSR: this method can be improved in future:
740 // to improve performance, the default values from resource manager should be cached in the displayer
741 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
744 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
746 // check that shape is not null
747 if ( AISShape.IsNull() ) return;
749 // check that study is active
750 SalomeApp_Study* study = getStudy();
751 if ( !study ) return;
753 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
754 !TopoDS_Iterator(myShape).More() )
755 return; // NPAL15983 (Bug when displaying empty groups)
757 // set interactive object
759 Handle( SALOME_InteractiveObject ) anIO;
761 if ( !myIO.IsNull() ) {
762 AISShape->setIO( myIO );
763 AISShape->SetOwner( myIO );
766 else if ( !myName.empty() ) {
767 // workaround to allow selection of temporary objects
768 static int tempId = 0;
769 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
770 AISShape->setIO( anIO );
771 AISShape->SetOwner( anIO );
774 // flag: only vertex or compound of vertices is processed (specific handling)
775 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
776 // presentation study entry (empty for temporary objects like preview)
777 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
778 // flag: temporary object
779 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
780 // currently active view window's ID (-1 if no active view)
781 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
783 // get presentation properties
784 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
786 // Temporary staff: vertex must be infinite for correct visualization
787 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
790 Material_Model material;
791 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
793 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
794 // - set front material properties
795 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
796 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
797 // - set back material properties
798 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
799 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
800 // - switch to default (both sides) facing mode
801 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
807 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
808 // we set it to the shape not taking into account material properties
809 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
811 else if ( !material.isPhysical() ) {
812 // shading color from properties is used only for non-physical materials
813 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
817 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
818 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
819 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
820 AISShape->Attributes()->SetLineAspect( anAspect );
822 // - unfree boundaries color
823 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
824 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
825 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
826 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
828 // - free boundaries color
829 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
830 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
831 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
832 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
834 // - standalone edges color
835 anAspect = AISShape->Attributes()->WireAspect();
836 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
837 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
838 AISShape->Attributes()->SetWireAspect( anAspect );
840 // - color for edges in shading+edges mode
841 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
844 AISShape->storeBoundaryColors();
847 AISShape->SetDisplayMode( HasDisplayMode() ?
848 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
850 // display mode from properties
851 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
853 // set display vectors flag
854 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
857 if( HasTransparency() ) {
858 AISShape->SetTransparency( GetTransparency() );
860 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
863 // set iso properties
864 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
865 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
866 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
867 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
868 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
869 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
870 uIsoAspect->SetColor( isosColor );
871 uIsoAspect->SetWidth( isosWidth );
872 uIsoAspect->SetNumber( uIsos );
873 vIsoAspect->SetColor( isosColor );
874 vIsoAspect->SetWidth( isosWidth );
875 vIsoAspect->SetNumber( vIsos );
876 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
877 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
879 // set deflection coefficient
880 // ... to avoid to small values of the coefficient, its lower value is limited
881 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
885 if ( HasTexture() ) {
886 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
887 aImagePath = GetTexture().c_str();
888 if ( ! entry.isEmpty() ) {
889 // check that study is active
890 SalomeApp_Study* study = getActiveStudy();
892 // Store the texture in object properties for next displays
893 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
894 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
896 // Update propeties map
897 propMap = getObjectProperties( study, entry, myViewFrame );
902 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
905 #if OCC_VERSION_LARGE > 0x06070000
906 Handle(Image_PixMap) aPixmap;
907 if ( !aImagePath.isEmpty() )
908 aPixmap = cacheTextureFor( aImagePath, AISShape );
910 aPixmap = getDefaultTexture();
912 // apply image to shape
913 if ( !aPixmap.IsNull() ) {
914 AISShape->SetTexturePixMap( aPixmap );
915 AISShape->SetTextureMapOn();
916 AISShape->DisableTextureModulate();
919 AISShape->SetTextureMapOff();
922 if ( !aImagePath.isEmpty() ) {
923 AISShape->SetTextureFileName( TCollection_AsciiString( aImagePath.toUtf8().constData() ) );
924 AISShape->SetTextureMapOn();
925 AISShape->DisableTextureModulate();
930 AISShape->SetWidth( HasWidth() ?
931 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
933 // libe width from properties
934 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
936 // set top-level flag
937 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
939 // set point marker (for vertex / compound of vertices only)
941 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
942 if ( aList.size() == 2 ) {
943 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
944 int aTypeOfMarker = aList[0].toInt();
945 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
946 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
947 anAspect->SetScale( aScaleOfMarker );
948 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
949 anAspect->SetColor( 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>() ) );
954 AISShape->Attributes()->SetPointAspect( anAspect );
956 else if ( aList.size() == 1 ) {
957 // custom marker string contains "IdOfTexture"
958 int textureId = aList[0].toInt();
959 Standard_Integer aWidth, aHeight;
960 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
961 Handle(TColStd_HArray1OfByte) aTexture =
963 Handle(Graphic3d_HArray1OfBytes) aTexture =
965 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
966 if ( !aTexture.IsNull() ) {
967 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
968 Handle(Prs3d_PointAspect) aTextureAspect =
969 new Prs3d_PointAspect( HasColor() ?
970 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
971 (Quantity_NameOfColor)GetColor() :
972 // color from properties
973 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
978 Handle(Prs3d_PointAspect) aTextureAspect =
979 new Prs3d_PointAspect( HasColor() ?
980 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
981 (Quantity_NameOfColor)GetColor() :
982 // color from properties
983 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
988 AISShape->Attributes()->SetPointAspect( aTextureAspect );
993 // set field step data
994 AISShape->setFieldStepInfo( myFieldDataType,
999 myFieldStepRangeMax );
1001 if ( create && !isTemporary && aMgrId != -1 ) {
1002 // set properties to the study
1003 study->setObjectPropMap( aMgrId, entry, propMap );
1006 // AISShape->SetName(???); ??? necessary to set name ???
1009 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1011 // check that actor is not null
1012 if ( !actor ) return;
1014 // check that study is active
1015 SalomeApp_Study* study = getStudy();
1016 if ( !study ) return;
1018 // set interactive object
1020 Handle( SALOME_InteractiveObject ) anIO;
1022 if ( !myIO.IsNull() ) {
1023 actor->setIO( myIO );
1026 else if ( !myName.empty() ) {
1027 // workaround to allow selection of temporary objects
1028 static int tempId = 0;
1029 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1030 actor->setIO( anIO );
1033 // presentation study entry (empty for temporary objects like preview)
1034 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1035 // flag: temporary object
1036 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1037 // currently active view window's ID (-1 if no active view)
1038 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1040 // get presentation properties
1041 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1044 /////////////////////////////////////////////////////////////////////////
1045 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1046 // due to performance problem
1047 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1048 /////////////////////////////////////////////////////////////////////////
1049 if ( !actor->getTopo().IsSame( myShape ) )
1050 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1053 Material_Model material;
1054 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1055 std::vector<vtkProperty*> mprops;
1056 mprops.push_back( material.getMaterialVTKProperty( true ) );
1057 mprops.push_back( material.getMaterialVTKProperty( false) );
1058 actor->SetMaterial( mprops );
1060 // set iso-lines properties
1062 // - set number of iso-lines
1063 int nbIsos[2]= { 1, 1 };
1064 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1065 nbIsos[0] = isos[0].toInt();
1066 nbIsos[1] = isos[1].toInt();
1067 actor->SetNbIsos( nbIsos );
1069 // - set iso-lines width
1070 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1072 // - set iso-lines color
1073 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1074 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1079 // - same color for all sub-actors
1080 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1081 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1084 // shading color (for non-physical materials)
1085 if ( !material.isPhysical() ) {
1086 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1087 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1088 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1091 // - standalone edge color
1092 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1093 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1095 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1096 // - shared edges color ???
1097 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1099 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1100 // - free edges color ???
1101 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1104 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1105 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1108 // - color for edges in shading+edges mode
1109 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1110 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1113 if( HasTransparency() ) {
1114 actor->SetOpacity( 1.0 - GetTransparency() );
1116 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1120 actor->SetWidth( HasWidth() ?
1121 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1123 // libe width from properties
1124 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1126 // set display vectors flag
1127 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1130 int displayMode = HasDisplayMode() ?
1131 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1133 // display mode from properties
1134 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1136 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1137 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1138 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1139 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1141 if ( displayMode == 2 )
1142 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1143 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1145 actor->setDisplayMode( displayMode );
1148 actor->PickableOn();
1150 actor->PickableOff();
1152 if ( create && !isTemporary && aMgrId != -1 ) {
1153 // set properties to the study
1154 study->setObjectPropMap( aMgrId, entry, propMap );
1158 //=================================================================
1160 * GEOM_Displayer::updateDimensions
1161 * Creates or renews dimension presentation for the IO.
1163 //=================================================================
1164 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1165 SALOME_OCCPrs* thePrs,
1166 const gp_Ax3& theShapeLCS )
1168 SalomeApp_Study* aStudy = getStudy();
1174 if ( theIO.IsNull() )
1179 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1181 AIS_ListOfInteractive aListOfIO;
1183 anOccPrs->GetObjects( aListOfIO );
1185 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1187 // remove outdated presentations of dimensions
1188 for ( ; aIterateIO.More(); aIterateIO.Next() )
1190 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1191 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1196 aListOfIO.Remove( aIterateIO );
1198 if ( !aIterateIO.More() )
1204 // prepare dimension styling
1205 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1207 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1208 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1209 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1210 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1211 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1212 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1213 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1215 // restore dimension presentation from saved attribute or property data
1216 AIS_ListOfInteractive aRestoredDimensions;
1218 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1220 GEOM::propertyName( GEOM::Dimensions ),
1223 GEOMGUI_DimensionProperty aRecords;
1225 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1227 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1231 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1234 // create up-to-date dimension presentations
1235 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1237 if ( !aRecords.IsVisible( aPrsIt ) )
1242 // init dimension by type
1243 Handle(AIS_Dimension) aPrs;
1244 switch( aRecords.GetType( aPrsIt ) )
1246 case GEOMGUI_DimensionProperty::DimensionType_Length :
1248 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1249 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1254 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1256 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1257 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1262 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1264 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1265 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1271 aPrs->SetOwner( theIO );
1273 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1275 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1277 aStyle->SetCommonColor( aColor );
1278 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1279 aStyle->MakeText3d( Standard_True );
1280 aStyle->MakeTextShaded( Standard_True );
1281 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1282 aStyle->TextAspect()->SetHeight( aFontHeight );
1283 aStyle->ArrowAspect()->SetLength( anArrowLength );
1284 aStyle->LineAspect()->SetWidth( aLineWidth );
1285 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1286 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1287 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1288 aPrs->SetDimensionAspect( aStyle );
1289 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1290 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1291 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1293 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1295 // show degree symbol for dimension instead of label "deg"
1296 if ( aUnitsAngle == "deg" )
1298 aPrs->SetSpecialSymbol(0xB0);
1299 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1300 aStyle->MakeUnitsDisplayed(Standard_False);
1304 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1305 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1310 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1313 aListOfIO.Append( aPrs );
1316 // update presentation
1319 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1321 anOccPrs->AddObject( aIterateIO.Value() );
1325 //=================================================================
1327 * GEOM_Displayer::Erase
1328 * Calls Erase() method for each object in the given list
1330 //=================================================================
1331 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1333 const bool updateViewer )
1335 SALOME_ListIteratorOfListIO Iter( theIOList );
1336 for ( ; Iter.More(); Iter.Next() )
1337 Erase( Iter.Value(), forced, false );
1343 //=================================================================
1345 * GEOM_Displayer::Redisplay
1346 * Calls Redisplay() method for each object in the given list
1348 //=================================================================
1349 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1350 const bool updateViewer,
1351 const bool checkActiveViewer )
1353 SALOME_ListIteratorOfListIO Iter( theIOList );
1354 for ( ; Iter.More(); Iter.Next() )
1355 Redisplay( Iter.Value(), false, checkActiveViewer );
1361 //=================================================================
1363 * GEOM_Displayer::Redisplay
1364 * Calls Redisplay() method for each object in the given list
1366 //=================================================================
1367 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1368 const bool theUpdateViewer,
1369 SALOME_View* theViewFrame )
1371 SALOME_ListIteratorOfListIO anIter( theIOList );
1372 for ( ; anIter.More(); anIter.Next() )
1374 Redisplay( anIter.Value(), false, theViewFrame );
1377 if ( theUpdateViewer )
1383 //=================================================================
1385 * GEOM_Displayer::Update
1386 * Update OCC presentaion
1387 * [ Reimplemented from SALOME_Displayer ]
1389 //=================================================================
1390 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1392 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1393 SalomeApp_Study* study = getStudy();
1395 if ( !occPrs || myShape.IsNull() || !study )
1398 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1401 // specific processing for local coordinate system presentation
1404 TopoDS_Face aFace = TopoDS::Face( myShape );
1405 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1406 if ( !aPlane.IsNull() )
1408 gp_Ax3 aPos = aPlane->Pln().Position();
1409 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1411 Handle(GEOM_AISTrihedron) aTrh;
1413 if ( occPrs->IsNull() )
1415 // new presentation is being created
1416 aTrh = new GEOM_AISTrihedron( aPlc );
1417 occPrs->AddObject( aTrh );
1421 // presentation is being updated
1422 AIS_ListOfInteractive aList;
1423 occPrs->GetObjects( aList );
1424 AIS_ListIteratorOfListOfInteractive anIter( aList );
1425 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1426 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1430 if ( !aTrh.IsNull() ) {
1431 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1433 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1434 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1436 aTrh->SetWidth( GetWidth() );
1438 if ( !myIO.IsNull() )
1440 aTrh->setIO( myIO );
1441 aTrh->SetOwner( myIO );
1443 aTrh->SetComponent( aPlc );
1444 aTrh->SetToUpdate();
1446 occPrs->SetToActivate( ToActivate() );
1452 // processing for usual geometry presentation
1455 // if presentation is empty we try to create new one
1456 if ( occPrs->IsNull() )
1458 // create presentation (specific for vectors)
1459 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1460 : new GEOM_AISShape ( myShape, "" );
1462 if( myType == GEOM_FIELD_STEP )
1463 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1464 // update shape properties
1465 updateShapeProperties( AISShape, true );
1467 // add shape to the presentation
1468 occPrs->AddObject( AISShape );
1470 // In accordance with ToActivate() value object will be activated/deactivated
1471 // when it will be displayed
1472 occPrs->SetToActivate( ToActivate() );
1474 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1475 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1477 // create additional wireframe shape
1478 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1479 aWirePrs->SetWidth(AISShape->Width());
1480 if ( !myIO.IsNull() ) {
1481 aWirePrs->setIO( myIO );
1482 aWirePrs->SetOwner( myIO );
1485 // add shape to the presentation
1486 occPrs->AddObject( aWirePrs );
1489 // if presentation is found -> set again shape for it
1492 AIS_ListOfInteractive IOList;
1493 occPrs->GetObjects( IOList );
1494 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1495 for ( ; Iter.More(); Iter.Next() )
1497 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1498 if ( AISShape.IsNull() )
1501 // re-set shape (it might be changed)
1502 if ( AISShape->Shape() != myShape )
1503 AISShape->Set( myShape );
1505 // update shape properties
1506 updateShapeProperties( AISShape, false );
1509 AISShape->UpdateSelection();
1510 AISShape->SetToUpdate();
1514 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1518 //=================================================================
1520 * GEOM_Displayer::Update
1521 * Update VTK presentaion
1522 * [ Reimplemented from SALOME_Displayer ]
1524 //=================================================================
1525 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1527 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1528 SalomeApp_Study* study = getStudy();
1530 if ( !vtkPrs || myShape.IsNull() || !study )
1533 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1536 // specific processing for local coordinate system presentation
1539 TopoDS_Face aFace = TopoDS::Face( myShape );
1540 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1541 if ( !aPlane.IsNull() ) {
1542 gp_Ax3 aPos = aPlane->Pln().Position();
1543 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1545 GEOM_VTKTrihedron* aTrh = 0;
1547 if ( vtkPrs->IsNull() ) {
1548 // new presentation is being created
1549 aTrh = GEOM_VTKTrihedron::New();
1550 vtkPrs->AddObject( aTrh );
1553 // presentation is being updated
1554 vtkActorCollection* actors = vtkPrs->GetObjects();
1556 actors->InitTraversal();
1557 vtkActor* a = actors->GetNextActor();
1558 while ( a && !aTrh ) {
1559 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1560 a = actors->GetNextActor();
1566 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1568 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1569 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1571 #ifdef VTK_TRIHEDRON_WIDTH
1573 // VSR: currently isn't supported
1575 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1577 aTrh->SetWidth( GetWidth() );
1580 if ( !myIO.IsNull() )
1581 aTrh->setIO( myIO );
1583 aTrh->SetPlacement( aPlc );
1590 // processing for usual geometry presentation
1593 // if presentation is empty we try to create new one
1594 if ( vtkPrs->IsNull() )
1597 GEOM_Actor* actor = GEOM_Actor::New();
1598 // update actor properties
1599 updateActorProperties( actor, true );
1600 // add actor to the presentation
1601 vtkPrs->AddObject( actor );
1604 // presentation is being updated
1605 vtkActorCollection* actors = vtkPrs->GetObjects();
1607 actors->InitTraversal();
1608 vtkActor* a = actors->GetNextActor();
1610 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1612 // update actor properties
1613 updateActorProperties( actor, false );
1614 a = actors->GetNextActor();
1622 //=================================================================
1624 * GEOM_Displayer::BuildPrs
1625 * Build presentation accordint to the current viewer type
1627 //=================================================================
1628 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1630 if ( theObj->_is_nil() )
1633 myViewFrame = GetActiveView();
1634 if ( myViewFrame == 0 )
1637 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1642 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1643 myType = theObj->GetType();
1645 // Update presentation
1651 //=================================================================
1653 * GEOM_Displayer::BuildPrs
1654 * Build presentation accordint to the current viewer type
1656 //=================================================================
1657 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1659 myViewFrame = GetActiveView();
1660 if ( theShape.IsNull() || myViewFrame == 0 )
1663 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1668 setShape( theShape );
1676 //=================================================================
1678 * GEOM_Displayer::buildPresentation
1679 * Builds/finds object's presentation for the current viewer
1680 * Calls corresponding Update() method by means of double dispatch
1683 //=================================================================
1684 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1685 SALOME_View* theViewFrame )
1687 SALOME_Prs* prs = 0;
1690 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1694 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1697 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1698 theIO->setEntry( entry.toLatin1().constData() );
1699 if ( !theIO.IsNull() )
1701 // set interactive object
1703 // Find SOBject (because shape should be published previously)
1704 SUIT_Session* session = SUIT_Session::session();
1705 SUIT_Application* app = session->activeApplication();
1708 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1711 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1714 // get CORBA reference to data object
1715 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1716 if ( !CORBA::is_nil( object ) )
1718 // downcast to GEOM base object
1719 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1720 if ( !GeomBaseObject->_is_nil() )
1722 myType = GeomBaseObject->GetType();
1724 // downcast to GEOM object
1725 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1726 if ( myType == GEOM_FIELD_STEP )
1728 // get the GEOM object from the field's shape
1729 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1730 if ( !GeomFieldStep->_is_nil() )
1732 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1733 if ( !GeomField->_is_nil() )
1734 GeomObject = GeomField->GetShape();
1737 // read the field step information
1738 readFieldStepInfo( GeomFieldStep );
1741 if ( !GeomObject->_is_nil() )
1743 // finally set shape
1744 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1752 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1758 //=================================================================
1760 * GEOM_Displayer::buildSubshapePresentation
1761 * Builds/finds object's presentation for the current viewer
1762 * Calls corresponding Update() method by means of double dispatch
1763 * For not published objects (for Mantis issue 0020435)
1765 //=================================================================
1766 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1767 const QString& entry,
1768 SALOME_View* theViewFrame)
1770 SALOME_Prs* prs = 0;
1773 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1777 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1780 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1781 theIO->setEntry(entry.toLatin1().constData());
1782 if (!theIO.IsNull())
1784 // set interactive object
1786 // finally set shape
1788 myType = GEOM_SUBSHAPE;
1790 UpdatePrs(prs); // Update presentation by using of the double dispatch
1796 //=================================================================
1798 * GEOM_Displayer::internalReset
1799 * Resets internal data
1802 //=================================================================
1803 void GEOM_Displayer::internalReset()
1808 myFieldDataType = GEOM::FDT_Double;
1809 myFieldDimension = 0;
1810 myFieldStepData.clear();
1811 myFieldStepName.Clear();
1812 myFieldStepRangeMin = 0;
1813 myFieldStepRangeMax = 0;
1816 //=================================================================
1818 * GEOM_Displayer::LocalSelection
1819 * Activate selection of CAD shapes with activisation of selection
1820 * of their sub-shapes (with opened local context for OCC viewer)
1822 //=================================================================
1823 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1825 SUIT_Session* session = SUIT_Session::session();
1826 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1830 LightApp_SelectionMgr* sm = app->selectionMgr();
1832 // remove all filters from selection
1835 SALOME_View* vf = GetActiveView();
1837 if (!theIO.IsNull() && !vf->isVisible(theIO))
1839 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1840 vf->LocalSelection( prs, theMode );
1841 delete prs; // delete presentation because displayer is its owner
1845 //=================================================================
1847 * GEOM_Displayer::globalSelection
1848 * Activate selection of CAD shapes without activisation of selection
1849 * of their sub-shapes (without opened local context for OCC viewer)
1851 //=================================================================
1852 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1854 TColStd_MapOfInteger aModes;
1855 aModes.Add( theMode );
1856 GlobalSelection( aModes, update );
1859 //=================================================================
1861 * GEOM_Displayer::globalSelection
1862 * Activate selection of CAD shapes without activisation of selection
1863 * of their sub-shapes (without opened local context for OCC viewer)
1865 //=================================================================
1866 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1867 const bool update, const QList<int>* theSubShapes )
1869 SUIT_Session* session = SUIT_Session::session();
1870 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1874 SALOME_View* vf = GetActiveView();
1878 // Close local context
1879 vf->GlobalSelection( update );
1881 // Set selection filters in accordance with current mode
1882 LightApp_SelectionMgr* sm = app->selectionMgr();
1886 // Remove from selection temporary objects if necessary
1887 if ( !theModes.Contains( GEOM_PREVIEW ) )
1888 clearTemporary( sm );
1890 //@ aSel->ClearIndex();
1894 // Remove filters from AIS_InteractiveContext
1895 Handle(AIS_InteractiveContext) ic;
1896 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1899 ic = viewer->getAISContext();
1901 ic->RemoveFilters();
1904 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1907 SUIT_SelectionFilter* aFilter;
1908 if ( theModes.Extent() == 1 )
1910 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1912 if ( aMode == GEOM_COMPOUNDFILTER )
1913 aFilter = getComplexFilter( theSubShapes );
1915 aFilter = getFilter( aMode );
1917 else if ( theModes.Extent() > 1 )
1919 TColStd_MapOfInteger aTopAbsModes;
1920 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1921 QList<SUIT_SelectionFilter*> aListOfFilters;
1922 for ( ; anIter.More(); anIter.Next() )
1924 SUIT_SelectionFilter* aFilter;
1925 int aMode = anIter.Key();
1926 if ( aMode == GEOM_COMPOUNDFILTER )
1927 aFilter = getComplexFilter( theSubShapes );
1929 aFilter = getFilter( aMode );
1932 aListOfFilters.append( aFilter );
1935 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1942 sm->installFilter( aFilter );
1945 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1946 ic->AddFilter( anOCCFilter );
1951 //=================================================================
1953 * GEOM_Displayer::LocalSelection
1954 * Activate selection of CAD shapes with activisation of selection
1955 * of their sub-shapes (with opened local context for OCC viewer)
1957 //=================================================================
1958 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1960 SALOME_ListIteratorOfListIO Iter( theIOList );
1961 for ( ; Iter.More(); Iter.Next() )
1962 LocalSelection( Iter.Value(), theMode );
1965 //=================================================================
1967 * GEOM_Displayer::BeforeDisplay
1968 * Called before displaying of pars. Close local context
1969 * [ Reimplemented from SALOME_Displayer ]
1971 //=================================================================
1972 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1974 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1977 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1980 if ( ic->HasOpenedContext() )
1981 ic->CloseAllContexts();
1986 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1988 UpdateColorScale(false,false);
1991 #if OCC_VERSION_LARGE > 0x06070000
1992 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1994 LightApp_Displayer::BeforeErase( v, p );
1995 releaseTextures( p );
1999 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2001 LightApp_Displayer::AfterErase( v, p );
2002 UpdateColorScale(false,false);
2005 //=================================================================
2007 * GEOM_Displayer::SetColor
2008 * Set color for shape displaying. If it is equal -1 then default color is used.
2009 * Available values are from Quantity_NameOfColor enumeration
2011 //=================================================================
2012 void GEOM_Displayer::SetColor( const int color )
2019 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2023 int GEOM_Displayer::GetColor() const
2028 bool GEOM_Displayer::HasColor() const
2030 return myColor != -1;
2033 void GEOM_Displayer::UnsetColor()
2037 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2038 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2039 myShadingColor = SalomeApp_Tools::color( col );
2042 //=================================================================
2044 * GEOM_Displayer::SetTransparency
2045 * Set transparency for shape displaying.
2047 //=================================================================
2048 void GEOM_Displayer::SetTransparency( const double transparency )
2050 myTransparency = transparency;
2053 double GEOM_Displayer::GetTransparency() const
2055 return myTransparency;
2058 bool GEOM_Displayer::HasTransparency() const
2060 return myTransparency != -1.0;
2063 void GEOM_Displayer::UnsetTransparency()
2065 myTransparency = -1.0;
2069 //=================================================================
2071 * GEOM_Displayer::SetTexture
2072 * Set color for shape displaying. If it is equal -1 then default color is used.
2073 * Available values are from Quantity_NameOfColor enumeration
2075 //=================================================================
2076 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2078 if(texureFileName!="")
2080 myTexture = texureFileName;
2084 bool GEOM_Displayer::HasTexture() const
2086 return myTexture != "";
2089 std::string GEOM_Displayer::GetTexture() const
2094 //=================================================================
2096 * GEOM_Displayer::SetWidth
2097 * Set width of shape displaying. If it is equal -1 then default width is used.
2099 //=================================================================
2100 void GEOM_Displayer::SetWidth( const double width )
2105 double GEOM_Displayer::GetWidth() const
2110 bool GEOM_Displayer::HasWidth() const
2112 return myWidth != -1;
2115 void GEOM_Displayer::UnsetWidth()
2121 int GEOM_Displayer::GetIsosWidth() const
2126 void GEOM_Displayer::SetIsosWidth(const int width)
2128 myIsosWidth = width;
2131 bool GEOM_Displayer::HasIsosWidth() const
2133 return myIsosWidth != -1;
2137 //=================================================================
2139 * GEOM_Displayer::SetToActivate
2140 * This method is used for activisation/deactivisation of objects to be displayed
2142 //=================================================================
2143 void GEOM_Displayer::SetToActivate( const bool toActivate )
2145 myToActivate = toActivate;
2147 bool GEOM_Displayer::ToActivate() const
2149 return myToActivate;
2152 //=================================================================
2154 * GEOM_Displayer::clearTemporary
2155 * Removes from selection temporary objects
2157 //=================================================================
2158 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2160 SALOME_ListIO selected, toSelect;
2161 theSelMgr->selectedObjects( selected );
2163 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2164 Handle(SALOME_InteractiveObject) io = it.Value();
2165 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2166 toSelect.Append( it.Value() );
2169 theSelMgr->setSelectedObjects( toSelect, true );
2172 void GEOM_Displayer::SetName( const char* theName )
2177 void GEOM_Displayer::UnsetName()
2182 SalomeApp_Study* GEOM_Displayer::getStudy() const
2184 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2187 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2192 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2197 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2198 const int theFieldDimension,
2199 const QList<QVariant>& theFieldStepData,
2200 const TCollection_AsciiString& theFieldStepName,
2201 const double theFieldStepRangeMin,
2202 const double theFieldStepRangeMax )
2204 myFieldDataType = theFieldDataType;
2205 myFieldDimension = theFieldDimension;
2206 myFieldStepData = theFieldStepData;
2207 myFieldStepName = theFieldStepName;
2208 myFieldStepRangeMin = theFieldStepRangeMin;
2209 myFieldStepRangeMax = theFieldStepRangeMax;
2212 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2214 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2215 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2216 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2217 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2218 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2219 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2222 int GEOM_Displayer::SetDisplayMode( const int theMode )
2224 int aPrevMode = myDisplayMode;
2225 if ( theMode != -1 ) {
2226 myDisplayMode = theMode;
2227 myHasDisplayMode = true;
2235 int GEOM_Displayer::GetDisplayMode() const
2237 return myDisplayMode;
2240 int GEOM_Displayer::UnsetDisplayMode()
2242 int aPrevMode = myDisplayMode;
2243 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2244 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2245 myHasDisplayMode = false;
2249 bool GEOM_Displayer::HasDisplayMode() const
2251 return myHasDisplayMode;
2254 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2256 static QList<QColor> colors;
2258 if ( colors.isEmpty() ) {
2260 for (int s = 0; s < 2 ; s++)
2262 for (int v = 100; v >= 40; v = v - 20)
2264 for (int h = 0; h < 359 ; h = h + 60)
2266 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2272 static int currentColor = 0;
2274 SALOMEDS::Color color;
2275 color.R = (double)colors[currentColor].red() / 255.0;
2276 color.G = (double)colors[currentColor].green() / 255.0;
2277 color.B = (double)colors[currentColor].blue() / 255.0;
2279 currentColor = (currentColor+1) % colors.count();
2284 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2287 int aTolerance = 64;
2288 int anIterations = 0;
2294 if( anIterations % aPeriod == 0 )
2297 if( aTolerance < 1 )
2300 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2302 aHue = (int)( 360.0 * rand() / RAND_MAX );
2303 //std::cout << "Hue = " << aHue << std::endl;
2305 //std::cout << "Auto colors : ";
2307 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2308 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2309 for( ; it != itEnd; ++it )
2311 SALOMEDS::Color anAutoColor = *it;
2312 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2315 aQColor.getHsv( &h, &s, &v );
2316 //std::cout << h << " ";
2317 if( abs( h - aHue ) < aTolerance )
2320 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2324 //std::cout << std::endl;
2330 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2332 aColor.setHsv( aHue, 255, 255 );
2334 SALOMEDS::Color aSColor;
2335 aSColor.R = (double)aColor.red() / 255.0;
2336 aSColor.G = (double)aColor.green() / 255.0;
2337 aSColor.B = (double)aColor.blue() / 255.0;
2342 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2343 const QString& entry,
2346 // get default properties for the explicitly specified default view type
2347 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2349 if ( study && view ) {
2350 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2351 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2352 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2354 if ( viewModel && viewId != -1 ) {
2355 // get properties from the study
2356 PropMap storedMap = study->getObjectPropMap( viewId, entry );
2357 // overwrite default properties from stored ones (that are specified)
2358 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2359 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2360 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2361 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2363 // ... specific processing for color
2364 // ... current implementation is to use same stored color for all aspects
2365 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2366 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2367 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2368 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2369 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2370 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2371 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2374 if ( !entry.isEmpty() ) {
2375 // get CORBA reference to geom object
2376 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2378 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2379 if ( !CORBA::is_nil( object ) ) {
2380 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2381 if ( !CORBA::is_nil( geomObject ) ) { // to check
2382 // check that geom object has color properly set
2383 bool hasColor = false;
2384 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2385 // set color from geometry object (only once, if it is not yet set in GUI)
2386 // current implementation is to use same color for all aspects
2387 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2388 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2389 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2390 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2391 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2392 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2393 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2394 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2396 // check that object has point marker properly set
2397 GEOM::marker_type mType = geomObject->GetMarkerType();
2398 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2399 int mTextureId = geomObject->GetMarkerTexture();
2400 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2401 ( mType == GEOM::MT_USER && mTextureId > 0 );
2402 // set point marker from geometry object (only once, if it is not yet set in GUI)
2403 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2404 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2406 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2407 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2409 else if ( mType == GEOM::MT_USER ) {
2411 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2423 PropMap GEOM_Displayer::getDefaultPropertyMap()
2427 // get resource manager
2428 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2430 // fill in the properties map with default values
2432 // - visibility (false by default)
2433 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2435 // - nb isos (take default value from preferences)
2436 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2437 QString( "%1%2%3" ).
2438 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2439 arg( GEOM::subSectionSeparator() ).
2440 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2442 // - transparency (opacity = 1-transparency)
2443 propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2445 // - display mode (take default value from preferences)
2446 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2447 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2449 // - show edges direction flag (false by default)
2450 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2452 // - shading color (take default value from preferences)
2453 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2454 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2456 // - wireframe color (take default value from preferences)
2457 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2458 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2460 // - standalone edges color (take default value from preferences)
2461 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2462 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2464 // - free boundaries color (take default value from preferences)
2465 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2466 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2468 // - points color (take default value from preferences)
2469 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2470 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2472 // - isos color (take default value from preferences)
2473 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2474 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2476 // - outlines color (take default value from preferences)
2477 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2478 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2480 // - deflection coefficient (take default value from preferences)
2481 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2482 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2484 // - material (take default value from preferences)
2485 Material_Model material;
2486 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2487 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2489 // - edge width (take default value from preferences)
2490 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2491 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2493 // - isos width (take default value from preferences)
2494 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2495 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2497 // - point marker (take default value from preferences)
2498 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2499 QString( "%1%2%3" ).
2500 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2501 arg( GEOM::subSectionSeparator() ).
2502 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2504 // - top-level flag (false by default)
2505 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2510 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2511 SALOMEDS::Color aSColor;
2514 SUIT_Session* session = SUIT_Session::session();
2515 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2517 if ( app && !theGeomObject->_is_nil()) {
2518 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2521 _PTR(Study) aStudy = study->studyDS();
2522 aSColor = theGeomObject->GetColor();
2523 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2525 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2526 bool general_autocolor = true;
2527 #else // auto-color for groups only
2528 bool general_autocolor = false;
2529 #endif // GENERAL_AUTOCOLOR
2530 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2531 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2532 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2533 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2534 aSColor = getPredefinedUniqueColor();
2536 #else // old algorithm for auto-colors
2537 QList<SALOMEDS::Color> aReservedColors;
2538 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2539 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2540 if ( aMainSObject ) {
2541 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2542 for ( ; it->More(); it->Next() ) {
2543 _PTR(SObject) aChildSObject( it->Value() );
2544 GEOM::GEOM_Object_var aChildObject =
2545 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2546 if ( CORBA::is_nil( aChildObject ) )
2549 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2550 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2551 aReservedColors.append( aReservedColor );
2554 aSColor = getUniqueColor( aReservedColors );
2556 #endif // SIMPLE_AUTOCOLOR
2566 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2567 const bool eraseOnlyChildren) {
2568 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2572 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2576 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2581 // Erase from all views
2582 QList<SALOME_View*> views;
2584 ViewManagerList vmans = app->viewManagers();
2585 SUIT_ViewManager* vman;
2586 foreach ( vman, vmans ) {
2587 SUIT_ViewModel* vmod = vman->getViewModel();
2588 view = dynamic_cast<SALOME_View*> ( vmod );
2590 views.append( view );
2593 if( views.count() == 0 )
2596 //Erase childrens w/o update views
2597 DataObjectList listObj = parent->children( true );
2598 SUIT_DataObject* obj;
2599 foreach( obj, listObj ) {
2600 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2602 foreach ( view, views ) {
2603 Handle(SALOME_InteractiveObject) anIO =
2604 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2605 Erase(anIO, false, false, view);
2609 //Erase parent with view update or repaint views
2610 foreach ( view, views ) {
2611 if(!eraseOnlyChildren)
2612 Erase(theIO, false, true, view);
2618 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2620 if( theGeomFieldStep->_is_nil() )
2623 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2624 if( aGeomField->_is_nil() )
2627 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2628 if( aGeomFieldShape->_is_nil() )
2631 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2632 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2633 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2635 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2637 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2639 int aFieldDimension = aGeomField->GetDimension();
2641 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2642 int aFieldNbComponents = aFieldComponents->length();
2644 QList<QVariant> aFieldStepData;
2645 if( aFieldDataType == GEOM::FDT_Bool )
2647 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2648 if ( !aGeomBoolFieldStep->_is_nil() )
2650 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2651 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2652 aFieldStepData << (bool)aValues[i];
2655 else if( aFieldDataType == GEOM::FDT_Int )
2657 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2658 if ( !aGeomIntFieldStep->_is_nil() )
2660 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2661 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2662 aFieldStepData << (qlonglong)aValues[i];
2665 else if( aFieldDataType == GEOM::FDT_Double )
2667 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2668 if ( !aGeomDoubleFieldStep->_is_nil() )
2670 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2671 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2672 aFieldStepData << (double)aValues[i];
2675 else if( aFieldDataType == GEOM::FDT_String )
2677 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2678 if ( !aGeomStringFieldStep->_is_nil() )
2680 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2681 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2682 aFieldStepData << QString( aValues[i] );
2686 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2687 aFieldStepData = groupFieldData( aFieldStepData,
2689 aFieldDataType == GEOM::FDT_String,
2691 aFieldStepRangeMax );
2693 setFieldStepInfo( aFieldDataType,
2698 aFieldStepRangeMax );
2701 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2702 const int theFieldNbComponents,
2703 const bool theIsString,
2704 double& theFieldStepRangeMin,
2705 double& theFieldStepRangeMax )
2707 QList<QVariant> aResultList;
2708 theFieldStepRangeMin = 0;
2709 theFieldStepRangeMax = 0;
2711 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2714 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2716 QList<QVariant> aGroupedList;
2718 bool anIsBoolean = false;
2719 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2722 QStringList aStringList;
2724 int aBaseIndex = aSubShape * theFieldNbComponents;
2725 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2727 int anIndex = aComponent + aBaseIndex;
2729 const QVariant& aVariant = theFieldStepData[ anIndex ];
2732 if( aVariant.type() == QVariant::String )
2733 aStringList << aVariant.toString();
2738 if( aVariant.type() == QVariant::Bool )
2740 aValue = aVariant.toBool() ? 1.0 : 0.0;
2746 if( aVariant.type() == QVariant::LongLong )
2747 aValue = double( aVariant.toLongLong() );
2748 else if( aVariant.type() == QVariant::Double )
2749 aValue = aVariant.toDouble();
2750 aNorm += aValue * aValue;
2756 aGroupedList << aStringList.join( "\n" );
2760 aNorm /= theFieldNbComponents;
2762 aNorm = pow( aNorm, 0.5 );
2764 if( aGroupedList.isEmpty() )
2765 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2768 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2769 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2772 aGroupedList << aNorm;
2778 theFieldStepRangeMin = 0.0;
2779 theFieldStepRangeMax = 1.0;
2782 SUIT_Session* session = SUIT_Session::session();
2783 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2784 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2786 QListIterator<QVariant> anIter( aGroupedList );
2787 while( anIter.hasNext() )
2789 const QVariant& aVariant = anIter.next();
2791 aResultList << aVariant;
2795 Quantity_Color aColor;
2796 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2797 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2798 aResultList << aQColor;
2804 // Note: the method is copied from Aspect_ColorScale class
2805 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2806 const Standard_Integer aMin,
2807 const Standard_Integer aMax )
2809 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2811 Standard_Integer aHue = maxLimit;
2813 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2815 aHue = Min( Max( minLimit, aHue ), maxLimit );
2820 // Note: the method is copied from Aspect_ColorScale class
2821 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2822 const Standard_Real aMin,
2823 const Standard_Real aMax,
2824 const Standard_Integer ColorsCount,
2825 Quantity_Color& aColor )
2827 if( aValue<aMin || aValue>aMax || aMax<aMin )
2828 return Standard_False;
2832 Standard_Real IntervNumber = 0;
2835 else if( aValue>aMax )
2836 IntervNumber = ColorsCount-1;
2837 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2838 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2840 Standard_Integer Interv = Standard_Integer( IntervNumber );
2842 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2844 return Standard_True;
2848 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2850 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2854 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2858 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2859 if( aViewer.IsNull() )
2862 aViewer->InitActiveViews();
2863 if( !aViewer->MoreActiveViews() )
2866 Handle(V3d_View) aView = aViewer->ActiveView();
2867 if( aView.IsNull() )
2870 Standard_Boolean anIsDisplayColorScale = Standard_False;
2871 TCollection_AsciiString aColorScaleTitle;
2872 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2873 Standard_Boolean anIsBoolean = Standard_False;
2875 SALOME_ListIO aSelectedObjects;
2876 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2877 if( aSelectedObjects.Extent() == 1 )
2879 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2880 if( !anIO.IsNull() )
2882 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2885 AIS_ListOfInteractive aList;
2886 aPrs->GetObjects( aList );
2887 AIS_ListIteratorOfListOfInteractive anIter( aList );
2888 for( ; anIter.More(); anIter.Next() )
2890 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2891 if( !aShape.IsNull() )
2893 GEOM::field_data_type aFieldDataType;
2894 int aFieldDimension;
2895 QList<QVariant> aFieldStepData;
2896 TCollection_AsciiString aFieldStepName;
2897 double aFieldStepRangeMin, aFieldStepRangeMax;
2898 aShape->getFieldStepInfo( aFieldDataType,
2903 aFieldStepRangeMax );
2904 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2906 anIsDisplayColorScale = Standard_True;
2907 aColorScaleTitle = aFieldStepName;
2908 aColorScaleMin = aFieldStepRangeMin;
2909 aColorScaleMax = aFieldStepRangeMax;
2910 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2918 if( anIsDisplayColorScale )
2920 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2921 if( !aColorScale.IsNull() )
2923 SUIT_Session* session = SUIT_Session::session();
2924 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2926 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2927 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2928 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2929 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2930 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2931 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2933 aColorScale->SetXPosition( anXPos );
2934 aColorScale->SetYPosition( anYPos );
2935 aColorScale->SetWidth( aWidth );
2936 aColorScale->SetHeight( aHeight );
2938 aColorScale->SetTextHeight( aTextHeight );
2939 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2941 aColorScale->SetTitle( aColorScaleTitle );
2942 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2944 if( !aView->ColorScaleIsDisplayed() )
2945 aView->ColorScaleDisplay();
2949 if( aView->ColorScaleIsDisplayed() )
2950 aView->ColorScaleErase();
2953 if( theIsRedisplayFieldSteps )
2955 _PTR(Study) aStudyDS = aStudy->studyDS();
2956 QList<SUIT_ViewManager*> vmList;
2957 myApp->viewManagers( vmList );
2958 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2960 if( SUIT_ViewManager* aViewManager = *vmIt )
2962 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2963 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2965 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2968 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2969 if( !CORBA::is_nil( anObject ) )
2971 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2972 if( !aFieldStep->_is_nil() )
2974 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2975 Handle(SALOME_InteractiveObject) aStepIO =
2976 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2977 Redisplay( aStepIO, false, false );