1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
28 #include "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
59 #include <Basics_OCCTVersion.hxx>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
68 #include <SALOME_ListIO.hxx>
69 #include <SALOME_Prs.h>
72 #include <SOCC_ViewModel.h>
75 #include <SVTK_ViewModel.h>
77 #include <OCCViewer_ViewWindow.h>
78 #include <OCCViewer_ViewPort3d.h>
79 #include <OCCViewer_Utilities.h>
82 #include <AIS_Drawer.hxx>
83 #include <AIS_Dimension.hxx>
84 #include <AIS_LengthDimension.hxx>
85 #include <AIS_DiameterDimension.hxx>
86 #include <AIS_AngleDimension.hxx>
87 #include <AIS_ListIteratorOfListOfInteractive.hxx>
88 #include <Aspect_PolygonOffsetMode.hxx>
89 #include <Aspect_ColorScale.hxx>
90 #include <Prs3d_IsoAspect.hxx>
91 #include <Prs3d_PointAspect.hxx>
92 #include <StdSelect_TypeOfEdge.hxx>
93 #include <StdSelect_TypeOfFace.hxx>
94 #include <StdSelect_DisplayMode.hxx>
95 #include <TopoDS_Face.hxx>
96 #include <BRep_Tool.hxx>
97 #include <Geom_Plane.hxx>
98 #include <Geom_Axis2Placement.hxx>
99 #include <Graphic3d_AspectFillArea3d.hxx>
100 #include <gp_Pln.hxx>
101 #include <TColStd_MapOfInteger.hxx>
102 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
103 #include <TopoDS_Iterator.hxx>
104 #include <Graphic3d_AspectMarker3d.hxx>
105 #include <TopTools_MapOfShape.hxx>
106 #include <TopTools_ListOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopoDS.hxx>
109 #include <NCollection_DataMap.hxx>
110 #include <NCollection_Map.hxx>
112 #include <Prs3d_ShadingAspect.hxx>
114 #include <BRepMesh_IncrementalMesh.hxx>
117 #include <vtkActorCollection.h>
118 #include <vtkProperty.h>
121 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
123 #include <GEOMImpl_Types.hxx>
125 #include <TColStd_HArray1OfByte.hxx>
127 // If the next macro is defined, autocolor feature works for all sub-shapes;
128 // if it is undefined, autocolor feature works for groups only
129 #define GENERAL_AUTOCOLOR
130 // Below macro, when uncommented, switches on simplified (more performant) algorithm
131 // of auto-color picking up
132 #define SIMPLE_AUTOCOLOR
134 // Hard-coded value of shape deflection coefficient for VTK viewer
135 const double VTK_MIN_DEFLECTION = 0.001;
137 // Pixmap caching support
140 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
141 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
142 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
144 static inline PixmapUsageMap& getPixmapUsageMap()
146 static PixmapUsageMap aMap;
150 static inline PixmapCacheMap& getPixmapCacheMap()
152 static PixmapCacheMap aMap;
156 //===========================================================================
157 // Function : getDefaultTexture
158 // Purpose : Get default texture
159 //===========================================================================
160 static inline Handle(Image_PixMap) getDefaultTexture()
162 static Handle(Image_PixMap) aPixmap;
163 if ( aPixmap.IsNull() ) {
164 QPixmap px(":images/default_texture.png");
166 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
171 //===========================================================================
172 // Function : cacheTextureFor
173 // Purpose : Load and cache image for the specified presentation.
174 //===========================================================================
175 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
176 const Handle(GEOM_AISShape)& theShape )
178 if ( thePath.isEmpty() )
181 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
182 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
184 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
185 if ( !aPixmap.IsNull() ) {
186 // point that the texture is used by the presentation
187 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
188 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
190 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
195 // convert texture to compatible image format
196 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
197 if ( anImage.isNull() )
200 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
202 aPixmapCacheMap.insert( thePath, aPixmap );
204 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
205 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
207 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
212 //===========================================================================
213 // Function : releaseTextures
214 // Purpose : Releases cached textures found for the specified presentation.
215 //===========================================================================
216 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
218 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
220 AIS_ListOfInteractive aListOfIO;
222 anOccPrs->GetObjects( aListOfIO );
224 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
226 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
227 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
229 for ( ; aIterateIO.More(); aIterateIO.Next() )
231 Handle(GEOM_AISShape) aAISShape =
232 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
234 if ( aAISShape.IsNull() )
237 #ifdef USE_TEXTURED_SHAPE
238 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
239 if ( aPixmap.IsNull() )
242 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
245 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
247 aUsersShapes.Remove( aAISShape );
249 if ( aUsersShapes.IsEmpty() ) {
250 aPixmapUsersMap.UnBind( aPixmap );
251 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
257 uint randomize( uint size )
259 static bool initialized = false;
260 if ( !initialized ) {
261 qsrand( QDateTime::currentDateTime().toTime_t() );
265 v = uint( (double)( v ) / RAND_MAX * size );
266 v = qMax( uint(0), qMin ( v, size-1 ) );
271 //================================================================
272 // Function : getActiveStudy
273 // Purpose : Get active study, returns 0 if no open study frame
274 //================================================================
275 static inline SalomeApp_Study* getActiveStudy()
277 SUIT_Session* session = SUIT_Session::session();
278 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
280 return ( SalomeApp_Study* )app->activeStudy();
284 static inline int getViewManagerId( SALOME_View* theViewFrame) {
285 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
286 SUIT_ViewManager* aViewMgr = 0;
288 aViewMgr = aModel->getViewManager();
289 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
292 //================================================================
293 // Function : getTopAbsMode
294 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
295 // one from GEOMImpl_Types.h
296 //================================================================
297 static inline int getTopAbsMode( const int implType )
301 case GEOM_COMPOUND : return TopAbs_COMPOUND;
302 case GEOM_SOLID : return TopAbs_SOLID;
303 case GEOM_SHELL : return TopAbs_SHELL;
304 case GEOM_FACE : return TopAbs_FACE;
305 case GEOM_WIRE : return TopAbs_WIRE;
306 case GEOM_EDGE : return TopAbs_EDGE;
307 case GEOM_POINT : return TopAbs_VERTEX;
312 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
314 if ( shape.IsNull() )
317 int ret = shape.ShapeType();
319 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
320 TopoDS_Iterator it(shape, Standard_True, Standard_False);
321 for (; it.More(); it.Next()) {
322 TopoDS_Shape sub_shape = it.Value();
323 if ( sub_shape.IsNull() ) continue;
324 int stype = getMinMaxShapeType( sub_shape, ismin );
325 if ( stype == TopAbs_SHAPE ) continue;
326 if ( ismin && stype > ret )
328 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
336 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
338 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
341 //================================================================
342 // Function : getFilter
343 // Purpose : Get filter corresponding to the type of object
344 // from GEOMImpl_Types.h
345 //================================================================
346 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
348 SUIT_SelectionFilter* aFilter;
350 int aTopAbsMode = getTopAbsMode( theMode );
351 if ( aTopAbsMode != -1 )
352 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
356 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
357 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
359 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
360 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
361 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
362 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
363 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
364 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
366 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
368 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
369 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
371 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
377 //================================================================
378 // Function : getComplexFilter
379 // Purpose : Get compound filter corresponding to the type of
380 // object from GEOMImpl_Types.h
381 //================================================================
382 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
384 GEOM_CompoundFilter* aFilter;
386 if(aSubShapes != NULL ) {
387 aFilter = new GEOM_CompoundFilter(getStudy());
388 QList<int> aTopAbsTypes;
389 QList<int>::const_iterator it;
390 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
391 int topAbsMode = getTopAbsMode(*it);
392 if(topAbsMode != -1 )
393 aTopAbsTypes.append(topAbsMode);
395 aFilter->addSubTypes(aTopAbsTypes);
401 //================================================================
402 // Function : getEntry
404 //================================================================
405 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
407 SUIT_Session* session = SUIT_Session::session();
408 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
411 CORBA::String_var IOR = app->orb()->object_to_string( object );
412 if ( strcmp(IOR.in(), "") != 0 )
414 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
415 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
423 //================================================================
424 // Function : getName
426 //================================================================
427 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
429 SUIT_Session* session = SUIT_Session::session();
430 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
433 CORBA::String_var IOR = app->orb()->object_to_string( object );
434 if ( strcmp(IOR.in(), "") != 0 )
436 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
437 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
439 _PTR(GenericAttribute) anAttr;
441 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
443 _PTR(AttributeName) aNameAttr( anAttr );
444 return aNameAttr->Value();
452 //=================================================================
454 * GEOM_Displayer::GEOM_Displayer
457 //=================================================================
458 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
461 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
466 SUIT_Session* session = SUIT_Session::session();
467 SUIT_ResourceMgr* resMgr = session->resourceMgr();
469 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
470 myShadingColor = SalomeApp_Tools::color( col );
472 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
473 myHasDisplayMode = false;
475 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
476 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
477 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
479 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
480 myHasTransparency = false;
482 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
483 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
484 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
487 // This color is used for shape displaying. If it is equal -1 then
488 // default color is used.
494 // This parameter is used for activisation/deactivisation of objects to be displayed
496 // Activate parallel vizualisation only for testing purpose
497 // and if the corresponding env variable is set to 1
498 char* parallel_visu = getenv("PARALLEL_VISU");
499 if (parallel_visu && atoi(parallel_visu))
501 MESSAGE("Parallel visualisation on");
502 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
507 myFieldDataType = GEOM::FDT_Double;
508 myFieldDimension = 0;
509 myFieldStepRangeMin = 0;
510 myFieldStepRangeMax = 0;
513 //=================================================================
515 * GEOM_Displayer::~GEOM_Displayer
518 //=================================================================
519 GEOM_Displayer::~GEOM_Displayer()
523 //=================================================================
525 * GEOM_Displayer::Display
526 * Display interactive object in the current viewer
528 //=================================================================
529 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
530 const bool updateViewer,
531 SALOME_View* theViewFrame )
533 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
536 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
540 vf->BeforeDisplay( this, prs );
541 vf->Display( this, prs );
542 vf->AfterDisplay( this, prs );
547 delete prs; // delete presentation because displayer is its owner
552 //=================================================================
554 * GEOM_Displayer::Display
555 * This overloaded Display() method can be useful for operations
556 * not using dialog boxes.
558 //=================================================================
559 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
561 if ( theObj->_is_nil() )
564 std::string entry = getEntry( theObj );
566 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
571 //=================================================================
573 * GEOM_Displayer::Erase
574 * Erase interactive object in the current viewer
576 //=================================================================
577 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
579 const bool updateViewer,
580 SALOME_View* theViewFrame )
582 if ( theIO.IsNull() )
585 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
588 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
590 vf->BeforeErase( this, prs );
591 vf->Erase( this, prs, forced );
592 vf->AfterErase( this, prs );
595 delete prs; // delete presentation because displayer is its owner
600 //=================================================================
602 * GEOM_Displayer::Erase
603 * Erase geometry object in the current viewer
605 //=================================================================
606 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
608 const bool updateViewer,
609 SALOME_View* theViewFrame)
611 std::string entry = getEntry( theObj );
614 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
615 forced, updateViewer, theViewFrame);
619 //=================================================================
621 * GEOM_Displayer::Redisplay
622 * Redisplay (erase and then display again) interactive object
623 * in the current viewer
625 //=================================================================
626 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
627 const bool updateViewer,
628 const bool checkActiveViewer )
630 // Remove the object permanently (<forced> == true)
631 SUIT_Session* ses = SUIT_Session::session();
632 SUIT_Application* app = ses->activeApplication();
635 SUIT_Desktop* desk = app->desktop();
636 QList<SUIT_ViewWindow*> wnds = desk->windows();
637 SUIT_ViewWindow* wnd;
638 QListIterator<SUIT_ViewWindow*> it( wnds );
639 while ( it.hasNext() && (wnd = it.next()) )
641 SUIT_ViewManager* vman = wnd->getViewManager();
644 SUIT_ViewModel* vmodel = vman->getViewModel();
647 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
650 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
652 Redisplay( theIO, updateViewer, view );
661 //=================================================================
663 * GEOM_Displayer::Redisplay
664 * Redisplay (erase and then display again) interactive object
665 * in the specified view
667 //=================================================================
668 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
669 const bool theUpdateViewer,
670 SALOME_View* theViewFrame )
672 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
678 Erase( theIO, true, false, theViewFrame );
679 Display( theIO, theUpdateViewer, theViewFrame );
682 //=================================================================
684 * GEOM_Displayer::Display
685 * Calls Display() method for each object in the given list
687 //=================================================================
688 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
690 SALOME_ListIteratorOfListIO Iter( theIOList );
691 for ( ; Iter.More(); Iter.Next() ) {
692 Display( Iter.Value(), false );
698 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
700 SalomeApp_Study* aStudy = getStudy();
702 if ( v ) vId = getViewManagerId( v );
705 QString entry = p->GetEntry();
706 if ( !entry.isEmpty() ) {
708 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
709 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
714 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
719 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
721 // VSR: this method can be improved in future:
722 // to improve performance, the default values from resource manager should be cached in the displayer
723 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
726 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
728 // VSR: this method can be improved in future:
729 // to improve performance, the default values from resource manager should be cached in the displayer
730 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
733 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
735 // check that shape is not null
736 if ( AISShape.IsNull() ) return;
738 // check that study is active
739 SalomeApp_Study* study = getStudy();
740 if ( !study ) return;
742 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
743 !TopoDS_Iterator(myShape).More() )
744 return; // NPAL15983 (Bug when displaying empty groups)
746 // set interactive object
748 Handle( SALOME_InteractiveObject ) anIO;
750 if ( !myIO.IsNull() ) {
751 AISShape->setIO( myIO );
752 AISShape->SetOwner( myIO );
755 else if ( !myName.empty() ) {
756 // workaround to allow selection of temporary objects
757 static int tempId = 0;
758 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
759 AISShape->setIO( anIO );
760 AISShape->SetOwner( anIO );
763 // flag: only vertex or compound of vertices is processed (specific handling)
764 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
765 // presentation study entry (empty for temporary objects like preview)
766 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
767 // flag: temporary object
768 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
769 // currently active view window's ID (-1 if no active view)
770 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
772 // get presentation properties
773 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
775 // Temporary staff: vertex must be infinite for correct visualization
776 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
779 Material_Model material;
780 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
782 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
783 // - set front material properties
784 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
785 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
786 // - set back material properties
787 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
788 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
789 // - switch to default (both sides) facing mode
790 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
796 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
797 // we set it to the shape not taking into account material properties
798 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
800 else if ( !material.isPhysical() ) {
801 // shading color from properties is used only for non-physical materials
802 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
806 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
807 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
808 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
809 AISShape->Attributes()->SetLineAspect( anAspect );
811 // - unfree boundaries color
812 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
813 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
814 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
815 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
817 // - free boundaries color
818 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
819 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
820 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
821 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
823 // - standalone edges color
824 anAspect = AISShape->Attributes()->WireAspect();
825 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
826 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
827 AISShape->Attributes()->SetWireAspect( anAspect );
829 // - color for edges in shading+edges mode
830 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
833 AISShape->SetDisplayMode( HasDisplayMode() ?
834 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
836 // display mode from properties
837 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
839 // - face boundaries color
840 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
841 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
842 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
843 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
844 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
846 // set display vectors flag
847 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
849 // set display vertices flag
850 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
851 AISShape->SetDisplayVertices( isVerticesMode );
854 if( HasTransparency() ) {
855 AISShape->SetTransparency( GetTransparency() );
857 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
860 // set iso properties
861 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
862 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
863 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
864 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
865 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
866 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
867 uIsoAspect->SetColor( isosColor );
868 uIsoAspect->SetWidth( isosWidth );
869 uIsoAspect->SetNumber( uIsos );
870 vIsoAspect->SetColor( isosColor );
871 vIsoAspect->SetWidth( isosWidth );
872 vIsoAspect->SetNumber( vIsos );
873 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
874 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
876 // set deflection coefficient
877 // ... to avoid to small values of the coefficient, its lower value is limited
878 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
882 if ( HasTexture() ) {
883 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
884 aImagePath = GetTexture().c_str();
885 if ( ! entry.isEmpty() ) {
886 // check that study is active
887 SalomeApp_Study* study = getActiveStudy();
889 // Store the texture in object properties for next displays
890 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
891 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
893 // Update propeties map
894 propMap = getObjectProperties( study, entry, myViewFrame );
899 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
902 #ifdef USE_TEXTURED_SHAPE
903 Handle(Image_PixMap) aPixmap;
904 if ( !aImagePath.isEmpty() )
905 aPixmap = cacheTextureFor( aImagePath, AISShape );
907 aPixmap = getDefaultTexture();
909 // apply image to shape
910 if ( !aPixmap.IsNull() ) {
911 AISShape->SetTexturePixMap( aPixmap );
912 AISShape->SetTextureMapOn();
913 AISShape->DisableTextureModulate();
916 AISShape->SetTextureMapOff();
921 AISShape->SetWidth( HasWidth() ?
922 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
924 // libe width from properties
925 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
927 // set top-level flag
928 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
930 // set point marker (for vertex / compound of vertices only)
931 if ( onlyVertex || isVerticesMode ) {
932 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
933 if ( aList.size() == 2 ) {
934 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
935 int aTypeOfMarker = aList[0].toInt();
936 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
937 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
938 anAspect->SetScale( aScaleOfMarker );
939 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
940 anAspect->SetColor( HasColor() ?
941 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
942 (Quantity_NameOfColor)GetColor() :
943 // color from properties
944 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
945 AISShape->Attributes()->SetPointAspect( anAspect );
947 else if ( aList.size() == 1 ) {
948 // custom marker string contains "IdOfTexture"
949 int textureId = aList[0].toInt();
950 Standard_Integer aWidth, aHeight;
951 Handle(TColStd_HArray1OfByte) aTexture =
952 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
953 if ( !aTexture.IsNull() ) {
954 Handle(Prs3d_PointAspect) aTextureAspect =
955 new Prs3d_PointAspect( HasColor() ?
956 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
957 (Quantity_NameOfColor)GetColor() :
958 // color from properties
959 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
962 AISShape->Attributes()->SetPointAspect( aTextureAspect );
967 // set field step data
968 AISShape->setFieldStepInfo( myFieldDataType,
973 myFieldStepRangeMax );
975 if ( create && !isTemporary && aMgrId != -1 ) {
976 // set properties to the study
977 study->setObjectProperties( aMgrId, entry, propMap );
980 // AISShape->SetName(???); ??? necessary to set name ???
983 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
985 // check that actor is not null
986 if ( !actor ) return;
988 // check that study is active
989 SalomeApp_Study* study = getStudy();
990 if ( !study ) return;
992 // set interactive object
994 Handle( SALOME_InteractiveObject ) anIO;
996 if ( !myIO.IsNull() ) {
997 actor->setIO( myIO );
1000 else if ( !myName.empty() ) {
1001 // workaround to allow selection of temporary objects
1002 static int tempId = 0;
1003 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1004 actor->setIO( anIO );
1007 // presentation study entry (empty for temporary objects like preview)
1008 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1009 // flag: temporary object
1010 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1011 // currently active view window's ID (-1 if no active view)
1012 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1014 // get presentation properties
1015 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1018 /////////////////////////////////////////////////////////////////////////
1019 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1020 // due to performance problem
1021 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1022 /////////////////////////////////////////////////////////////////////////
1023 if ( !actor->getTopo().IsSame( myShape ) )
1024 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1027 Material_Model material;
1028 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1029 std::vector<vtkProperty*> mprops;
1030 mprops.push_back( material.getMaterialVTKProperty( true ) );
1031 mprops.push_back( material.getMaterialVTKProperty( false) );
1032 actor->SetMaterial( mprops );
1034 // set iso-lines properties
1036 // - set number of iso-lines
1037 int nbIsos[2]= { 1, 1 };
1038 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1039 nbIsos[0] = isos[0].toInt();
1040 nbIsos[1] = isos[1].toInt();
1041 actor->SetNbIsos( nbIsos );
1043 // - set iso-lines width
1044 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1046 // - set iso-lines color
1047 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1048 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1053 // - same color for all sub-actors
1054 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1055 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1058 // shading color (for non-physical materials)
1059 if ( !material.isPhysical() ) {
1060 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1061 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1062 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1065 // - standalone edge color
1066 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1067 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1069 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1070 // - shared edges color ???
1071 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1073 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1074 // - free edges color ???
1075 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1078 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1079 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1082 // - color for edges in shading+edges mode
1083 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1084 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1087 if( HasTransparency() ) {
1088 actor->SetOpacity( 1.0 - GetTransparency() );
1090 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1094 actor->SetWidth( HasWidth() ?
1095 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1097 // libe width from properties
1098 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1100 // set display vectors flag
1101 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1103 // set display vertices flag
1104 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1107 int displayMode = HasDisplayMode() ?
1108 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1110 // display mode from properties
1111 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1113 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1114 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1115 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1116 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1118 if ( displayMode == 2 )
1119 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1120 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1122 actor->setDisplayMode( displayMode );
1125 actor->PickableOn();
1127 actor->PickableOff();
1129 if ( create && !isTemporary && aMgrId != -1 ) {
1130 // set properties to the study
1131 study->setObjectProperties( aMgrId, entry, propMap );
1135 //=================================================================
1137 * GEOM_Displayer::updateDimensions
1138 * Creates or renews dimension presentation for the IO.
1140 //=================================================================
1141 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1142 SALOME_OCCPrs* thePrs,
1143 const gp_Ax3& theShapeLCS )
1145 SalomeApp_Study* aStudy = getStudy();
1151 if ( theIO.IsNull() )
1156 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1158 AIS_ListOfInteractive aListOfIO;
1160 anOccPrs->GetObjects( aListOfIO );
1162 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1164 // remove outdated presentations of dimensions
1165 for ( ; aIterateIO.More(); aIterateIO.Next() )
1167 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1168 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1173 aListOfIO.Remove( aIterateIO );
1175 if ( !aIterateIO.More() )
1181 // prepare dimension styling
1182 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1184 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1185 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1186 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1187 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1188 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1189 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1190 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1192 // restore dimension presentation from saved attribute or property data
1193 AIS_ListOfInteractive aRestoredDimensions;
1195 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1197 GEOM::propertyName( GEOM::Dimensions ),
1200 GEOMGUI_DimensionProperty aRecords;
1202 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1204 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1208 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1211 // create up-to-date dimension presentations
1212 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1214 if ( !aRecords.IsVisible( aPrsIt ) )
1219 // init dimension by type
1220 Handle(AIS_Dimension) aPrs;
1221 switch( aRecords.GetType( aPrsIt ) )
1223 case GEOMGUI_DimensionProperty::DimensionType_Length :
1225 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1226 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1231 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1233 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1234 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1239 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1241 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1242 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1248 aPrs->SetOwner( theIO );
1250 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1252 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1254 aStyle->SetCommonColor( aColor );
1255 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1256 aStyle->MakeText3d( Standard_True );
1257 aStyle->MakeTextShaded( Standard_True );
1258 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1259 aStyle->TextAspect()->SetHeight( aFontHeight );
1260 aStyle->ArrowAspect()->SetLength( anArrowLength );
1261 aStyle->LineAspect()->SetWidth( aLineWidth );
1262 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1263 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1264 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1265 aPrs->SetDimensionAspect( aStyle );
1266 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1267 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1268 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1270 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1272 // show degree symbol for dimension instead of label "deg"
1273 if ( aUnitsAngle == "deg" )
1275 aPrs->SetSpecialSymbol(0xB0);
1276 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1277 aStyle->MakeUnitsDisplayed(Standard_False);
1281 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1282 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1287 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1290 aListOfIO.Append( aPrs );
1293 // update presentation
1296 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1298 anOccPrs->AddObject( aIterateIO.Value() );
1302 //=================================================================
1304 * GEOM_Displayer::Erase
1305 * Calls Erase() method for each object in the given list
1307 //=================================================================
1308 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1310 const bool updateViewer )
1312 SALOME_ListIteratorOfListIO Iter( theIOList );
1313 for ( ; Iter.More(); Iter.Next() )
1314 Erase( Iter.Value(), forced, false );
1320 //=================================================================
1322 * GEOM_Displayer::Redisplay
1323 * Calls Redisplay() method for each object in the given list
1325 //=================================================================
1326 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1327 const bool updateViewer,
1328 const bool checkActiveViewer )
1330 SALOME_ListIteratorOfListIO Iter( theIOList );
1331 for ( ; Iter.More(); Iter.Next() )
1332 Redisplay( Iter.Value(), false, checkActiveViewer );
1338 //=================================================================
1340 * GEOM_Displayer::Redisplay
1341 * Calls Redisplay() method for each object in the given list
1343 //=================================================================
1344 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1345 const bool theUpdateViewer,
1346 SALOME_View* theViewFrame )
1348 SALOME_ListIteratorOfListIO anIter( theIOList );
1349 for ( ; anIter.More(); anIter.Next() )
1351 Redisplay( anIter.Value(), false, theViewFrame );
1354 if ( theUpdateViewer )
1360 //=================================================================
1362 * GEOM_Displayer::Update
1363 * Update OCC presentaion
1364 * [ Reimplemented from SALOME_Displayer ]
1366 //=================================================================
1367 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1369 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1370 SalomeApp_Study* study = getStudy();
1372 if ( !occPrs || myShape.IsNull() || !study )
1375 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1378 // specific processing for local coordinate system presentation
1381 TopoDS_Face aFace = TopoDS::Face( myShape );
1382 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1383 if ( !aPlane.IsNull() )
1385 gp_Ax3 aPos = aPlane->Pln().Position();
1386 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1388 Handle(GEOM_AISTrihedron) aTrh;
1390 if ( occPrs->IsNull() )
1392 // new presentation is being created
1393 aTrh = new GEOM_AISTrihedron( aPlc );
1394 occPrs->AddObject( aTrh );
1398 // presentation is being updated
1399 AIS_ListOfInteractive aList;
1400 occPrs->GetObjects( aList );
1401 AIS_ListIteratorOfListOfInteractive anIter( aList );
1402 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1403 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1407 if ( !aTrh.IsNull() ) {
1408 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1410 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1411 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1413 aTrh->SetWidth( GetWidth() );
1415 if ( !myIO.IsNull() )
1417 aTrh->setIO( myIO );
1418 aTrh->SetOwner( myIO );
1420 aTrh->SetComponent( aPlc );
1421 aTrh->SetToUpdate();
1423 occPrs->SetToActivate( ToActivate() );
1429 // processing for usual geometry presentation
1432 // if presentation is empty we try to create new one
1433 if ( occPrs->IsNull() )
1435 // create presentation (specific for vectors)
1436 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1437 : new GEOM_AISShape ( myShape, "" );
1439 if( myType == GEOM_FIELD_STEP )
1440 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1441 // update shape properties
1442 updateShapeProperties( AISShape, true );
1444 // add shape to the presentation
1445 occPrs->AddObject( AISShape );
1447 // In accordance with ToActivate() value object will be activated/deactivated
1448 // when it will be displayed
1449 occPrs->SetToActivate( ToActivate() );
1451 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1452 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1454 // create additional wireframe shape
1455 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1456 aWirePrs->SetWidth(AISShape->Width());
1457 if ( !myIO.IsNull() ) {
1458 aWirePrs->setIO( myIO );
1459 aWirePrs->SetOwner( myIO );
1462 // add shape to the presentation
1463 occPrs->AddObject( aWirePrs );
1466 // if presentation is found -> set again shape for it
1469 AIS_ListOfInteractive IOList;
1470 occPrs->GetObjects( IOList );
1471 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1472 for ( ; Iter.More(); Iter.Next() )
1474 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1475 if ( AISShape.IsNull() )
1478 // re-set shape (it might be changed)
1479 if ( AISShape->Shape() != myShape )
1480 AISShape->Set( myShape );
1482 // update shape properties
1483 updateShapeProperties( AISShape, false );
1486 AISShape->UpdateSelection();
1487 AISShape->SetToUpdate();
1491 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1495 //=================================================================
1497 * GEOM_Displayer::Update
1498 * Update VTK presentaion
1499 * [ Reimplemented from SALOME_Displayer ]
1501 //=================================================================
1502 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1504 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1505 SalomeApp_Study* study = getStudy();
1507 if ( !vtkPrs || myShape.IsNull() || !study )
1510 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1513 // specific processing for local coordinate system presentation
1516 TopoDS_Face aFace = TopoDS::Face( myShape );
1517 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1518 if ( !aPlane.IsNull() ) {
1519 gp_Ax3 aPos = aPlane->Pln().Position();
1520 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1522 GEOM_VTKTrihedron* aTrh = 0;
1524 if ( vtkPrs->IsNull() ) {
1525 // new presentation is being created
1526 aTrh = GEOM_VTKTrihedron::New();
1527 vtkPrs->AddObject( aTrh );
1530 // presentation is being updated
1531 vtkActorCollection* actors = vtkPrs->GetObjects();
1533 actors->InitTraversal();
1534 vtkActor* a = actors->GetNextActor();
1535 while ( a && !aTrh ) {
1536 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1537 a = actors->GetNextActor();
1543 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1545 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1546 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1548 #ifdef VTK_TRIHEDRON_WIDTH
1550 // VSR: currently isn't supported
1552 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1554 aTrh->SetWidth( GetWidth() );
1557 if ( !myIO.IsNull() )
1558 aTrh->setIO( myIO );
1560 aTrh->SetPlacement( aPlc );
1567 // processing for usual geometry presentation
1570 // if presentation is empty we try to create new one
1571 if ( vtkPrs->IsNull() )
1574 GEOM_Actor* actor = GEOM_Actor::New();
1575 // update actor properties
1576 updateActorProperties( actor, true );
1577 // add actor to the presentation
1578 vtkPrs->AddObject( actor );
1581 // presentation is being updated
1582 vtkActorCollection* actors = vtkPrs->GetObjects();
1584 actors->InitTraversal();
1585 vtkActor* a = actors->GetNextActor();
1587 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1589 // update actor properties
1590 updateActorProperties( actor, false );
1591 a = actors->GetNextActor();
1599 //=================================================================
1601 * GEOM_Displayer::BuildPrs
1602 * Build presentation accordint to the current viewer type
1604 //=================================================================
1605 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1607 if ( theObj->_is_nil() )
1610 myViewFrame = GetActiveView();
1611 if ( myViewFrame == 0 )
1614 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1619 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1620 myType = theObj->GetType();
1622 // Update presentation
1628 //=================================================================
1630 * GEOM_Displayer::BuildPrs
1631 * Build presentation accordint to the current viewer type
1633 //=================================================================
1634 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1636 myViewFrame = GetActiveView();
1637 if ( theShape.IsNull() || myViewFrame == 0 )
1640 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1645 setShape( theShape );
1653 //=================================================================
1655 * GEOM_Displayer::buildPresentation
1656 * Builds/finds object's presentation for the current viewer
1657 * Calls corresponding Update() method by means of double dispatch
1660 //=================================================================
1661 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1662 SALOME_View* theViewFrame )
1664 SALOME_Prs* prs = 0;
1667 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1671 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1674 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1675 theIO->setEntry( entry.toLatin1().constData() );
1676 if ( !theIO.IsNull() )
1678 // set interactive object
1680 // Find SOBject (because shape should be published previously)
1681 SUIT_Session* session = SUIT_Session::session();
1682 SUIT_Application* app = session->activeApplication();
1685 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1688 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1691 // get CORBA reference to data object
1692 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1693 if ( !CORBA::is_nil( object ) )
1695 // downcast to GEOM base object
1696 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1697 if ( !GeomBaseObject->_is_nil() )
1699 myType = GeomBaseObject->GetType();
1701 // downcast to GEOM object
1702 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1703 if ( myType == GEOM_FIELD_STEP )
1705 // get the GEOM object from the field's shape
1706 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1707 if ( !GeomFieldStep->_is_nil() )
1709 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1710 if ( !GeomField->_is_nil() )
1711 GeomObject = GeomField->GetShape();
1714 // read the field step information
1715 readFieldStepInfo( GeomFieldStep );
1718 if ( !GeomObject->_is_nil() )
1720 // finally set shape
1721 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1729 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1735 //=================================================================
1737 * GEOM_Displayer::buildSubshapePresentation
1738 * Builds/finds object's presentation for the current viewer
1739 * Calls corresponding Update() method by means of double dispatch
1740 * For not published objects (for Mantis issue 0020435)
1742 //=================================================================
1743 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1744 const QString& entry,
1745 SALOME_View* theViewFrame)
1747 SALOME_Prs* prs = 0;
1750 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1754 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1757 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1758 theIO->setEntry(entry.toLatin1().constData());
1759 if (!theIO.IsNull())
1761 // set interactive object
1763 // finally set shape
1765 myType = GEOM_SUBSHAPE;
1767 UpdatePrs(prs); // Update presentation by using of the double dispatch
1773 //=================================================================
1775 * GEOM_Displayer::internalReset
1776 * Resets internal data
1779 //=================================================================
1780 void GEOM_Displayer::internalReset()
1785 myFieldDataType = GEOM::FDT_Double;
1786 myFieldDimension = 0;
1787 myFieldStepData.clear();
1788 myFieldStepName.Clear();
1789 myFieldStepRangeMin = 0;
1790 myFieldStepRangeMax = 0;
1793 //=================================================================
1795 * GEOM_Displayer::LocalSelection
1796 * Activate selection of CAD shapes with activisation of selection
1797 * of their sub-shapes (with opened local context for OCC viewer)
1799 //=================================================================
1800 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1802 SUIT_Session* session = SUIT_Session::session();
1803 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1807 LightApp_SelectionMgr* sm = app->selectionMgr();
1809 // remove all filters from selection
1812 SALOME_View* vf = GetActiveView();
1814 if (!theIO.IsNull() && !vf->isVisible(theIO))
1816 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1817 vf->LocalSelection( prs, theMode );
1818 delete prs; // delete presentation because displayer is its owner
1822 //=================================================================
1824 * GEOM_Displayer::globalSelection
1825 * Activate selection of CAD shapes without activisation of selection
1826 * of their sub-shapes (without opened local context for OCC viewer)
1828 //=================================================================
1829 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1831 TColStd_MapOfInteger aModes;
1832 aModes.Add( theMode );
1833 GlobalSelection( aModes, update );
1836 //=================================================================
1838 * GEOM_Displayer::globalSelection
1839 * Activate selection of CAD shapes without activisation of selection
1840 * of their sub-shapes (without opened local context for OCC viewer)
1842 //=================================================================
1843 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1844 const bool update, const QList<int>* theSubShapes )
1846 SUIT_Session* session = SUIT_Session::session();
1847 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1851 SALOME_View* vf = GetActiveView();
1855 // Close local context
1856 vf->GlobalSelection( update );
1858 // Set selection filters in accordance with current mode
1859 LightApp_SelectionMgr* sm = app->selectionMgr();
1863 // Remove from selection temporary objects if necessary
1864 if ( !theModes.Contains( GEOM_PREVIEW ) )
1865 clearTemporary( sm );
1867 //@ aSel->ClearIndex();
1871 // Remove filters from AIS_InteractiveContext
1872 Handle(AIS_InteractiveContext) ic;
1873 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1876 ic = viewer->getAISContext();
1878 ic->RemoveFilters();
1881 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1884 SUIT_SelectionFilter* aFilter;
1885 if ( theModes.Extent() == 1 )
1887 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1889 if ( aMode == GEOM_COMPOUNDFILTER )
1890 aFilter = getComplexFilter( theSubShapes );
1892 aFilter = getFilter( aMode );
1894 else if ( theModes.Extent() > 1 )
1896 TColStd_MapOfInteger aTopAbsModes;
1897 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1898 QList<SUIT_SelectionFilter*> aListOfFilters;
1899 for ( ; anIter.More(); anIter.Next() )
1901 SUIT_SelectionFilter* aFilter;
1902 int aMode = anIter.Key();
1903 if ( aMode == GEOM_COMPOUNDFILTER )
1904 aFilter = getComplexFilter( theSubShapes );
1906 aFilter = getFilter( aMode );
1909 aListOfFilters.append( aFilter );
1912 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1919 sm->installFilter( aFilter );
1922 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1923 ic->AddFilter( anOCCFilter );
1928 //=================================================================
1930 * GEOM_Displayer::LocalSelection
1931 * Activate selection of CAD shapes with activisation of selection
1932 * of their sub-shapes (with opened local context for OCC viewer)
1934 //=================================================================
1935 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1937 SALOME_ListIteratorOfListIO Iter( theIOList );
1938 for ( ; Iter.More(); Iter.Next() )
1939 LocalSelection( Iter.Value(), theMode );
1942 //=================================================================
1944 * GEOM_Displayer::BeforeDisplay
1945 * Called before displaying of pars. Close local context
1946 * [ Reimplemented from SALOME_Displayer ]
1948 //=================================================================
1949 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1951 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1954 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1957 if ( ic->HasOpenedContext() )
1958 ic->CloseAllContexts();
1963 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1965 UpdateColorScale(false,false);
1968 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1970 LightApp_Displayer::BeforeErase( v, p );
1971 releaseTextures( p );
1974 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1976 LightApp_Displayer::AfterErase( v, p );
1977 UpdateColorScale(false,false);
1980 //=================================================================
1982 * GEOM_Displayer::SetColor
1983 * Set color for shape displaying. If it is equal -1 then default color is used.
1984 * Available values are from Quantity_NameOfColor enumeration
1986 //=================================================================
1987 void GEOM_Displayer::SetColor( const int color )
1994 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1998 int GEOM_Displayer::GetColor() const
2003 bool GEOM_Displayer::HasColor() const
2005 return myColor != -1;
2008 void GEOM_Displayer::UnsetColor()
2012 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2013 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2014 myShadingColor = SalomeApp_Tools::color( col );
2017 //=================================================================
2019 * GEOM_Displayer::SetTransparency
2020 * Set transparency for shape displaying.
2022 //=================================================================
2023 double GEOM_Displayer::SetTransparency( const double transparency )
2025 double aPrevTransparency = myTransparency;
2026 if ( transparency < 0 ) {
2027 UnsetTransparency();
2030 myTransparency = transparency;
2031 myHasTransparency = true;
2033 return aPrevTransparency;
2036 //=================================================================
2038 * GEOM_Displayer::GetTransparency
2039 * Get transparency for shape displaying.
2041 //=================================================================
2042 double GEOM_Displayer::GetTransparency() const
2044 return myTransparency;
2047 //=================================================================
2049 * GEOM_Displayer::HasTransparency
2050 * Check if transparency for shape displaying is set.
2052 //=================================================================
2053 bool GEOM_Displayer::HasTransparency() const
2055 return myHasTransparency;
2058 //=================================================================
2060 * GEOM_Displayer::UnsetTransparency
2061 * Unset transparency for shape displaying.
2063 //=================================================================
2064 double GEOM_Displayer::UnsetTransparency()
2066 double aPrevTransparency = myTransparency;
2067 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2068 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
2069 myHasTransparency = false;
2070 return aPrevTransparency;
2074 //=================================================================
2076 * GEOM_Displayer::SetTexture
2077 * Set color for shape displaying. If it is equal -1 then default color is used.
2078 * Available values are from Quantity_NameOfColor enumeration
2080 //=================================================================
2081 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2083 if(texureFileName!="")
2085 myTexture = texureFileName;
2089 bool GEOM_Displayer::HasTexture() const
2091 return myTexture != "";
2094 std::string GEOM_Displayer::GetTexture() const
2099 //=================================================================
2101 * GEOM_Displayer::SetWidth
2102 * Set width of shape displaying. If it is equal -1 then default width is used.
2104 //=================================================================
2105 void GEOM_Displayer::SetWidth( const double width )
2110 double GEOM_Displayer::GetWidth() const
2115 bool GEOM_Displayer::HasWidth() const
2117 return myWidth != -1;
2120 void GEOM_Displayer::UnsetWidth()
2126 int GEOM_Displayer::GetIsosWidth() const
2131 void GEOM_Displayer::SetIsosWidth(const int width)
2133 myIsosWidth = width;
2136 bool GEOM_Displayer::HasIsosWidth() const
2138 return myIsosWidth != -1;
2142 //=================================================================
2144 * GEOM_Displayer::SetToActivate
2145 * This method is used for activisation/deactivisation of objects to be displayed
2147 //=================================================================
2148 void GEOM_Displayer::SetToActivate( const bool toActivate )
2150 myToActivate = toActivate;
2152 bool GEOM_Displayer::ToActivate() const
2154 return myToActivate;
2157 //=================================================================
2159 * GEOM_Displayer::clearTemporary
2160 * Removes from selection temporary objects
2162 //=================================================================
2163 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2165 SALOME_ListIO selected, toSelect;
2166 theSelMgr->selectedObjects( selected );
2168 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2169 Handle(SALOME_InteractiveObject) io = it.Value();
2170 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2171 toSelect.Append( it.Value() );
2174 theSelMgr->setSelectedObjects( toSelect, true );
2177 void GEOM_Displayer::SetName( const char* theName )
2182 void GEOM_Displayer::UnsetName()
2187 SalomeApp_Study* GEOM_Displayer::getStudy() const
2189 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2192 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2197 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2202 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2203 const int theFieldDimension,
2204 const QList<QVariant>& theFieldStepData,
2205 const TCollection_AsciiString& theFieldStepName,
2206 const double theFieldStepRangeMin,
2207 const double theFieldStepRangeMax )
2209 myFieldDataType = theFieldDataType;
2210 myFieldDimension = theFieldDimension;
2211 myFieldStepData = theFieldStepData;
2212 myFieldStepName = theFieldStepName;
2213 myFieldStepRangeMin = theFieldStepRangeMin;
2214 myFieldStepRangeMax = theFieldStepRangeMax;
2217 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2219 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2220 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2221 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2222 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2223 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2224 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2227 int GEOM_Displayer::SetDisplayMode( const int theMode )
2229 int aPrevMode = myDisplayMode;
2230 if ( theMode != -1 ) {
2231 myDisplayMode = theMode;
2232 myHasDisplayMode = true;
2240 int GEOM_Displayer::GetDisplayMode() const
2242 return myDisplayMode;
2245 int GEOM_Displayer::UnsetDisplayMode()
2247 int aPrevMode = myDisplayMode;
2248 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2249 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2250 myHasDisplayMode = false;
2254 bool GEOM_Displayer::HasDisplayMode() const
2256 return myHasDisplayMode;
2259 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2261 static QList<QColor> colors;
2263 if ( colors.isEmpty() ) {
2265 for (int s = 0; s < 2 ; s++)
2267 for (int v = 100; v >= 40; v = v - 20)
2269 for (int h = 0; h < 359 ; h = h + 60)
2271 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2277 static int currentColor = randomize( colors.size() );
2279 SALOMEDS::Color color;
2280 color.R = (double)colors[currentColor].red() / 255.0;
2281 color.G = (double)colors[currentColor].green() / 255.0;
2282 color.B = (double)colors[currentColor].blue() / 255.0;
2284 currentColor = (currentColor+1) % colors.count();
2289 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2292 int aTolerance = 64;
2293 int anIterations = 0;
2299 if( anIterations % aPeriod == 0 )
2302 if( aTolerance < 1 )
2305 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2307 aHue = (int)( 360.0 * rand() / RAND_MAX );
2308 //std::cout << "Hue = " << aHue << std::endl;
2310 //std::cout << "Auto colors : ";
2312 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2313 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2314 for( ; it != itEnd; ++it )
2316 SALOMEDS::Color anAutoColor = *it;
2317 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2320 aQColor.getHsv( &h, &s, &v );
2321 //std::cout << h << " ";
2322 if( abs( h - aHue ) < aTolerance )
2325 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2329 //std::cout << std::endl;
2335 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2337 aColor.setHsv( aHue, 255, 255 );
2339 SALOMEDS::Color aSColor;
2340 aSColor.R = (double)aColor.red() / 255.0;
2341 aSColor.G = (double)aColor.green() / 255.0;
2342 aSColor.B = (double)aColor.blue() / 255.0;
2347 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2348 const QString& entry,
2351 // get default properties for the explicitly specified default view type
2352 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2354 if ( study && view ) {
2355 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2356 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2357 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2359 if ( viewModel && viewId != -1 ) {
2360 // get properties from the study
2361 PropMap storedMap = study->getObjectProperties( viewId, entry );
2362 // overwrite default properties from stored ones (that are specified)
2363 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2364 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2365 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2366 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2368 // ... specific processing for color
2369 // ... current implementation is to use same stored color for all aspects
2370 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2371 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2372 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2373 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2374 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2375 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2376 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2379 if ( !entry.isEmpty() ) {
2380 // get CORBA reference to geom object
2381 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2383 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2384 if ( !CORBA::is_nil( object ) ) {
2385 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2386 if ( !CORBA::is_nil( geomObject ) ) { // to check
2387 // check that geom object has color properly set
2388 bool hasColor = false;
2389 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2390 // set color from geometry object (only once, if it is not yet set in GUI)
2391 // current implementation is to use same color for all aspects
2392 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2393 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2394 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2395 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2396 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2397 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2398 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2399 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2401 // check that object has point marker properly set
2402 GEOM::marker_type mType = geomObject->GetMarkerType();
2403 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2404 int mTextureId = geomObject->GetMarkerTexture();
2405 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2406 ( mType == GEOM::MT_USER && mTextureId > 0 );
2407 // set point marker from geometry object (only once, if it is not yet set in GUI)
2408 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2409 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2411 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2412 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2414 else if ( mType == GEOM::MT_USER ) {
2416 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2428 PropMap GEOM_Displayer::getDefaultPropertyMap()
2432 // get resource manager
2433 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2435 // fill in the properties map with default values
2437 // - visibility (false by default)
2438 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2440 // - nb isos (take default value from preferences)
2441 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2442 QString( "%1%2%3" ).
2443 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2444 arg( GEOM::subSectionSeparator() ).
2445 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2447 // - transparency (opacity = 1-transparency)
2448 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2449 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2451 // - display mode (take default value from preferences)
2452 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2453 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2455 // - show edges direction flag (false by default)
2456 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2458 // - show vertices flag (false by default)
2459 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2461 // - shading color (take default value from preferences)
2462 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2463 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2465 // - wireframe color (take default value from preferences)
2466 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2467 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2469 // - standalone edges color (take default value from preferences)
2470 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2471 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2473 // - free boundaries color (take default value from preferences)
2474 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2475 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2477 // - points color (take default value from preferences)
2478 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2479 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2481 // - isos color (take default value from preferences)
2482 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2483 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2485 // - outlines color (take default value from preferences)
2486 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2487 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2489 // - deflection coefficient (take default value from preferences)
2490 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2491 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2493 // - material (take default value from preferences)
2494 Material_Model material;
2495 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2496 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2498 // - edge width (take default value from preferences)
2499 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2500 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2502 // - isos width (take default value from preferences)
2503 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2504 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2506 // - point marker (take default value from preferences)
2507 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2508 QString( "%1%2%3" ).
2509 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2510 arg( GEOM::subSectionSeparator() ).
2511 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2513 // - top-level flag (false by default)
2514 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2519 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2520 SALOMEDS::Color aSColor;
2523 SUIT_Session* session = SUIT_Session::session();
2524 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2526 if ( app && !theGeomObject->_is_nil()) {
2527 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2530 _PTR(Study) aStudy = study->studyDS();
2531 aSColor = theGeomObject->GetColor();
2532 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2534 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2535 bool general_autocolor = true;
2536 #else // auto-color for groups only
2537 bool general_autocolor = false;
2538 #endif // GENERAL_AUTOCOLOR
2539 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2540 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2541 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2542 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2543 aSColor = getPredefinedUniqueColor();
2545 #else // old algorithm for auto-colors
2546 QList<SALOMEDS::Color> aReservedColors;
2547 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2548 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2549 if ( aMainSObject ) {
2550 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2551 for ( ; it->More(); it->Next() ) {
2552 _PTR(SObject) aChildSObject( it->Value() );
2553 GEOM::GEOM_Object_var aChildObject =
2554 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2555 if ( CORBA::is_nil( aChildObject ) )
2558 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2559 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2560 aReservedColors.append( aReservedColor );
2563 aSColor = getUniqueColor( aReservedColors );
2565 #endif // SIMPLE_AUTOCOLOR
2575 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2576 const bool eraseOnlyChildren) {
2577 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2581 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2585 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2590 // Erase from all views
2591 QList<SALOME_View*> views;
2593 ViewManagerList vmans = app->viewManagers();
2594 SUIT_ViewManager* vman;
2595 foreach ( vman, vmans ) {
2596 SUIT_ViewModel* vmod = vman->getViewModel();
2597 view = dynamic_cast<SALOME_View*> ( vmod );
2599 views.append( view );
2602 if( views.count() == 0 )
2605 //Erase childrens w/o update views
2606 DataObjectList listObj = parent->children( true );
2607 SUIT_DataObject* obj;
2608 foreach( obj, listObj ) {
2609 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2611 foreach ( view, views ) {
2612 Handle(SALOME_InteractiveObject) anIO =
2613 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2614 Erase(anIO, false, false, view);
2618 //Erase parent with view update or repaint views
2619 foreach ( view, views ) {
2620 if(!eraseOnlyChildren)
2621 Erase(theIO, false, true, view);
2627 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2629 if( theGeomFieldStep->_is_nil() )
2632 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2633 if( aGeomField->_is_nil() )
2636 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2637 if( aGeomFieldShape->_is_nil() )
2640 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2641 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2642 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2644 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2646 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2648 int aFieldDimension = aGeomField->GetDimension();
2650 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2651 int aFieldNbComponents = aFieldComponents->length();
2653 QList<QVariant> aFieldStepData;
2654 if( aFieldDataType == GEOM::FDT_Bool )
2656 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2657 if ( !aGeomBoolFieldStep->_is_nil() )
2659 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2660 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2661 aFieldStepData << (bool)aValues[i];
2664 else if( aFieldDataType == GEOM::FDT_Int )
2666 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2667 if ( !aGeomIntFieldStep->_is_nil() )
2669 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2670 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2671 aFieldStepData << (qlonglong)aValues[i];
2674 else if( aFieldDataType == GEOM::FDT_Double )
2676 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2677 if ( !aGeomDoubleFieldStep->_is_nil() )
2679 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2680 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2681 aFieldStepData << (double)aValues[i];
2684 else if( aFieldDataType == GEOM::FDT_String )
2686 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2687 if ( !aGeomStringFieldStep->_is_nil() )
2689 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2690 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2691 aFieldStepData << QString( aValues[i] );
2695 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2696 aFieldStepData = groupFieldData( aFieldStepData,
2698 aFieldDataType == GEOM::FDT_String,
2700 aFieldStepRangeMax );
2702 setFieldStepInfo( aFieldDataType,
2707 aFieldStepRangeMax );
2710 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2711 const int theFieldNbComponents,
2712 const bool theIsString,
2713 double& theFieldStepRangeMin,
2714 double& theFieldStepRangeMax )
2716 QList<QVariant> aResultList;
2717 theFieldStepRangeMin = 0;
2718 theFieldStepRangeMax = 0;
2720 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2723 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2725 QList<QVariant> aGroupedList;
2727 bool anIsBoolean = false;
2728 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2731 QStringList aStringList;
2733 int aBaseIndex = aSubShape * theFieldNbComponents;
2734 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2736 int anIndex = aComponent + aBaseIndex;
2738 const QVariant& aVariant = theFieldStepData[ anIndex ];
2741 if( aVariant.type() == QVariant::String )
2742 aStringList << aVariant.toString();
2747 if( aVariant.type() == QVariant::Bool )
2749 aValue = aVariant.toBool() ? 1.0 : 0.0;
2755 if( aVariant.type() == QVariant::LongLong )
2756 aValue = double( aVariant.toLongLong() );
2757 else if( aVariant.type() == QVariant::Double )
2758 aValue = aVariant.toDouble();
2759 aNorm += aValue * aValue;
2765 aGroupedList << aStringList.join( "\n" );
2769 aNorm /= theFieldNbComponents;
2771 aNorm = pow( aNorm, 0.5 );
2773 if( aGroupedList.isEmpty() )
2774 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2777 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2778 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2781 aGroupedList << aNorm;
2787 theFieldStepRangeMin = 0.0;
2788 theFieldStepRangeMax = 1.0;
2791 SUIT_Session* session = SUIT_Session::session();
2792 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2793 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2795 QListIterator<QVariant> anIter( aGroupedList );
2796 while( anIter.hasNext() )
2798 const QVariant& aVariant = anIter.next();
2800 aResultList << aVariant;
2804 Quantity_Color aColor;
2805 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2806 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2807 aResultList << aQColor;
2813 // Note: the method is copied from Aspect_ColorScale class
2814 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2815 const Standard_Integer aMin,
2816 const Standard_Integer aMax )
2818 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2820 Standard_Integer aHue = maxLimit;
2822 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2824 aHue = Min( Max( minLimit, aHue ), maxLimit );
2829 // Note: the method is copied from Aspect_ColorScale class
2830 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2831 const Standard_Real aMin,
2832 const Standard_Real aMax,
2833 const Standard_Integer ColorsCount,
2834 Quantity_Color& aColor )
2836 if( aValue<aMin || aValue>aMax || aMax<aMin )
2837 return Standard_False;
2841 Standard_Real IntervNumber = 0;
2844 else if( aValue>aMax )
2845 IntervNumber = ColorsCount-1;
2846 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2847 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2849 Standard_Integer Interv = Standard_Integer( IntervNumber );
2851 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2853 return Standard_True;
2857 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2859 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2863 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2867 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2868 if( aViewer.IsNull() )
2871 aViewer->InitActiveViews();
2872 if( !aViewer->MoreActiveViews() )
2875 Handle(V3d_View) aView = aViewer->ActiveView();
2876 if( aView.IsNull() )
2879 Standard_Boolean anIsDisplayColorScale = Standard_False;
2880 TCollection_AsciiString aColorScaleTitle;
2881 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2882 Standard_Boolean anIsBoolean = Standard_False;
2884 SALOME_ListIO aSelectedObjects;
2885 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2886 if( aSelectedObjects.Extent() == 1 )
2888 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2889 if( !anIO.IsNull() )
2891 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2894 AIS_ListOfInteractive aList;
2895 aPrs->GetObjects( aList );
2896 AIS_ListIteratorOfListOfInteractive anIter( aList );
2897 for( ; anIter.More(); anIter.Next() )
2899 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2900 if( !aShape.IsNull() )
2902 GEOM::field_data_type aFieldDataType;
2903 int aFieldDimension;
2904 QList<QVariant> aFieldStepData;
2905 TCollection_AsciiString aFieldStepName;
2906 double aFieldStepRangeMin, aFieldStepRangeMax;
2907 aShape->getFieldStepInfo( aFieldDataType,
2912 aFieldStepRangeMax );
2913 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2915 anIsDisplayColorScale = Standard_True;
2916 aColorScaleTitle = aFieldStepName;
2917 aColorScaleMin = aFieldStepRangeMin;
2918 aColorScaleMax = aFieldStepRangeMax;
2919 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2927 if( anIsDisplayColorScale )
2929 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2930 if( !aColorScale.IsNull() )
2932 SUIT_Session* session = SUIT_Session::session();
2933 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2935 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2936 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2937 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2938 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2939 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2940 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2942 aColorScale->SetXPosition( anXPos );
2943 aColorScale->SetYPosition( anYPos );
2944 aColorScale->SetWidth( aWidth );
2945 aColorScale->SetHeight( aHeight );
2947 aColorScale->SetTextHeight( aTextHeight );
2948 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2950 aColorScale->SetTitle( aColorScaleTitle );
2951 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2953 if( !aView->ColorScaleIsDisplayed() )
2954 aView->ColorScaleDisplay();
2958 if( aView->ColorScaleIsDisplayed() )
2959 aView->ColorScaleErase();
2962 if( theIsRedisplayFieldSteps )
2964 _PTR(Study) aStudyDS = aStudy->studyDS();
2965 QList<SUIT_ViewManager*> vmList;
2966 myApp->viewManagers( vmList );
2967 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2969 if( SUIT_ViewManager* aViewManager = *vmIt )
2971 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
2972 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2974 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2977 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2978 if( !CORBA::is_nil( anObject ) )
2980 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2981 if( !aFieldStep->_is_nil() )
2983 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2984 Handle(SALOME_InteractiveObject) aStepIO =
2985 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2986 Redisplay( aStepIO, false, false );