1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
28 #include "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
59 #include <Basics_OCCTVersion.hxx>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
68 #include <SALOME_ListIO.hxx>
69 #include <SALOME_Prs.h>
70 #include "utilities.h"
73 #include <SOCC_ViewModel.h>
76 #include <SVTK_ViewModel.h>
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
80 #include <OCCViewer_Utilities.h>
83 #include <AIS_Drawer.hxx>
84 #include <AIS_Dimension.hxx>
85 #include <AIS_LengthDimension.hxx>
86 #include <AIS_DiameterDimension.hxx>
87 #include <AIS_AngleDimension.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <Aspect_PolygonOffsetMode.hxx>
90 #include <Aspect_ColorScale.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <StdSelect_TypeOfEdge.hxx>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <StdSelect_DisplayMode.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <BRep_Tool.hxx>
98 #include <Geom_Plane.hxx>
99 #include <Geom_Axis2Placement.hxx>
100 #include <Graphic3d_AspectFillArea3d.hxx>
101 #include <gp_Pln.hxx>
102 #include <TColStd_MapOfInteger.hxx>
103 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
104 #include <TopoDS_Iterator.hxx>
105 #include <Graphic3d_AspectMarker3d.hxx>
106 #include <TopTools_MapOfShape.hxx>
107 #include <TopTools_ListOfShape.hxx>
108 #include <TopTools_ListIteratorOfListOfShape.hxx>
109 #include <TopoDS.hxx>
110 #include <NCollection_DataMap.hxx>
111 #include <NCollection_Map.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #include <TColStd_HArray1OfByte.hxx>
128 // If the next macro is defined, autocolor feature works for all sub-shapes;
129 // if it is undefined, autocolor feature works for groups only
130 #define GENERAL_AUTOCOLOR
131 // Below macro, when uncommented, switches on simplified (more performant) algorithm
132 // of auto-color picking up
133 #define SIMPLE_AUTOCOLOR
135 // Hard-coded value of shape deflection coefficient for VTK viewer
136 const double VTK_MIN_DEFLECTION = 0.001;
138 // Pixmap caching support
141 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
142 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
143 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
145 static inline PixmapUsageMap& getPixmapUsageMap()
147 static PixmapUsageMap aMap;
151 static inline PixmapCacheMap& getPixmapCacheMap()
153 static PixmapCacheMap aMap;
157 //===========================================================================
158 // Function : getDefaultTexture
159 // Purpose : Get default texture
160 //===========================================================================
161 static inline Handle(Image_PixMap) getDefaultTexture()
163 static Handle(Image_PixMap) aPixmap;
164 if ( aPixmap.IsNull() ) {
165 QPixmap px(":images/default_texture.png");
167 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
172 //===========================================================================
173 // Function : cacheTextureFor
174 // Purpose : Load and cache image for the specified presentation.
175 //===========================================================================
176 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
177 const Handle(GEOM_AISShape)& theShape )
179 if ( thePath.isEmpty() )
182 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
183 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
185 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
186 if ( !aPixmap.IsNull() ) {
187 // point that the texture is used by the presentation
188 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
189 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
191 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
196 // convert texture to compatible image format
197 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
198 if ( anImage.isNull() )
201 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
203 aPixmapCacheMap.insert( thePath, aPixmap );
205 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
206 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
208 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
213 //===========================================================================
214 // Function : releaseTextures
215 // Purpose : Releases cached textures found for the specified presentation.
216 //===========================================================================
217 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
219 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
221 AIS_ListOfInteractive aListOfIO;
223 anOccPrs->GetObjects( aListOfIO );
225 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
227 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
228 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
230 for ( ; aIterateIO.More(); aIterateIO.Next() )
232 Handle(GEOM_AISShape) aAISShape =
233 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
235 if ( aAISShape.IsNull() )
238 #ifdef USE_TEXTURED_SHAPE
239 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
240 if ( aPixmap.IsNull() )
243 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
246 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
248 aUsersShapes.Remove( aAISShape );
250 if ( aUsersShapes.IsEmpty() ) {
251 aPixmapUsersMap.UnBind( aPixmap );
252 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
258 uint randomize( uint size )
260 static bool initialized = false;
261 if ( !initialized ) {
262 qsrand( QDateTime::currentDateTime().toTime_t() );
266 v = uint( (double)( v ) / RAND_MAX * size );
267 v = qMax( uint(0), qMin ( v, size-1 ) );
272 //================================================================
273 // Function : getActiveStudy
274 // Purpose : Get active study, returns 0 if no open study frame
275 //================================================================
276 static inline SalomeApp_Study* getActiveStudy()
278 SUIT_Session* session = SUIT_Session::session();
279 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
281 return ( SalomeApp_Study* )app->activeStudy();
285 static inline int getViewManagerId( SALOME_View* theViewFrame) {
286 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
287 SUIT_ViewManager* aViewMgr = 0;
289 aViewMgr = aModel->getViewManager();
290 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
293 //================================================================
294 // Function : getTopAbsMode
295 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
296 // one from GEOMImpl_Types.h
297 //================================================================
298 static inline int getTopAbsMode( const int implType )
302 case GEOM_COMPOUND : return TopAbs_COMPOUND;
303 case GEOM_SOLID : return TopAbs_SOLID;
304 case GEOM_SHELL : return TopAbs_SHELL;
305 case GEOM_FACE : return TopAbs_FACE;
306 case GEOM_WIRE : return TopAbs_WIRE;
307 case GEOM_EDGE : return TopAbs_EDGE;
308 case GEOM_POINT : return TopAbs_VERTEX;
313 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
315 if ( shape.IsNull() )
318 int ret = shape.ShapeType();
320 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
321 TopoDS_Iterator it(shape, Standard_True, Standard_False);
322 for (; it.More(); it.Next()) {
323 TopoDS_Shape sub_shape = it.Value();
324 if ( sub_shape.IsNull() ) continue;
325 int stype = getMinMaxShapeType( sub_shape, ismin );
326 if ( stype == TopAbs_SHAPE ) continue;
327 if ( ismin && stype > ret )
329 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
337 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
339 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
342 //================================================================
343 // Function : getFilter
344 // Purpose : Get filter corresponding to the type of object
345 // from GEOMImpl_Types.h
346 //================================================================
347 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
349 SUIT_SelectionFilter* aFilter;
351 int aTopAbsMode = getTopAbsMode( theMode );
352 if ( aTopAbsMode != -1 )
353 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
357 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
358 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
360 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
361 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
362 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
363 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
364 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
365 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
367 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
369 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
370 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
372 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
378 //================================================================
379 // Function : getComplexFilter
380 // Purpose : Get compound filter corresponding to the type of
381 // object from GEOMImpl_Types.h
382 //================================================================
383 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
385 GEOM_CompoundFilter* aFilter;
387 if(aSubShapes != NULL ) {
388 aFilter = new GEOM_CompoundFilter(getStudy());
389 QList<int> aTopAbsTypes;
390 QList<int>::const_iterator it;
391 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
392 int topAbsMode = getTopAbsMode(*it);
393 if(topAbsMode != -1 )
394 aTopAbsTypes.append(topAbsMode);
396 aFilter->addSubTypes(aTopAbsTypes);
402 //================================================================
403 // Function : getEntry
405 //================================================================
406 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
408 SUIT_Session* session = SUIT_Session::session();
409 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
412 CORBA::String_var IOR = app->orb()->object_to_string( object );
413 if ( strcmp(IOR.in(), "") != 0 )
415 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
416 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
424 //================================================================
425 // Function : getName
427 //================================================================
428 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
430 SUIT_Session* session = SUIT_Session::session();
431 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
434 CORBA::String_var IOR = app->orb()->object_to_string( object );
435 if ( strcmp(IOR.in(), "") != 0 )
437 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
438 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
440 _PTR(GenericAttribute) anAttr;
442 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
444 _PTR(AttributeName) aNameAttr( anAttr );
445 return aNameAttr->Value();
453 //=================================================================
455 * GEOM_Displayer::GEOM_Displayer
458 //=================================================================
459 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
462 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
467 SUIT_Session* session = SUIT_Session::session();
468 SUIT_ResourceMgr* resMgr = session->resourceMgr();
470 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
471 myShadingColor = SalomeApp_Tools::color( col );
473 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
474 myHasDisplayMode = false;
476 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
477 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
478 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
480 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
481 myHasTransparency = false;
483 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
484 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
485 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
488 // This color is used for shape displaying. If it is equal -1 then
489 // default color is used.
495 // This parameter is used for activisation/deactivisation of objects to be displayed
497 // Activate parallel vizualisation only for testing purpose
498 // and if the corresponding env variable is set to 1
499 char* parallel_visu = getenv("PARALLEL_VISU");
500 if (parallel_visu && atoi(parallel_visu))
502 MESSAGE("Parallel visualisation on");
503 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
508 myFieldDataType = GEOM::FDT_Double;
509 myFieldDimension = 0;
510 myFieldStepRangeMin = 0;
511 myFieldStepRangeMax = 0;
514 //=================================================================
516 * GEOM_Displayer::~GEOM_Displayer
519 //=================================================================
520 GEOM_Displayer::~GEOM_Displayer()
524 //=================================================================
526 * GEOM_Displayer::Display
527 * Display interactive object in the current viewer
529 //=================================================================
530 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
531 const bool updateViewer,
532 SALOME_View* theViewFrame )
534 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
537 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
541 vf->BeforeDisplay( this, prs );
542 vf->Display( this, prs );
543 vf->AfterDisplay( this, prs );
548 delete prs; // delete presentation because displayer is its owner
553 //=================================================================
555 * GEOM_Displayer::Display
556 * This overloaded Display() method can be useful for operations
557 * not using dialog boxes.
559 //=================================================================
560 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
562 if ( theObj->_is_nil() )
565 std::string entry = getEntry( theObj );
567 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
572 //=================================================================
574 * GEOM_Displayer::Erase
575 * Erase interactive object in the current viewer
577 //=================================================================
578 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
580 const bool updateViewer,
581 SALOME_View* theViewFrame )
583 if ( theIO.IsNull() )
586 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
589 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
591 vf->BeforeErase( this, prs );
592 vf->Erase( this, prs, forced );
593 vf->AfterErase( this, prs );
596 delete prs; // delete presentation because displayer is its owner
601 //=================================================================
603 * GEOM_Displayer::Erase
604 * Erase geometry object in the current viewer
606 //=================================================================
607 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
609 const bool updateViewer,
610 SALOME_View* theViewFrame)
612 std::string entry = getEntry( theObj );
615 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
616 forced, updateViewer, theViewFrame);
620 //=================================================================
622 * GEOM_Displayer::Redisplay
623 * Redisplay (erase and then display again) interactive object
624 * in the current viewer
626 //=================================================================
627 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
628 const bool updateViewer,
629 const bool checkActiveViewer )
631 // Remove the object permanently (<forced> == true)
632 SUIT_Session* ses = SUIT_Session::session();
633 SUIT_Application* app = ses->activeApplication();
636 SUIT_Desktop* desk = app->desktop();
637 QList<SUIT_ViewWindow*> wnds = desk->windows();
638 SUIT_ViewWindow* wnd;
639 QListIterator<SUIT_ViewWindow*> it( wnds );
640 while ( it.hasNext() && (wnd = it.next()) )
642 SUIT_ViewManager* vman = wnd->getViewManager();
645 SUIT_ViewModel* vmodel = vman->getViewModel();
648 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
651 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
653 Redisplay( theIO, updateViewer, view );
662 //=================================================================
664 * GEOM_Displayer::Redisplay
665 * Redisplay (erase and then display again) interactive object
666 * in the specified view
668 //=================================================================
669 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
670 const bool theUpdateViewer,
671 SALOME_View* theViewFrame )
673 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
679 Erase( theIO, true, false, theViewFrame );
680 Display( theIO, theUpdateViewer, theViewFrame );
683 //=================================================================
685 * GEOM_Displayer::Display
686 * Calls Display() method for each object in the given list
688 //=================================================================
689 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
691 SALOME_ListIteratorOfListIO Iter( theIOList );
692 for ( ; Iter.More(); Iter.Next() ) {
693 Display( Iter.Value(), false );
699 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
701 SalomeApp_Study* aStudy = getStudy();
703 if ( v ) vId = getViewManagerId( v );
706 QString entry = p->GetEntry();
707 if ( !entry.isEmpty() ) {
709 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
710 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
715 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
720 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
722 // VSR: this method can be improved in future:
723 // to improve performance, the default values from resource manager should be cached in the displayer
724 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
727 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
729 // VSR: this method can be improved in future:
730 // to improve performance, the default values from resource manager should be cached in the displayer
731 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
734 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
736 // check that shape is not null
737 if ( AISShape.IsNull() ) return;
739 // check that study is active
740 SalomeApp_Study* study = getStudy();
741 if ( !study ) return;
743 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
744 !TopoDS_Iterator(myShape).More() )
745 return; // NPAL15983 (Bug when displaying empty groups)
747 // set interactive object
749 Handle( SALOME_InteractiveObject ) anIO;
751 if ( !myIO.IsNull() ) {
752 AISShape->setIO( myIO );
753 AISShape->SetOwner( myIO );
756 else if ( !myName.empty() ) {
757 // workaround to allow selection of temporary objects
758 static int tempId = 0;
759 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
760 AISShape->setIO( anIO );
761 AISShape->SetOwner( anIO );
764 // flag: only vertex or compound of vertices is processed (specific handling)
765 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
766 // presentation study entry (empty for temporary objects like preview)
767 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
768 // flag: temporary object
769 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
770 // currently active view window's ID (-1 if no active view)
771 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
773 // get presentation properties
774 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
776 // Temporary staff: vertex must be infinite for correct visualization
777 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
780 Material_Model material;
781 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
783 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
784 // - set front material properties
785 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
786 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
787 // - set back material properties
788 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
789 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
790 // - switch to default (both sides) facing mode
791 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
797 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
798 // we set it to the shape not taking into account material properties
799 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
801 else if ( !material.isPhysical() ) {
802 // shading color from properties is used only for non-physical materials
803 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
807 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
808 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
809 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
810 AISShape->Attributes()->SetLineAspect( anAspect );
812 // - unfree boundaries color
813 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
814 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
815 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
816 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
818 // - free boundaries color
819 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
820 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
821 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
822 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
824 // - standalone edges color
825 anAspect = AISShape->Attributes()->WireAspect();
826 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
827 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
828 AISShape->Attributes()->SetWireAspect( anAspect );
830 // - color for edges in shading+edges mode
831 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
834 AISShape->SetDisplayMode( HasDisplayMode() ?
835 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
837 // display mode from properties
838 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
840 // - face boundaries color
841 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
842 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
843 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
844 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
845 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
847 // set display vectors flag
848 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
850 // set display vertices flag
851 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
852 AISShape->SetDisplayVertices( isVerticesMode );
855 if( HasTransparency() ) {
856 AISShape->SetTransparency( GetTransparency() );
858 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
861 // set iso properties
862 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
863 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
864 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
865 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
866 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
867 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
868 uIsoAspect->SetColor( isosColor );
869 uIsoAspect->SetWidth( isosWidth );
870 uIsoAspect->SetNumber( uIsos );
871 vIsoAspect->SetColor( isosColor );
872 vIsoAspect->SetWidth( isosWidth );
873 vIsoAspect->SetNumber( vIsos );
874 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
875 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
877 // set deflection coefficient
878 // ... to avoid to small values of the coefficient, its lower value is limited
879 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
883 if ( HasTexture() ) {
884 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
885 aImagePath = GetTexture().c_str();
886 if ( ! entry.isEmpty() ) {
887 // check that study is active
888 SalomeApp_Study* study = getActiveStudy();
890 // Store the texture in object properties for next displays
891 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
892 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
894 // Update propeties map
895 propMap = getObjectProperties( study, entry, myViewFrame );
900 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
903 #ifdef USE_TEXTURED_SHAPE
904 Handle(Image_PixMap) aPixmap;
905 if ( !aImagePath.isEmpty() )
906 aPixmap = cacheTextureFor( aImagePath, AISShape );
908 aPixmap = getDefaultTexture();
910 // apply image to shape
911 if ( !aPixmap.IsNull() ) {
912 AISShape->SetTexturePixMap( aPixmap );
913 AISShape->SetTextureMapOn();
914 AISShape->DisableTextureModulate();
917 AISShape->SetTextureMapOff();
922 AISShape->SetWidth( HasWidth() ?
923 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
925 // libe width from properties
926 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
928 // set top-level flag
929 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
931 // set point marker (for vertex / compound of vertices only)
932 if ( onlyVertex || isVerticesMode ) {
933 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
934 if ( aList.size() == 2 ) {
935 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
936 int aTypeOfMarker = aList[0].toInt();
937 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
938 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
939 anAspect->SetScale( aScaleOfMarker );
940 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
941 anAspect->SetColor( HasColor() ?
942 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
943 (Quantity_NameOfColor)GetColor() :
944 // color from properties
945 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
946 AISShape->Attributes()->SetPointAspect( anAspect );
948 else if ( aList.size() == 1 ) {
949 // custom marker string contains "IdOfTexture"
950 int textureId = aList[0].toInt();
951 Standard_Integer aWidth, aHeight;
952 Handle(TColStd_HArray1OfByte) aTexture =
953 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
954 if ( !aTexture.IsNull() ) {
955 Handle(Prs3d_PointAspect) aTextureAspect =
956 new Prs3d_PointAspect( HasColor() ?
957 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
958 (Quantity_NameOfColor)GetColor() :
959 // color from properties
960 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
963 AISShape->Attributes()->SetPointAspect( aTextureAspect );
968 // set field step data
969 AISShape->setFieldStepInfo( myFieldDataType,
974 myFieldStepRangeMax );
976 if ( create && !isTemporary && aMgrId != -1 ) {
977 // set properties to the study
978 study->setObjectProperties( aMgrId, entry, propMap );
981 // AISShape->SetName(???); ??? necessary to set name ???
984 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
986 // check that actor is not null
987 if ( !actor ) return;
989 // check that study is active
990 SalomeApp_Study* study = getStudy();
991 if ( !study ) return;
993 // set interactive object
995 Handle( SALOME_InteractiveObject ) anIO;
997 if ( !myIO.IsNull() ) {
998 actor->setIO( myIO );
1001 else if ( !myName.empty() ) {
1002 // workaround to allow selection of temporary objects
1003 static int tempId = 0;
1004 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1005 actor->setIO( anIO );
1008 // presentation study entry (empty for temporary objects like preview)
1009 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1010 // flag: temporary object
1011 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1012 // currently active view window's ID (-1 if no active view)
1013 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1015 // get presentation properties
1016 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1019 /////////////////////////////////////////////////////////////////////////
1020 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1021 // due to performance problem
1022 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1023 /////////////////////////////////////////////////////////////////////////
1024 if ( !actor->getTopo().IsSame( myShape ) )
1025 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1028 Material_Model material;
1029 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1030 std::vector<vtkProperty*> mprops;
1031 mprops.push_back( material.getMaterialVTKProperty( true ) );
1032 mprops.push_back( material.getMaterialVTKProperty( false) );
1033 actor->SetMaterial( mprops );
1035 // set iso-lines properties
1037 // - set number of iso-lines
1038 int nbIsos[2]= { 1, 1 };
1039 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1040 nbIsos[0] = isos[0].toInt();
1041 nbIsos[1] = isos[1].toInt();
1042 actor->SetNbIsos( nbIsos );
1044 // - set iso-lines width
1045 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1047 // - set iso-lines color
1048 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1049 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1054 // - same color for all sub-actors
1055 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1056 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1059 // shading color (for non-physical materials)
1060 if ( !material.isPhysical() ) {
1061 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1062 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1063 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1066 // - standalone edge color
1067 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1068 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1070 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1071 // - shared edges color ???
1072 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1074 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1075 // - free edges color ???
1076 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1079 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1080 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1083 // - color for edges in shading+edges mode
1084 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1085 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1088 if( HasTransparency() ) {
1089 actor->SetOpacity( 1.0 - GetTransparency() );
1091 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1095 actor->SetWidth( HasWidth() ?
1096 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1098 // libe width from properties
1099 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1101 // set display vectors flag
1102 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1104 // set display vertices flag
1105 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1108 int displayMode = HasDisplayMode() ?
1109 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1111 // display mode from properties
1112 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1114 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1115 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1116 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1117 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1119 if ( displayMode == 2 )
1120 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1121 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1123 actor->setDisplayMode( displayMode );
1126 actor->PickableOn();
1128 actor->PickableOff();
1130 if ( create && !isTemporary && aMgrId != -1 ) {
1131 // set properties to the study
1132 study->setObjectProperties( aMgrId, entry, propMap );
1136 //=================================================================
1138 * GEOM_Displayer::updateDimensions
1139 * Creates or renews dimension presentation for the IO.
1141 //=================================================================
1142 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1143 SALOME_OCCPrs* thePrs,
1144 const gp_Ax3& theShapeLCS )
1146 SalomeApp_Study* aStudy = getStudy();
1152 if ( theIO.IsNull() )
1157 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1159 AIS_ListOfInteractive aListOfIO;
1161 anOccPrs->GetObjects( aListOfIO );
1163 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1165 // remove outdated presentations of dimensions
1166 for ( ; aIterateIO.More(); aIterateIO.Next() )
1168 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1169 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1174 aListOfIO.Remove( aIterateIO );
1176 if ( !aIterateIO.More() )
1182 // prepare dimension styling
1183 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1185 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1186 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1187 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1188 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1189 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1190 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1191 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1193 // restore dimension presentation from saved attribute or property data
1194 AIS_ListOfInteractive aRestoredDimensions;
1196 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1198 GEOM::propertyName( GEOM::Dimensions ),
1201 GEOMGUI_DimensionProperty aRecords;
1203 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1205 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1209 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1212 // create up-to-date dimension presentations
1213 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1215 if ( !aRecords.IsVisible( aPrsIt ) )
1220 // init dimension by type
1221 Handle(AIS_Dimension) aPrs;
1222 switch( aRecords.GetType( aPrsIt ) )
1224 case GEOMGUI_DimensionProperty::DimensionType_Length :
1226 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1227 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1232 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1234 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1235 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1240 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1242 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1243 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1249 aPrs->SetOwner( theIO );
1251 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1253 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1255 aStyle->SetCommonColor( aColor );
1256 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1257 aStyle->MakeText3d( Standard_True );
1258 aStyle->MakeTextShaded( Standard_True );
1259 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1260 aStyle->TextAspect()->SetHeight( aFontHeight );
1261 aStyle->ArrowAspect()->SetLength( anArrowLength );
1262 aStyle->LineAspect()->SetWidth( aLineWidth );
1263 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1264 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1265 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1266 aPrs->SetDimensionAspect( aStyle );
1267 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1268 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1269 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1271 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1273 // show degree symbol for dimension instead of label "deg"
1274 if ( aUnitsAngle == "deg" )
1276 aPrs->SetSpecialSymbol(0xB0);
1277 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1278 aStyle->MakeUnitsDisplayed(Standard_False);
1282 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1283 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1288 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1291 aListOfIO.Append( aPrs );
1294 // update presentation
1297 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1299 anOccPrs->AddObject( aIterateIO.Value() );
1303 //=================================================================
1305 * GEOM_Displayer::Erase
1306 * Calls Erase() method for each object in the given list
1308 //=================================================================
1309 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1311 const bool updateViewer )
1313 SALOME_ListIteratorOfListIO Iter( theIOList );
1314 for ( ; Iter.More(); Iter.Next() )
1315 Erase( Iter.Value(), forced, false );
1321 //=================================================================
1323 * GEOM_Displayer::Redisplay
1324 * Calls Redisplay() method for each object in the given list
1326 //=================================================================
1327 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1328 const bool updateViewer,
1329 const bool checkActiveViewer )
1331 SALOME_ListIteratorOfListIO Iter( theIOList );
1332 for ( ; Iter.More(); Iter.Next() )
1333 Redisplay( Iter.Value(), false, checkActiveViewer );
1339 //=================================================================
1341 * GEOM_Displayer::Redisplay
1342 * Calls Redisplay() method for each object in the given list
1344 //=================================================================
1345 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1346 const bool theUpdateViewer,
1347 SALOME_View* theViewFrame )
1349 SALOME_ListIteratorOfListIO anIter( theIOList );
1350 for ( ; anIter.More(); anIter.Next() )
1352 Redisplay( anIter.Value(), false, theViewFrame );
1355 if ( theUpdateViewer )
1361 //=================================================================
1363 * GEOM_Displayer::Update
1364 * Update OCC presentaion
1365 * [ Reimplemented from SALOME_Displayer ]
1367 //=================================================================
1368 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1370 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1371 SalomeApp_Study* study = getStudy();
1373 if ( !occPrs || myShape.IsNull() || !study )
1376 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1379 // specific processing for local coordinate system presentation
1382 TopoDS_Face aFace = TopoDS::Face( myShape );
1383 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1384 if ( !aPlane.IsNull() )
1386 gp_Ax3 aPos = aPlane->Pln().Position();
1387 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1389 Handle(GEOM_AISTrihedron) aTrh;
1391 if ( occPrs->IsNull() )
1393 // new presentation is being created
1394 aTrh = new GEOM_AISTrihedron( aPlc );
1395 occPrs->AddObject( aTrh );
1399 // presentation is being updated
1400 AIS_ListOfInteractive aList;
1401 occPrs->GetObjects( aList );
1402 AIS_ListIteratorOfListOfInteractive anIter( aList );
1403 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1404 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1408 if ( !aTrh.IsNull() ) {
1409 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1411 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1412 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1414 aTrh->SetWidth( GetWidth() );
1416 if ( !myIO.IsNull() )
1418 aTrh->setIO( myIO );
1419 aTrh->SetOwner( myIO );
1421 aTrh->SetComponent( aPlc );
1422 aTrh->SetToUpdate();
1424 occPrs->SetToActivate( ToActivate() );
1430 // processing for usual geometry presentation
1433 // if presentation is empty we try to create new one
1434 if ( occPrs->IsNull() )
1436 // create presentation (specific for vectors)
1437 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1438 : new GEOM_AISShape ( myShape, "" );
1440 if( myType == GEOM_FIELD_STEP )
1441 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1442 // update shape properties
1443 updateShapeProperties( AISShape, true );
1445 // add shape to the presentation
1446 occPrs->AddObject( AISShape );
1448 // In accordance with ToActivate() value object will be activated/deactivated
1449 // when it will be displayed
1450 occPrs->SetToActivate( ToActivate() );
1452 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1453 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1455 // create additional wireframe shape
1456 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1457 aWirePrs->SetWidth(AISShape->Width());
1458 if ( !myIO.IsNull() ) {
1459 aWirePrs->setIO( myIO );
1460 aWirePrs->SetOwner( myIO );
1463 // add shape to the presentation
1464 occPrs->AddObject( aWirePrs );
1467 // if presentation is found -> set again shape for it
1470 AIS_ListOfInteractive IOList;
1471 occPrs->GetObjects( IOList );
1472 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1473 for ( ; Iter.More(); Iter.Next() )
1475 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1476 if ( AISShape.IsNull() )
1479 // re-set shape (it might be changed)
1480 if ( AISShape->Shape() != myShape )
1481 AISShape->Set( myShape );
1483 // update shape properties
1484 updateShapeProperties( AISShape, false );
1487 AISShape->UpdateSelection();
1488 AISShape->SetToUpdate();
1492 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1496 //=================================================================
1498 * GEOM_Displayer::Update
1499 * Update VTK presentaion
1500 * [ Reimplemented from SALOME_Displayer ]
1502 //=================================================================
1503 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1505 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1506 SalomeApp_Study* study = getStudy();
1508 if ( !vtkPrs || myShape.IsNull() || !study )
1511 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1514 // specific processing for local coordinate system presentation
1517 TopoDS_Face aFace = TopoDS::Face( myShape );
1518 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1519 if ( !aPlane.IsNull() ) {
1520 gp_Ax3 aPos = aPlane->Pln().Position();
1521 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1523 GEOM_VTKTrihedron* aTrh = 0;
1525 if ( vtkPrs->IsNull() ) {
1526 // new presentation is being created
1527 aTrh = GEOM_VTKTrihedron::New();
1528 vtkPrs->AddObject( aTrh );
1531 // presentation is being updated
1532 vtkActorCollection* actors = vtkPrs->GetObjects();
1534 actors->InitTraversal();
1535 vtkActor* a = actors->GetNextActor();
1536 while ( a && !aTrh ) {
1537 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1538 a = actors->GetNextActor();
1544 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1546 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1547 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1549 #ifdef VTK_TRIHEDRON_WIDTH
1551 // VSR: currently isn't supported
1553 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1555 aTrh->SetWidth( GetWidth() );
1558 if ( !myIO.IsNull() )
1559 aTrh->setIO( myIO );
1561 aTrh->SetPlacement( aPlc );
1568 // processing for usual geometry presentation
1571 // if presentation is empty we try to create new one
1572 if ( vtkPrs->IsNull() )
1575 GEOM_Actor* actor = GEOM_Actor::New();
1576 // update actor properties
1577 updateActorProperties( actor, true );
1578 // add actor to the presentation
1579 vtkPrs->AddObject( actor );
1582 // presentation is being updated
1583 vtkActorCollection* actors = vtkPrs->GetObjects();
1585 actors->InitTraversal();
1586 vtkActor* a = actors->GetNextActor();
1588 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1590 // update actor properties
1591 updateActorProperties( actor, false );
1592 a = actors->GetNextActor();
1600 //=================================================================
1602 * GEOM_Displayer::BuildPrs
1603 * Build presentation accordint to the current viewer type
1605 //=================================================================
1606 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1608 if ( theObj->_is_nil() )
1611 myViewFrame = GetActiveView();
1612 if ( myViewFrame == 0 )
1615 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1620 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1621 myType = theObj->GetType();
1623 // Update presentation
1629 //=================================================================
1631 * GEOM_Displayer::BuildPrs
1632 * Build presentation accordint to the current viewer type
1634 //=================================================================
1635 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1637 myViewFrame = GetActiveView();
1638 if ( theShape.IsNull() || myViewFrame == 0 )
1641 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1646 setShape( theShape );
1654 //=================================================================
1656 * GEOM_Displayer::buildPresentation
1657 * Builds/finds object's presentation for the current viewer
1658 * Calls corresponding Update() method by means of double dispatch
1661 //=================================================================
1662 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1663 SALOME_View* theViewFrame )
1665 SALOME_Prs* prs = 0;
1668 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1672 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1675 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1676 theIO->setEntry( entry.toLatin1().constData() );
1677 if ( !theIO.IsNull() )
1679 // set interactive object
1681 // Find SOBject (because shape should be published previously)
1682 SUIT_Session* session = SUIT_Session::session();
1683 SUIT_Application* app = session->activeApplication();
1686 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1689 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1692 // get CORBA reference to data object
1693 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1694 if ( !CORBA::is_nil( object ) )
1696 // downcast to GEOM base object
1697 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1698 if ( !GeomBaseObject->_is_nil() )
1700 myType = GeomBaseObject->GetType();
1702 // downcast to GEOM object
1703 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1704 if ( myType == GEOM_FIELD_STEP )
1706 // get the GEOM object from the field's shape
1707 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1708 if ( !GeomFieldStep->_is_nil() )
1710 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1711 if ( !GeomField->_is_nil() )
1712 GeomObject = GeomField->GetShape();
1715 // read the field step information
1716 readFieldStepInfo( GeomFieldStep );
1719 if ( !GeomObject->_is_nil() )
1721 // finally set shape
1722 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1730 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1736 //=================================================================
1738 * GEOM_Displayer::buildSubshapePresentation
1739 * Builds/finds object's presentation for the current viewer
1740 * Calls corresponding Update() method by means of double dispatch
1741 * For not published objects (for Mantis issue 0020435)
1743 //=================================================================
1744 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1745 const QString& entry,
1746 SALOME_View* theViewFrame)
1748 SALOME_Prs* prs = 0;
1751 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1755 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1758 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1759 theIO->setEntry(entry.toLatin1().constData());
1760 if (!theIO.IsNull())
1762 // set interactive object
1764 // finally set shape
1766 myType = GEOM_SUBSHAPE;
1768 UpdatePrs(prs); // Update presentation by using of the double dispatch
1774 //=================================================================
1776 * GEOM_Displayer::internalReset
1777 * Resets internal data
1780 //=================================================================
1781 void GEOM_Displayer::internalReset()
1786 myFieldDataType = GEOM::FDT_Double;
1787 myFieldDimension = 0;
1788 myFieldStepData.clear();
1789 myFieldStepName.Clear();
1790 myFieldStepRangeMin = 0;
1791 myFieldStepRangeMax = 0;
1794 //=================================================================
1796 * GEOM_Displayer::LocalSelection
1797 * Activate selection of CAD shapes with activisation of selection
1798 * of their sub-shapes (with opened local context for OCC viewer)
1800 //=================================================================
1801 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1803 SUIT_Session* session = SUIT_Session::session();
1804 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1808 LightApp_SelectionMgr* sm = app->selectionMgr();
1810 // remove all filters from selection
1813 SALOME_View* vf = GetActiveView();
1815 if (!theIO.IsNull() && !vf->isVisible(theIO))
1817 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1818 vf->LocalSelection( prs, theMode );
1819 delete prs; // delete presentation because displayer is its owner
1823 //=================================================================
1825 * GEOM_Displayer::globalSelection
1826 * Activate selection of CAD shapes without activisation of selection
1827 * of their sub-shapes (without opened local context for OCC viewer)
1829 //=================================================================
1830 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1832 TColStd_MapOfInteger aModes;
1833 aModes.Add( theMode );
1834 GlobalSelection( aModes, update );
1837 //=================================================================
1839 * GEOM_Displayer::globalSelection
1840 * Activate selection of CAD shapes without activisation of selection
1841 * of their sub-shapes (without opened local context for OCC viewer)
1843 //=================================================================
1844 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1845 const bool update, const QList<int>* theSubShapes )
1847 SUIT_Session* session = SUIT_Session::session();
1848 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1852 SALOME_View* vf = GetActiveView();
1856 // Close local context
1857 vf->GlobalSelection( update );
1859 // Set selection filters in accordance with current mode
1860 LightApp_SelectionMgr* sm = app->selectionMgr();
1864 // Remove from selection temporary objects if necessary
1865 if ( !theModes.Contains( GEOM_PREVIEW ) )
1866 clearTemporary( sm );
1868 //@ aSel->ClearIndex();
1872 // Remove filters from AIS_InteractiveContext
1873 Handle(AIS_InteractiveContext) ic;
1874 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1877 ic = viewer->getAISContext();
1879 ic->RemoveFilters();
1882 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1885 SUIT_SelectionFilter* aFilter;
1886 if ( theModes.Extent() == 1 )
1888 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1890 if ( aMode == GEOM_COMPOUNDFILTER )
1891 aFilter = getComplexFilter( theSubShapes );
1893 aFilter = getFilter( aMode );
1895 else if ( theModes.Extent() > 1 )
1897 TColStd_MapOfInteger aTopAbsModes;
1898 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1899 QList<SUIT_SelectionFilter*> aListOfFilters;
1900 for ( ; anIter.More(); anIter.Next() )
1902 SUIT_SelectionFilter* aFilter;
1903 int aMode = anIter.Key();
1904 if ( aMode == GEOM_COMPOUNDFILTER )
1905 aFilter = getComplexFilter( theSubShapes );
1907 aFilter = getFilter( aMode );
1910 aListOfFilters.append( aFilter );
1913 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1920 sm->installFilter( aFilter );
1923 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1924 ic->AddFilter( anOCCFilter );
1929 //=================================================================
1931 * GEOM_Displayer::LocalSelection
1932 * Activate selection of CAD shapes with activisation of selection
1933 * of their sub-shapes (with opened local context for OCC viewer)
1935 //=================================================================
1936 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1938 SALOME_ListIteratorOfListIO Iter( theIOList );
1939 for ( ; Iter.More(); Iter.Next() )
1940 LocalSelection( Iter.Value(), theMode );
1943 //=================================================================
1945 * GEOM_Displayer::BeforeDisplay
1946 * Called before displaying of pars. Close local context
1947 * [ Reimplemented from SALOME_Displayer ]
1949 //=================================================================
1950 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1952 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1955 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1958 if ( ic->HasOpenedContext() )
1959 ic->CloseAllContexts();
1964 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1966 UpdateColorScale(false,false);
1969 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1971 LightApp_Displayer::BeforeErase( v, p );
1972 releaseTextures( p );
1975 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1977 LightApp_Displayer::AfterErase( v, p );
1978 UpdateColorScale(false,false);
1981 //=================================================================
1983 * GEOM_Displayer::SetColor
1984 * Set color for shape displaying. If it is equal -1 then default color is used.
1985 * Available values are from Quantity_NameOfColor enumeration
1987 //=================================================================
1988 void GEOM_Displayer::SetColor( const int color )
1995 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1999 int GEOM_Displayer::GetColor() const
2004 bool GEOM_Displayer::HasColor() const
2006 return myColor != -1;
2009 void GEOM_Displayer::UnsetColor()
2013 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2014 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2015 myShadingColor = SalomeApp_Tools::color( col );
2018 //=================================================================
2020 * GEOM_Displayer::SetTransparency
2021 * Set transparency for shape displaying.
2023 //=================================================================
2024 double GEOM_Displayer::SetTransparency( const double transparency )
2026 double aPrevTransparency = myTransparency;
2027 if ( transparency < 0 ) {
2028 UnsetTransparency();
2031 myTransparency = transparency;
2032 myHasTransparency = true;
2034 return aPrevTransparency;
2037 //=================================================================
2039 * GEOM_Displayer::GetTransparency
2040 * Get transparency for shape displaying.
2042 //=================================================================
2043 double GEOM_Displayer::GetTransparency() const
2045 return myTransparency;
2048 //=================================================================
2050 * GEOM_Displayer::HasTransparency
2051 * Check if transparency for shape displaying is set.
2053 //=================================================================
2054 bool GEOM_Displayer::HasTransparency() const
2056 return myHasTransparency;
2059 //=================================================================
2061 * GEOM_Displayer::UnsetTransparency
2062 * Unset transparency for shape displaying.
2064 //=================================================================
2065 double GEOM_Displayer::UnsetTransparency()
2067 double aPrevTransparency = myTransparency;
2068 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2069 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
2070 myHasTransparency = false;
2071 return aPrevTransparency;
2075 //=================================================================
2077 * GEOM_Displayer::SetTexture
2078 * Set color for shape displaying. If it is equal -1 then default color is used.
2079 * Available values are from Quantity_NameOfColor enumeration
2081 //=================================================================
2082 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2084 if(texureFileName!="")
2086 myTexture = texureFileName;
2090 bool GEOM_Displayer::HasTexture() const
2092 return myTexture != "";
2095 std::string GEOM_Displayer::GetTexture() const
2100 //=================================================================
2102 * GEOM_Displayer::SetWidth
2103 * Set width of shape displaying. If it is equal -1 then default width is used.
2105 //=================================================================
2106 void GEOM_Displayer::SetWidth( const double width )
2111 double GEOM_Displayer::GetWidth() const
2116 bool GEOM_Displayer::HasWidth() const
2118 return myWidth != -1;
2121 void GEOM_Displayer::UnsetWidth()
2127 int GEOM_Displayer::GetIsosWidth() const
2132 void GEOM_Displayer::SetIsosWidth(const int width)
2134 myIsosWidth = width;
2137 bool GEOM_Displayer::HasIsosWidth() const
2139 return myIsosWidth != -1;
2143 //=================================================================
2145 * GEOM_Displayer::SetToActivate
2146 * This method is used for activisation/deactivisation of objects to be displayed
2148 //=================================================================
2149 void GEOM_Displayer::SetToActivate( const bool toActivate )
2151 myToActivate = toActivate;
2153 bool GEOM_Displayer::ToActivate() const
2155 return myToActivate;
2158 //=================================================================
2160 * GEOM_Displayer::clearTemporary
2161 * Removes from selection temporary objects
2163 //=================================================================
2164 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2166 SALOME_ListIO selected, toSelect;
2167 theSelMgr->selectedObjects( selected );
2169 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2170 Handle(SALOME_InteractiveObject) io = it.Value();
2171 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2172 toSelect.Append( it.Value() );
2175 theSelMgr->setSelectedObjects( toSelect, true );
2178 void GEOM_Displayer::SetName( const char* theName )
2183 void GEOM_Displayer::UnsetName()
2188 SalomeApp_Study* GEOM_Displayer::getStudy() const
2190 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2193 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2198 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2203 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2204 const int theFieldDimension,
2205 const QList<QVariant>& theFieldStepData,
2206 const TCollection_AsciiString& theFieldStepName,
2207 const double theFieldStepRangeMin,
2208 const double theFieldStepRangeMax )
2210 myFieldDataType = theFieldDataType;
2211 myFieldDimension = theFieldDimension;
2212 myFieldStepData = theFieldStepData;
2213 myFieldStepName = theFieldStepName;
2214 myFieldStepRangeMin = theFieldStepRangeMin;
2215 myFieldStepRangeMax = theFieldStepRangeMax;
2218 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2220 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2221 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2222 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2223 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2224 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2225 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2228 int GEOM_Displayer::SetDisplayMode( const int theMode )
2230 int aPrevMode = myDisplayMode;
2231 if ( theMode != -1 ) {
2232 myDisplayMode = theMode;
2233 myHasDisplayMode = true;
2241 int GEOM_Displayer::GetDisplayMode() const
2243 return myDisplayMode;
2246 int GEOM_Displayer::UnsetDisplayMode()
2248 int aPrevMode = myDisplayMode;
2249 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2250 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2251 myHasDisplayMode = false;
2255 bool GEOM_Displayer::HasDisplayMode() const
2257 return myHasDisplayMode;
2260 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2262 static QList<QColor> colors;
2264 if ( colors.isEmpty() ) {
2266 for (int s = 0; s < 2 ; s++)
2268 for (int v = 100; v >= 40; v = v - 20)
2270 for (int h = 0; h < 359 ; h = h + 60)
2272 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2278 static int currentColor = randomize( colors.size() );
2280 SALOMEDS::Color color;
2281 color.R = (double)colors[currentColor].red() / 255.0;
2282 color.G = (double)colors[currentColor].green() / 255.0;
2283 color.B = (double)colors[currentColor].blue() / 255.0;
2285 currentColor = (currentColor+1) % colors.count();
2290 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2293 int aTolerance = 64;
2294 int anIterations = 0;
2300 if( anIterations % aPeriod == 0 )
2303 if( aTolerance < 1 )
2306 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2308 aHue = (int)( 360.0 * rand() / RAND_MAX );
2309 //std::cout << "Hue = " << aHue << std::endl;
2311 //std::cout << "Auto colors : ";
2313 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2314 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2315 for( ; it != itEnd; ++it )
2317 SALOMEDS::Color anAutoColor = *it;
2318 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2321 aQColor.getHsv( &h, &s, &v );
2322 //std::cout << h << " ";
2323 if( abs( h - aHue ) < aTolerance )
2326 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2330 //std::cout << std::endl;
2336 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2338 aColor.setHsv( aHue, 255, 255 );
2340 SALOMEDS::Color aSColor;
2341 aSColor.R = (double)aColor.red() / 255.0;
2342 aSColor.G = (double)aColor.green() / 255.0;
2343 aSColor.B = (double)aColor.blue() / 255.0;
2348 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2349 const QString& entry,
2352 // get default properties for the explicitly specified default view type
2353 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2355 if ( study && view ) {
2356 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2357 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2358 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2360 if ( viewModel && viewId != -1 ) {
2361 // get properties from the study
2362 PropMap storedMap = study->getObjectProperties( viewId, entry );
2363 // overwrite default properties from stored ones (that are specified)
2364 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2365 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2366 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2367 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2369 // ... specific processing for color
2370 // ... current implementation is to use same stored color for all aspects
2371 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2372 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2373 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2374 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2375 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2376 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2377 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2380 if ( !entry.isEmpty() ) {
2381 // get CORBA reference to geom object
2382 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2384 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2385 if ( !CORBA::is_nil( object ) ) {
2386 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2387 if ( !CORBA::is_nil( geomObject ) ) { // to check
2388 // check that geom object has color properly set
2389 bool hasColor = false;
2390 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2391 // set color from geometry object (only once, if it is not yet set in GUI)
2392 // current implementation is to use same color for all aspects
2393 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2394 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2395 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2396 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2397 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2398 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2399 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2400 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2402 // check that object has point marker properly set
2403 GEOM::marker_type mType = geomObject->GetMarkerType();
2404 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2405 int mTextureId = geomObject->GetMarkerTexture();
2406 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2407 ( mType == GEOM::MT_USER && mTextureId > 0 );
2408 // set point marker from geometry object (only once, if it is not yet set in GUI)
2409 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2410 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2412 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2413 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2415 else if ( mType == GEOM::MT_USER ) {
2417 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2429 PropMap GEOM_Displayer::getDefaultPropertyMap()
2433 // get resource manager
2434 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2436 // fill in the properties map with default values
2438 // - visibility (false by default)
2439 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2441 // - nb isos (take default value from preferences)
2442 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2443 QString( "%1%2%3" ).
2444 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2445 arg( GEOM::subSectionSeparator() ).
2446 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2448 // - transparency (opacity = 1-transparency)
2449 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2450 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2452 // - display mode (take default value from preferences)
2453 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2454 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2456 // - show edges direction flag (false by default)
2457 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2459 // - show vertices flag (false by default)
2460 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2462 // - shading color (take default value from preferences)
2463 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2464 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2466 // - wireframe color (take default value from preferences)
2467 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2468 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2470 // - standalone edges color (take default value from preferences)
2471 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2472 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2474 // - free boundaries color (take default value from preferences)
2475 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2476 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2478 // - points color (take default value from preferences)
2479 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2480 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2482 // - isos color (take default value from preferences)
2483 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2484 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2486 // - outlines color (take default value from preferences)
2487 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2488 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2490 // - deflection coefficient (take default value from preferences)
2491 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2492 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2494 // - material (take default value from preferences)
2495 Material_Model material;
2496 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2497 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2499 // - edge width (take default value from preferences)
2500 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2501 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2503 // - isos width (take default value from preferences)
2504 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2505 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2507 // - point marker (take default value from preferences)
2508 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2509 QString( "%1%2%3" ).
2510 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2511 arg( GEOM::subSectionSeparator() ).
2512 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2514 // - top-level flag (false by default)
2515 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2520 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2521 SALOMEDS::Color aSColor;
2524 SUIT_Session* session = SUIT_Session::session();
2525 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2527 if ( app && !theGeomObject->_is_nil()) {
2528 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2531 _PTR(Study) aStudy = study->studyDS();
2532 aSColor = theGeomObject->GetColor();
2533 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2535 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2536 bool general_autocolor = true;
2537 #else // auto-color for groups only
2538 bool general_autocolor = false;
2539 #endif // GENERAL_AUTOCOLOR
2540 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2541 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2542 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2543 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2544 aSColor = getPredefinedUniqueColor();
2546 #else // old algorithm for auto-colors
2547 QList<SALOMEDS::Color> aReservedColors;
2548 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2549 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2550 if ( aMainSObject ) {
2551 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2552 for ( ; it->More(); it->Next() ) {
2553 _PTR(SObject) aChildSObject( it->Value() );
2554 GEOM::GEOM_Object_var aChildObject =
2555 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2556 if ( CORBA::is_nil( aChildObject ) )
2559 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2560 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2561 aReservedColors.append( aReservedColor );
2564 aSColor = getUniqueColor( aReservedColors );
2566 #endif // SIMPLE_AUTOCOLOR
2576 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2577 const bool eraseOnlyChildren) {
2578 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2582 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2586 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2591 // Erase from all views
2592 QList<SALOME_View*> views;
2594 ViewManagerList vmans = app->viewManagers();
2595 SUIT_ViewManager* vman;
2596 foreach ( vman, vmans ) {
2597 SUIT_ViewModel* vmod = vman->getViewModel();
2598 view = dynamic_cast<SALOME_View*> ( vmod );
2600 views.append( view );
2603 if( views.count() == 0 )
2606 //Erase childrens w/o update views
2607 DataObjectList listObj = parent->children( true );
2608 SUIT_DataObject* obj;
2609 foreach( obj, listObj ) {
2610 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2612 foreach ( view, views ) {
2613 Handle(SALOME_InteractiveObject) anIO =
2614 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2615 Erase(anIO, false, false, view);
2619 //Erase parent with view update or repaint views
2620 foreach ( view, views ) {
2621 if(!eraseOnlyChildren)
2622 Erase(theIO, false, true, view);
2628 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2630 if( theGeomFieldStep->_is_nil() )
2633 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2634 if( aGeomField->_is_nil() )
2637 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2638 if( aGeomFieldShape->_is_nil() )
2641 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2642 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2643 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2645 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2647 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2649 int aFieldDimension = aGeomField->GetDimension();
2651 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2652 int aFieldNbComponents = aFieldComponents->length();
2654 QList<QVariant> aFieldStepData;
2655 if( aFieldDataType == GEOM::FDT_Bool )
2657 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2658 if ( !aGeomBoolFieldStep->_is_nil() )
2660 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2661 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2662 aFieldStepData << (bool)aValues[i];
2665 else if( aFieldDataType == GEOM::FDT_Int )
2667 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2668 if ( !aGeomIntFieldStep->_is_nil() )
2670 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2671 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2672 aFieldStepData << (qlonglong)aValues[i];
2675 else if( aFieldDataType == GEOM::FDT_Double )
2677 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2678 if ( !aGeomDoubleFieldStep->_is_nil() )
2680 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2681 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2682 aFieldStepData << (double)aValues[i];
2685 else if( aFieldDataType == GEOM::FDT_String )
2687 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2688 if ( !aGeomStringFieldStep->_is_nil() )
2690 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2691 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2692 aFieldStepData << QString( aValues[i] );
2696 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2697 aFieldStepData = groupFieldData( aFieldStepData,
2699 aFieldDataType == GEOM::FDT_String,
2701 aFieldStepRangeMax );
2703 setFieldStepInfo( aFieldDataType,
2708 aFieldStepRangeMax );
2711 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2712 const int theFieldNbComponents,
2713 const bool theIsString,
2714 double& theFieldStepRangeMin,
2715 double& theFieldStepRangeMax )
2717 QList<QVariant> aResultList;
2718 theFieldStepRangeMin = 0;
2719 theFieldStepRangeMax = 0;
2721 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2724 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2726 QList<QVariant> aGroupedList;
2728 bool anIsBoolean = false;
2729 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2732 QStringList aStringList;
2734 int aBaseIndex = aSubShape * theFieldNbComponents;
2735 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2737 int anIndex = aComponent + aBaseIndex;
2739 const QVariant& aVariant = theFieldStepData[ anIndex ];
2742 if( aVariant.type() == QVariant::String )
2743 aStringList << aVariant.toString();
2748 if( aVariant.type() == QVariant::Bool )
2750 aValue = aVariant.toBool() ? 1.0 : 0.0;
2756 if( aVariant.type() == QVariant::LongLong )
2757 aValue = double( aVariant.toLongLong() );
2758 else if( aVariant.type() == QVariant::Double )
2759 aValue = aVariant.toDouble();
2760 aNorm += aValue * aValue;
2766 aGroupedList << aStringList.join( "\n" );
2770 aNorm /= theFieldNbComponents;
2772 aNorm = pow( aNorm, 0.5 );
2774 if( aGroupedList.isEmpty() )
2775 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2778 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2779 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2782 aGroupedList << aNorm;
2788 theFieldStepRangeMin = 0.0;
2789 theFieldStepRangeMax = 1.0;
2792 SUIT_Session* session = SUIT_Session::session();
2793 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2794 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2796 QListIterator<QVariant> anIter( aGroupedList );
2797 while( anIter.hasNext() )
2799 const QVariant& aVariant = anIter.next();
2801 aResultList << aVariant;
2805 Quantity_Color aColor;
2806 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2807 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2808 aResultList << aQColor;
2814 // Note: the method is copied from Aspect_ColorScale class
2815 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2816 const Standard_Integer aMin,
2817 const Standard_Integer aMax )
2819 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2821 Standard_Integer aHue = maxLimit;
2823 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2825 aHue = Min( Max( minLimit, aHue ), maxLimit );
2830 // Note: the method is copied from Aspect_ColorScale class
2831 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2832 const Standard_Real aMin,
2833 const Standard_Real aMax,
2834 const Standard_Integer ColorsCount,
2835 Quantity_Color& aColor )
2837 if( aValue<aMin || aValue>aMax || aMax<aMin )
2838 return Standard_False;
2842 Standard_Real IntervNumber = 0;
2845 else if( aValue>aMax )
2846 IntervNumber = ColorsCount-1;
2847 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2848 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2850 Standard_Integer Interv = Standard_Integer( IntervNumber );
2852 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2854 return Standard_True;
2858 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2860 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2864 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2868 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2869 if( aViewer.IsNull() )
2872 aViewer->InitActiveViews();
2873 if( !aViewer->MoreActiveViews() )
2876 Handle(V3d_View) aView = aViewer->ActiveView();
2877 if( aView.IsNull() )
2880 Standard_Boolean anIsDisplayColorScale = Standard_False;
2881 TCollection_AsciiString aColorScaleTitle;
2882 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2883 Standard_Boolean anIsBoolean = Standard_False;
2885 SALOME_ListIO aSelectedObjects;
2886 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2887 if( aSelectedObjects.Extent() == 1 )
2889 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2890 if( !anIO.IsNull() )
2892 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2895 AIS_ListOfInteractive aList;
2896 aPrs->GetObjects( aList );
2897 AIS_ListIteratorOfListOfInteractive anIter( aList );
2898 for( ; anIter.More(); anIter.Next() )
2900 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2901 if( !aShape.IsNull() )
2903 GEOM::field_data_type aFieldDataType;
2904 int aFieldDimension;
2905 QList<QVariant> aFieldStepData;
2906 TCollection_AsciiString aFieldStepName;
2907 double aFieldStepRangeMin, aFieldStepRangeMax;
2908 aShape->getFieldStepInfo( aFieldDataType,
2913 aFieldStepRangeMax );
2914 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2916 anIsDisplayColorScale = Standard_True;
2917 aColorScaleTitle = aFieldStepName;
2918 aColorScaleMin = aFieldStepRangeMin;
2919 aColorScaleMax = aFieldStepRangeMax;
2920 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2928 if( anIsDisplayColorScale )
2930 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2931 if( !aColorScale.IsNull() )
2933 SUIT_Session* session = SUIT_Session::session();
2934 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2936 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2937 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2938 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2939 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2940 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2941 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2943 aColorScale->SetXPosition( anXPos );
2944 aColorScale->SetYPosition( anYPos );
2945 aColorScale->SetWidth( aWidth );
2946 aColorScale->SetHeight( aHeight );
2948 aColorScale->SetTextHeight( aTextHeight );
2949 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2951 aColorScale->SetTitle( aColorScaleTitle );
2952 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2954 if( !aView->ColorScaleIsDisplayed() )
2955 aView->ColorScaleDisplay();
2959 if( aView->ColorScaleIsDisplayed() )
2960 aView->ColorScaleErase();
2963 if( theIsRedisplayFieldSteps )
2965 _PTR(Study) aStudyDS = aStudy->studyDS();
2966 QList<SUIT_ViewManager*> vmList;
2967 myApp->viewManagers( vmList );
2968 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2970 if( SUIT_ViewManager* aViewManager = *vmIt )
2972 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
2973 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2975 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2978 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2979 if( !CORBA::is_nil( anObject ) )
2981 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2982 if( !aFieldStep->_is_nil() )
2984 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2985 Handle(SALOME_InteractiveObject) aStepIO =
2986 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2987 Redisplay( aStepIO, false, false );