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;
136 // If the next macro is defined, the deflection coefficient for VTK presentation
137 // is limited by VTK_MIN_DEFLECTION
138 //#define LIMIT_DEFLECTION_FOR_VTK
140 // Pixmap caching support
143 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
144 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
145 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
147 static inline PixmapUsageMap& getPixmapUsageMap()
149 static PixmapUsageMap aMap;
153 static inline PixmapCacheMap& getPixmapCacheMap()
155 static PixmapCacheMap aMap;
159 //===========================================================================
160 // Function : getDefaultTexture
161 // Purpose : Get default texture
162 //===========================================================================
163 static inline Handle(Image_PixMap) getDefaultTexture()
165 static Handle(Image_PixMap) aPixmap;
166 if ( aPixmap.IsNull() ) {
167 QPixmap px(":images/default_texture.png");
169 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
174 //===========================================================================
175 // Function : cacheTextureFor
176 // Purpose : Load and cache image for the specified presentation.
177 //===========================================================================
178 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
179 const Handle(GEOM_AISShape)& theShape )
181 if ( thePath.isEmpty() )
184 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
185 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
187 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
188 if ( !aPixmap.IsNull() ) {
189 // point that the texture is used by the presentation
190 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
191 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
193 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
198 // convert texture to compatible image format
199 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
200 if ( anImage.isNull() )
203 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
205 aPixmapCacheMap.insert( thePath, aPixmap );
207 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
208 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
210 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
215 //===========================================================================
216 // Function : releaseTextures
217 // Purpose : Releases cached textures found for the specified presentation.
218 //===========================================================================
219 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
221 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
223 AIS_ListOfInteractive aListOfIO;
225 anOccPrs->GetObjects( aListOfIO );
227 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
229 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
230 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
232 for ( ; aIterateIO.More(); aIterateIO.Next() )
234 Handle(GEOM_AISShape) aAISShape =
235 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
237 if ( aAISShape.IsNull() )
240 #ifdef USE_TEXTURED_SHAPE
241 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
242 if ( aPixmap.IsNull() )
245 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
248 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
250 aUsersShapes.Remove( aAISShape );
252 if ( aUsersShapes.IsEmpty() ) {
253 aPixmapUsersMap.UnBind( aPixmap );
254 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
260 uint randomize( uint size )
262 static bool initialized = false;
263 if ( !initialized ) {
264 qsrand( QDateTime::currentDateTime().toTime_t() );
268 v = uint( (double)( v ) / RAND_MAX * size );
269 v = qMax( uint(0), qMin ( v, size-1 ) );
274 //================================================================
275 // Function : getActiveStudy
276 // Purpose : Get active study, returns 0 if no open study frame
277 //================================================================
278 static inline SalomeApp_Study* getActiveStudy()
280 SUIT_Session* session = SUIT_Session::session();
281 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
283 return ( SalomeApp_Study* )app->activeStudy();
287 static inline int getViewManagerId( SALOME_View* theViewFrame) {
288 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
289 SUIT_ViewManager* aViewMgr = 0;
291 aViewMgr = aModel->getViewManager();
292 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
295 //================================================================
296 // Function : getTopAbsMode
297 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
298 // one from GEOMImpl_Types.h
299 //================================================================
300 static inline int getTopAbsMode( const int implType )
304 case GEOM_COMPOUND : return TopAbs_COMPOUND;
305 case GEOM_SOLID : return TopAbs_SOLID;
306 case GEOM_SHELL : return TopAbs_SHELL;
307 case GEOM_FACE : return TopAbs_FACE;
308 case GEOM_WIRE : return TopAbs_WIRE;
309 case GEOM_EDGE : return TopAbs_EDGE;
310 case GEOM_POINT : return TopAbs_VERTEX;
315 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
317 if ( shape.IsNull() )
320 int ret = shape.ShapeType();
322 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
323 TopoDS_Iterator it(shape, Standard_True, Standard_False);
324 for (; it.More(); it.Next()) {
325 TopoDS_Shape sub_shape = it.Value();
326 if ( sub_shape.IsNull() ) continue;
327 int stype = getMinMaxShapeType( sub_shape, ismin );
328 if ( stype == TopAbs_SHAPE ) continue;
329 if ( ismin && stype > ret )
331 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
339 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
341 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
344 //================================================================
345 // Function : getFilter
346 // Purpose : Get filter corresponding to the type of object
347 // from GEOMImpl_Types.h
348 //================================================================
349 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
351 SUIT_SelectionFilter* aFilter;
353 int aTopAbsMode = getTopAbsMode( theMode );
354 if ( aTopAbsMode != -1 )
355 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
359 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
360 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
362 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
363 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
364 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
365 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
366 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
367 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
369 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
371 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
372 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
374 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
380 //================================================================
381 // Function : getComplexFilter
382 // Purpose : Get compound filter corresponding to the type of
383 // object from GEOMImpl_Types.h
384 //================================================================
385 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
387 GEOM_CompoundFilter* aFilter;
389 if(aSubShapes != NULL ) {
390 aFilter = new GEOM_CompoundFilter(getStudy());
391 QList<int> aTopAbsTypes;
392 QList<int>::const_iterator it;
393 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
394 int topAbsMode = getTopAbsMode(*it);
395 if(topAbsMode != -1 )
396 aTopAbsTypes.append(topAbsMode);
398 aFilter->addSubTypes(aTopAbsTypes);
404 //================================================================
405 // Function : getEntry
407 //================================================================
408 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
410 SUIT_Session* session = SUIT_Session::session();
411 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
414 CORBA::String_var IOR = app->orb()->object_to_string( object );
415 if ( strcmp(IOR.in(), "") != 0 )
417 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
418 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
426 //================================================================
427 // Function : getName
429 //================================================================
430 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
432 SUIT_Session* session = SUIT_Session::session();
433 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
436 CORBA::String_var IOR = app->orb()->object_to_string( object );
437 if ( strcmp(IOR.in(), "") != 0 )
439 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
440 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
442 _PTR(GenericAttribute) anAttr;
444 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
446 _PTR(AttributeName) aNameAttr( anAttr );
447 return aNameAttr->Value();
455 //=================================================================
457 * GEOM_Displayer::GEOM_Displayer
460 //=================================================================
461 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
464 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
469 SUIT_Session* session = SUIT_Session::session();
470 SUIT_ResourceMgr* resMgr = session->resourceMgr();
472 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
473 myShadingColor = SalomeApp_Tools::color( col );
475 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
476 myHasDisplayMode = false;
478 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
480 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
481 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
482 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
484 // Next properties provide a way to customize displaying of presentations;
485 // for instance, this is useful for preview
495 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
498 // Activate parallel vizualisation only for testing purpose
499 // and if the corresponding env variable is set to 1
500 char* parallel_visu = getenv("PARALLEL_VISU");
501 if (parallel_visu && atoi(parallel_visu))
503 MESSAGE("Parallel visualisation on");
504 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
509 myFieldDataType = GEOM::FDT_Double;
510 myFieldDimension = 0;
511 myFieldStepRangeMin = 0;
512 myFieldStepRangeMax = 0;
515 //=================================================================
517 * GEOM_Displayer::~GEOM_Displayer
520 //=================================================================
521 GEOM_Displayer::~GEOM_Displayer()
525 //=================================================================
527 * GEOM_Displayer::Display
528 * Display interactive object in the current viewer
530 //=================================================================
531 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
532 const bool updateViewer,
533 SALOME_View* theViewFrame )
535 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
538 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
542 vf->BeforeDisplay( this, prs );
543 vf->Display( this, prs );
544 vf->AfterDisplay( this, prs );
549 delete prs; // delete presentation because displayer is its owner
554 //=================================================================
556 * GEOM_Displayer::Display
557 * This overloaded Display() method can be useful for operations
558 * not using dialog boxes.
560 //=================================================================
561 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
563 if ( theObj->_is_nil() )
566 std::string entry = getEntry( theObj );
568 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
573 //=================================================================
575 * GEOM_Displayer::Erase
576 * Erase interactive object in the current viewer
578 //=================================================================
579 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
581 const bool updateViewer,
582 SALOME_View* theViewFrame )
584 if ( theIO.IsNull() )
587 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
590 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
592 vf->BeforeErase( this, prs );
593 vf->Erase( this, prs, forced );
594 vf->AfterErase( this, prs );
597 delete prs; // delete presentation because displayer is its owner
602 //=================================================================
604 * GEOM_Displayer::Erase
605 * Erase geometry object in the current viewer
607 //=================================================================
608 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
610 const bool updateViewer,
611 SALOME_View* theViewFrame)
613 std::string entry = getEntry( theObj );
616 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
617 forced, updateViewer, theViewFrame);
621 //=================================================================
623 * GEOM_Displayer::Redisplay
624 * Redisplay (erase and then display again) interactive object
625 * in the current viewer
627 //=================================================================
628 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
629 const bool updateViewer,
630 const bool checkActiveViewer )
632 // Remove the object permanently (<forced> == true)
633 SUIT_Session* ses = SUIT_Session::session();
634 SUIT_Application* app = ses->activeApplication();
637 SUIT_Desktop* desk = app->desktop();
638 QList<SUIT_ViewWindow*> wnds = desk->windows();
639 SUIT_ViewWindow* wnd;
640 QListIterator<SUIT_ViewWindow*> it( wnds );
641 while ( it.hasNext() && (wnd = it.next()) )
643 SUIT_ViewManager* vman = wnd->getViewManager();
646 SUIT_ViewModel* vmodel = vman->getViewModel();
649 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
652 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
654 Redisplay( theIO, updateViewer, view );
663 //=================================================================
665 * GEOM_Displayer::Redisplay
666 * Redisplay (erase and then display again) interactive object
667 * in the specified view
669 //=================================================================
670 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
671 const bool theUpdateViewer,
672 SALOME_View* theViewFrame )
674 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
680 Erase( theIO, true, false, theViewFrame );
681 Display( theIO, theUpdateViewer, theViewFrame );
684 //=================================================================
686 * GEOM_Displayer::Display
687 * Calls Display() method for each object in the given list
689 //=================================================================
690 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
692 SALOME_ListIteratorOfListIO Iter( theIOList );
693 for ( ; Iter.More(); Iter.Next() ) {
694 Display( Iter.Value(), false );
700 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
702 SalomeApp_Study* aStudy = getStudy();
704 if ( v ) vId = getViewManagerId( v );
707 QString entry = p->GetEntry();
708 if ( !entry.isEmpty() ) {
710 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
711 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
716 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
721 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
723 // VSR: this method can be improved in future:
724 // to improve performance, the default values from resource manager should be cached in the displayer
725 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
728 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
730 // VSR: this method can be improved in future:
731 // to improve performance, the default values from resource manager should be cached in the displayer
732 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
735 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
737 // check that shape is not null
738 if ( AISShape.IsNull() ) return;
740 // check that study is active
741 SalomeApp_Study* study = getStudy();
742 if ( !study ) return;
744 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
745 !TopoDS_Iterator(myShape).More() )
746 return; // NPAL15983 (Bug when displaying empty groups)
748 // set interactive object
750 Handle( SALOME_InteractiveObject ) anIO;
752 if ( !myIO.IsNull() ) {
753 AISShape->setIO( myIO );
754 AISShape->SetOwner( myIO );
757 else if ( !myName.empty() ) {
758 // workaround to allow selection of temporary objects
759 static int tempId = 0;
760 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
761 AISShape->setIO( anIO );
762 AISShape->SetOwner( anIO );
765 // flag: only vertex or compound of vertices is processed (specific handling)
766 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
767 // presentation study entry (empty for temporary objects like preview)
768 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
769 // flag: temporary object
770 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
771 // currently active view window's ID (-1 if no active view)
772 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
774 // get presentation properties
775 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
777 // Temporary staff: vertex must be infinite for correct visualization
778 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
781 Material_Model material;
782 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
784 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
785 // - set front material properties
786 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
787 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
788 // - set back material properties
789 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
790 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
791 // - switch to default (both sides) facing mode
792 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
798 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
799 // we set it to the shape not taking into account material properties
800 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
802 else if ( !material.isPhysical() ) {
803 // shading color from properties is used only for non-physical materials
804 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
808 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
809 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
810 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
811 AISShape->Attributes()->SetLineAspect( anAspect );
813 // - unfree boundaries color
814 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
815 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
816 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
817 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
819 // - free boundaries color
820 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
821 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
822 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
823 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
825 // - standalone edges color
826 anAspect = AISShape->Attributes()->WireAspect();
827 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
828 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
829 AISShape->Attributes()->SetWireAspect( anAspect );
831 // - color for edges in shading+edges mode
832 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
835 AISShape->SetDisplayMode( HasDisplayMode() ?
836 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
838 // display mode from properties
839 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
841 // - face boundaries color
842 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
843 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
844 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
845 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
846 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
848 // set display vectors flag
849 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
851 // set display vertices flag
852 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
853 AISShape->SetDisplayVertices( isVerticesMode );
856 if( HasTransparency() ) {
857 AISShape->SetTransparency( GetTransparency() );
859 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
862 // set iso properties
863 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
864 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
865 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
866 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
867 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
868 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
870 if ( HasIsosColor() ) {
871 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
872 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
875 uIsoAspect->SetColor( isosColor );
876 vIsoAspect->SetColor( isosColor );
879 if ( HasIsosWidth() ) {
880 uIsoAspect->SetWidth( GetIsosWidth() );
881 vIsoAspect->SetWidth( GetIsosWidth() );
884 uIsoAspect->SetWidth( isosWidth );
885 vIsoAspect->SetWidth( isosWidth );
889 uIsoAspect->SetNumber( GetNbIsos() );
890 vIsoAspect->SetNumber( GetNbIsos() );
893 uIsoAspect->SetNumber( uIsos );
894 vIsoAspect->SetNumber( vIsos );
897 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
898 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
900 // set deflection coefficient
901 // ... to avoid to small values of the coefficient, its lower value is limited
902 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
906 if ( HasTexture() ) {
907 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
908 aImagePath = GetTexture().c_str();
909 if ( ! entry.isEmpty() ) {
910 // check that study is active
911 SalomeApp_Study* study = getActiveStudy();
913 // Store the texture in object properties for next displays
914 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
915 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
917 // Update propeties map
918 propMap = getObjectProperties( study, entry, myViewFrame );
923 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
926 #ifdef USE_TEXTURED_SHAPE
927 Handle(Image_PixMap) aPixmap;
928 if ( !aImagePath.isEmpty() )
929 aPixmap = cacheTextureFor( aImagePath, AISShape );
931 aPixmap = getDefaultTexture();
933 // apply image to shape
934 if ( !aPixmap.IsNull() ) {
935 AISShape->SetTexturePixMap( aPixmap );
936 AISShape->SetTextureMapOn();
937 AISShape->DisableTextureModulate();
940 AISShape->SetTextureMapOff();
945 AISShape->SetWidth( HasWidth() ?
946 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
948 // libe width from properties
949 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
951 // set top-level flag
952 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
954 // set point marker (for vertex / compound of vertices only)
955 if ( onlyVertex || isVerticesMode ) {
956 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
957 if ( aList.size() == 2 ) {
958 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
959 int aTypeOfMarker = aList[0].toInt();
960 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
961 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
962 anAspect->SetScale( aScaleOfMarker );
963 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
964 anAspect->SetColor( HasColor() ?
965 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
966 (Quantity_NameOfColor)GetColor() :
967 // color from properties
968 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
969 AISShape->Attributes()->SetPointAspect( anAspect );
971 else if ( aList.size() == 1 ) {
972 // custom marker string contains "IdOfTexture"
973 int textureId = aList[0].toInt();
974 Standard_Integer aWidth, aHeight;
975 Handle(TColStd_HArray1OfByte) aTexture =
976 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
977 if ( !aTexture.IsNull() ) {
978 Handle(Prs3d_PointAspect) aTextureAspect =
979 new Prs3d_PointAspect( HasColor() ?
980 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
981 (Quantity_NameOfColor)GetColor() :
982 // color from properties
983 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
986 AISShape->Attributes()->SetPointAspect( aTextureAspect );
991 // set field step data
992 AISShape->setFieldStepInfo( myFieldDataType,
997 myFieldStepRangeMax );
999 if ( create && !isTemporary && aMgrId != -1 ) {
1000 // set properties to the study
1001 study->setObjectProperties( aMgrId, entry, propMap );
1004 // AISShape->SetName(???); ??? necessary to set name ???
1007 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1009 // check that actor is not null
1010 if ( !actor ) return;
1012 // check that study is active
1013 SalomeApp_Study* study = getStudy();
1014 if ( !study ) return;
1016 // set interactive object
1018 Handle( SALOME_InteractiveObject ) anIO;
1020 if ( !myIO.IsNull() ) {
1021 actor->setIO( myIO );
1024 else if ( !myName.empty() ) {
1025 // workaround to allow selection of temporary objects
1026 static int tempId = 0;
1027 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1028 actor->setIO( anIO );
1031 // presentation study entry (empty for temporary objects like preview)
1032 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1033 // flag: temporary object
1034 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1035 // currently active view window's ID (-1 if no active view)
1036 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1038 // get presentation properties
1039 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1042 /////////////////////////////////////////////////////////////////////////
1043 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1044 // due to performance problem
1045 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1046 /////////////////////////////////////////////////////////////////////////
1047 if ( !actor->getTopo().IsSame( myShape ) )
1048 #ifdef LIMIT_DEFLECTION_FOR_VTK
1049 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1051 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1055 Material_Model material;
1056 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1057 std::vector<vtkProperty*> mprops;
1058 mprops.push_back( material.getMaterialVTKProperty( true ) );
1059 mprops.push_back( material.getMaterialVTKProperty( false) );
1060 actor->SetMaterial( mprops );
1062 // set iso-lines properties
1064 // - set number of iso-lines
1065 int nbIsos[2]= { 1, 1 };
1066 if ( HasNbIsos() ) {
1067 nbIsos[0] = GetNbIsos();
1068 nbIsos[1] = GetNbIsos();
1071 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1072 nbIsos[0] = isos[0].toInt();
1073 nbIsos[1] = isos[1].toInt();
1075 actor->SetNbIsos( nbIsos );
1077 // - set iso-lines width
1078 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1080 // - set iso-lines color
1081 if ( HasIsosColor() )
1082 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1084 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1085 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1090 // - same color for all sub-actors
1091 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1092 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1095 // shading color (for non-physical materials)
1096 if ( !material.isPhysical() ) {
1097 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1098 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1099 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1102 // - standalone edge color
1103 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1104 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1106 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1107 // - shared edges color ???
1108 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1110 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1111 // - free edges color ???
1112 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1115 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1116 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1119 // - color for edges in shading+edges mode
1120 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1121 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1124 if( HasTransparency() ) {
1125 actor->SetOpacity( 1.0 - GetTransparency() );
1127 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1131 actor->SetWidth( HasWidth() ?
1132 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1134 // libe width from properties
1135 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1137 // set display vectors flag
1138 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1140 // set display vertices flag
1141 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1144 int displayMode = HasDisplayMode() ?
1145 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1147 // display mode from properties
1148 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1150 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1151 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1152 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1153 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1155 if ( displayMode == 2 )
1156 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1157 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1159 actor->setDisplayMode( displayMode );
1162 actor->PickableOn();
1164 actor->PickableOff();
1166 if ( create && !isTemporary && aMgrId != -1 ) {
1167 // set properties to the study
1168 study->setObjectProperties( aMgrId, entry, propMap );
1172 //=================================================================
1174 * GEOM_Displayer::updateDimensions
1175 * Creates or renews dimension presentation for the IO.
1177 //=================================================================
1178 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1179 SALOME_OCCPrs* thePrs,
1180 const gp_Ax3& theShapeLCS )
1182 SalomeApp_Study* aStudy = getStudy();
1188 if ( theIO.IsNull() )
1193 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1195 AIS_ListOfInteractive aListOfIO;
1197 anOccPrs->GetObjects( aListOfIO );
1199 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1201 // remove outdated presentations of dimensions
1202 for ( ; aIterateIO.More(); aIterateIO.Next() )
1204 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1205 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1210 aListOfIO.Remove( aIterateIO );
1212 if ( !aIterateIO.More() )
1218 // prepare dimension styling
1219 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1221 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1222 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1223 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1224 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1225 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1226 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1227 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1229 // restore dimension presentation from saved attribute or property data
1230 AIS_ListOfInteractive aRestoredDimensions;
1232 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1234 GEOM::propertyName( GEOM::Dimensions ),
1237 GEOMGUI_DimensionProperty aRecords;
1239 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1241 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1245 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1248 // create up-to-date dimension presentations
1249 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1251 if ( !aRecords.IsVisible( aPrsIt ) )
1256 // init dimension by type
1257 Handle(AIS_Dimension) aPrs;
1258 switch( aRecords.GetType( aPrsIt ) )
1260 case GEOMGUI_DimensionProperty::DimensionType_Length :
1262 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1263 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1268 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1270 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1271 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1276 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1278 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1279 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1285 aPrs->SetOwner( theIO );
1287 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1289 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1291 aStyle->SetCommonColor( aColor );
1292 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1293 aStyle->MakeText3d( Standard_True );
1294 aStyle->MakeTextShaded( Standard_True );
1295 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1296 aStyle->TextAspect()->SetHeight( aFontHeight );
1297 aStyle->ArrowAspect()->SetLength( anArrowLength );
1298 aStyle->LineAspect()->SetWidth( aLineWidth );
1299 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1300 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1301 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1302 aPrs->SetDimensionAspect( aStyle );
1303 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1304 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1305 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1307 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1309 // show degree symbol for dimension instead of label "deg"
1310 if ( aUnitsAngle == "deg" )
1312 aPrs->SetSpecialSymbol(0xB0);
1313 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1314 aStyle->MakeUnitsDisplayed(Standard_False);
1318 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1319 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1324 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1327 aListOfIO.Append( aPrs );
1330 // update presentation
1333 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1335 anOccPrs->AddObject( aIterateIO.Value() );
1339 //=================================================================
1341 * GEOM_Displayer::Erase
1342 * Calls Erase() method for each object in the given list
1344 //=================================================================
1345 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1347 const bool updateViewer )
1349 SALOME_ListIteratorOfListIO Iter( theIOList );
1350 for ( ; Iter.More(); Iter.Next() )
1351 Erase( Iter.Value(), forced, false );
1357 //=================================================================
1359 * GEOM_Displayer::Redisplay
1360 * Calls Redisplay() method for each object in the given list
1362 //=================================================================
1363 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1364 const bool updateViewer,
1365 const bool checkActiveViewer )
1367 SALOME_ListIteratorOfListIO Iter( theIOList );
1368 for ( ; Iter.More(); Iter.Next() )
1369 Redisplay( Iter.Value(), false, checkActiveViewer );
1375 //=================================================================
1377 * GEOM_Displayer::Redisplay
1378 * Calls Redisplay() method for each object in the given list
1380 //=================================================================
1381 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1382 const bool theUpdateViewer,
1383 SALOME_View* theViewFrame )
1385 SALOME_ListIteratorOfListIO anIter( theIOList );
1386 for ( ; anIter.More(); anIter.Next() )
1388 Redisplay( anIter.Value(), false, theViewFrame );
1391 if ( theUpdateViewer )
1397 //=================================================================
1399 * GEOM_Displayer::Update
1400 * Update OCC presentaion
1401 * [ Reimplemented from SALOME_Displayer ]
1403 //=================================================================
1404 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1406 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1407 SalomeApp_Study* study = getStudy();
1409 if ( !occPrs || myShape.IsNull() || !study )
1412 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1415 // specific processing for local coordinate system presentation
1418 TopoDS_Face aFace = TopoDS::Face( myShape );
1419 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1420 if ( !aPlane.IsNull() )
1422 gp_Ax3 aPos = aPlane->Pln().Position();
1423 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1425 Handle(GEOM_AISTrihedron) aTrh;
1427 if ( occPrs->IsNull() )
1429 // new presentation is being created
1430 aTrh = new GEOM_AISTrihedron( aPlc );
1431 occPrs->AddObject( aTrh );
1435 // presentation is being updated
1436 AIS_ListOfInteractive aList;
1437 occPrs->GetObjects( aList );
1438 AIS_ListIteratorOfListOfInteractive anIter( aList );
1439 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1440 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1444 if ( !aTrh.IsNull() ) {
1445 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1447 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1448 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1450 aTrh->SetWidth( GetWidth() );
1452 if ( !myIO.IsNull() )
1454 aTrh->setIO( myIO );
1455 aTrh->SetOwner( myIO );
1457 aTrh->SetComponent( aPlc );
1458 aTrh->SetToUpdate();
1460 occPrs->SetToActivate( ToActivate() );
1466 // processing for usual geometry presentation
1469 // if presentation is empty we try to create new one
1470 if ( occPrs->IsNull() )
1472 // create presentation (specific for vectors)
1473 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1474 : new GEOM_AISShape ( myShape, "" );
1476 if( myType == GEOM_FIELD_STEP )
1477 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1478 // update shape properties
1479 updateShapeProperties( AISShape, true );
1481 // add shape to the presentation
1482 occPrs->AddObject( AISShape );
1484 // In accordance with ToActivate() value object will be activated/deactivated
1485 // when it will be displayed
1486 occPrs->SetToActivate( ToActivate() );
1488 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1489 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1491 // create additional wireframe shape
1492 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1493 aWirePrs->SetWidth(AISShape->Width());
1494 if ( !myIO.IsNull() ) {
1495 aWirePrs->setIO( myIO );
1496 aWirePrs->SetOwner( myIO );
1499 // add shape to the presentation
1500 occPrs->AddObject( aWirePrs );
1503 // if presentation is found -> set again shape for it
1506 AIS_ListOfInteractive IOList;
1507 occPrs->GetObjects( IOList );
1508 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1509 for ( ; Iter.More(); Iter.Next() )
1511 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1512 if ( AISShape.IsNull() )
1515 // re-set shape (it might be changed)
1516 if ( AISShape->Shape() != myShape )
1517 AISShape->Set( myShape );
1519 // update shape properties
1520 updateShapeProperties( AISShape, false );
1523 AISShape->UpdateSelection();
1524 AISShape->SetToUpdate();
1528 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1532 //=================================================================
1534 * GEOM_Displayer::Update
1535 * Update VTK presentaion
1536 * [ Reimplemented from SALOME_Displayer ]
1538 //=================================================================
1539 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1541 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1542 SalomeApp_Study* study = getStudy();
1544 if ( !vtkPrs || myShape.IsNull() || !study )
1547 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1550 // specific processing for local coordinate system presentation
1553 TopoDS_Face aFace = TopoDS::Face( myShape );
1554 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1555 if ( !aPlane.IsNull() ) {
1556 gp_Ax3 aPos = aPlane->Pln().Position();
1557 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1559 GEOM_VTKTrihedron* aTrh = 0;
1561 if ( vtkPrs->IsNull() ) {
1562 // new presentation is being created
1563 aTrh = GEOM_VTKTrihedron::New();
1564 vtkPrs->AddObject( aTrh );
1567 // presentation is being updated
1568 vtkActorCollection* actors = vtkPrs->GetObjects();
1570 actors->InitTraversal();
1571 vtkActor* a = actors->GetNextActor();
1572 while ( a && !aTrh ) {
1573 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1574 a = actors->GetNextActor();
1580 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1582 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1583 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1585 #ifdef VTK_TRIHEDRON_WIDTH
1587 // VSR: currently isn't supported
1589 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1591 aTrh->SetWidth( GetWidth() );
1594 if ( !myIO.IsNull() )
1595 aTrh->setIO( myIO );
1597 aTrh->SetPlacement( aPlc );
1604 // processing for usual geometry presentation
1607 // if presentation is empty we try to create new one
1608 if ( vtkPrs->IsNull() )
1611 GEOM_Actor* actor = GEOM_Actor::New();
1612 // update actor properties
1613 updateActorProperties( actor, true );
1614 // add actor to the presentation
1615 vtkPrs->AddObject( actor );
1618 // presentation is being updated
1619 vtkActorCollection* actors = vtkPrs->GetObjects();
1621 actors->InitTraversal();
1622 vtkActor* a = actors->GetNextActor();
1624 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1626 // update actor properties
1627 updateActorProperties( actor, false );
1628 a = actors->GetNextActor();
1636 //=================================================================
1638 * GEOM_Displayer::BuildPrs
1639 * Build presentation accordint to the current viewer type
1641 //=================================================================
1642 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1644 if ( theObj->_is_nil() )
1647 myViewFrame = GetActiveView();
1648 if ( myViewFrame == 0 )
1651 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1656 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1657 myType = theObj->GetType();
1659 // Update presentation
1665 //=================================================================
1667 * GEOM_Displayer::BuildPrs
1668 * Build presentation accordint to the current viewer type
1670 //=================================================================
1671 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1673 myViewFrame = GetActiveView();
1674 if ( theShape.IsNull() || myViewFrame == 0 )
1677 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1682 setShape( theShape );
1690 //=================================================================
1692 * GEOM_Displayer::buildPresentation
1693 * Builds/finds object's presentation for the current viewer
1694 * Calls corresponding Update() method by means of double dispatch
1697 //=================================================================
1698 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1699 SALOME_View* theViewFrame )
1701 SALOME_Prs* prs = 0;
1704 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1708 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1711 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1712 theIO->setEntry( entry.toLatin1().constData() );
1713 if ( !theIO.IsNull() )
1715 // set interactive object
1717 // Find SOBject (because shape should be published previously)
1718 SUIT_Session* session = SUIT_Session::session();
1719 SUIT_Application* app = session->activeApplication();
1722 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1725 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1728 // get CORBA reference to data object
1729 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1730 if ( !CORBA::is_nil( object ) )
1732 // downcast to GEOM base object
1733 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1734 if ( !GeomBaseObject->_is_nil() )
1736 myType = GeomBaseObject->GetType();
1738 // downcast to GEOM object
1739 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1740 if ( myType == GEOM_FIELD_STEP )
1742 // get the GEOM object from the field's shape
1743 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1744 if ( !GeomFieldStep->_is_nil() )
1746 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1747 if ( !GeomField->_is_nil() )
1748 GeomObject = GeomField->GetShape();
1751 // read the field step information
1752 readFieldStepInfo( GeomFieldStep );
1755 if ( !GeomObject->_is_nil() )
1757 // finally set shape
1758 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1766 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1772 //=================================================================
1774 * GEOM_Displayer::buildSubshapePresentation
1775 * Builds/finds object's presentation for the current viewer
1776 * Calls corresponding Update() method by means of double dispatch
1777 * For not published objects (for Mantis issue 0020435)
1779 //=================================================================
1780 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1781 const QString& entry,
1782 SALOME_View* theViewFrame)
1784 SALOME_Prs* prs = 0;
1787 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1791 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1794 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1795 theIO->setEntry(entry.toLatin1().constData());
1796 if (!theIO.IsNull())
1798 // set interactive object
1800 // finally set shape
1802 myType = GEOM_SUBSHAPE;
1804 UpdatePrs(prs); // Update presentation by using of the double dispatch
1810 //=================================================================
1812 * GEOM_Displayer::internalReset
1813 * Resets internal data
1816 //=================================================================
1817 void GEOM_Displayer::internalReset()
1822 myFieldDataType = GEOM::FDT_Double;
1823 myFieldDimension = 0;
1824 myFieldStepData.clear();
1825 myFieldStepName.Clear();
1826 myFieldStepRangeMin = 0;
1827 myFieldStepRangeMax = 0;
1830 //=================================================================
1832 * GEOM_Displayer::LocalSelection
1833 * Activate selection of CAD shapes with activisation of selection
1834 * of their sub-shapes (with opened local context for OCC viewer)
1836 //=================================================================
1837 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1839 SUIT_Session* session = SUIT_Session::session();
1840 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1844 LightApp_SelectionMgr* sm = app->selectionMgr();
1846 // remove all filters from selection
1849 SALOME_View* vf = GetActiveView();
1851 if (!theIO.IsNull() && !vf->isVisible(theIO))
1853 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1854 vf->LocalSelection( prs, theMode );
1855 delete prs; // delete presentation because displayer is its owner
1859 //=================================================================
1861 * GEOM_Displayer::globalSelection
1862 * Activate selection of CAD shapes without activisation of selection
1863 * of their sub-shapes (without opened local context for OCC viewer)
1865 //=================================================================
1866 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1868 TColStd_MapOfInteger aModes;
1869 aModes.Add( theMode );
1870 GlobalSelection( aModes, update );
1873 //=================================================================
1875 * GEOM_Displayer::globalSelection
1876 * Activate selection of CAD shapes without activisation of selection
1877 * of their sub-shapes (without opened local context for OCC viewer)
1879 //=================================================================
1880 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1881 const bool update, const QList<int>* theSubShapes )
1883 SUIT_Session* session = SUIT_Session::session();
1884 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1888 SALOME_View* vf = GetActiveView();
1892 // Close local context
1893 vf->GlobalSelection( update );
1895 // Set selection filters in accordance with current mode
1896 LightApp_SelectionMgr* sm = app->selectionMgr();
1900 // Remove from selection temporary objects if necessary
1901 if ( !theModes.Contains( GEOM_PREVIEW ) )
1902 clearTemporary( sm );
1904 //@ aSel->ClearIndex();
1908 // Remove filters from AIS_InteractiveContext
1909 Handle(AIS_InteractiveContext) ic;
1910 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1913 ic = viewer->getAISContext();
1915 ic->RemoveFilters();
1918 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1921 SUIT_SelectionFilter* aFilter;
1922 if ( theModes.Extent() == 1 )
1924 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1926 if ( aMode == GEOM_COMPOUNDFILTER )
1927 aFilter = getComplexFilter( theSubShapes );
1929 aFilter = getFilter( aMode );
1931 else if ( theModes.Extent() > 1 )
1933 TColStd_MapOfInteger aTopAbsModes;
1934 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1935 QList<SUIT_SelectionFilter*> aListOfFilters;
1936 for ( ; anIter.More(); anIter.Next() )
1938 SUIT_SelectionFilter* aFilter;
1939 int aMode = anIter.Key();
1940 if ( aMode == GEOM_COMPOUNDFILTER )
1941 aFilter = getComplexFilter( theSubShapes );
1943 aFilter = getFilter( aMode );
1946 aListOfFilters.append( aFilter );
1949 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1956 sm->installFilter( aFilter );
1959 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1960 ic->AddFilter( anOCCFilter );
1965 //=================================================================
1967 * GEOM_Displayer::LocalSelection
1968 * Activate selection of CAD shapes with activisation of selection
1969 * of their sub-shapes (with opened local context for OCC viewer)
1971 //=================================================================
1972 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1974 SALOME_ListIteratorOfListIO Iter( theIOList );
1975 for ( ; Iter.More(); Iter.Next() )
1976 LocalSelection( Iter.Value(), theMode );
1979 //=================================================================
1981 * GEOM_Displayer::BeforeDisplay
1982 * Called before displaying of pars. Close local context
1983 * [ Reimplemented from SALOME_Displayer ]
1985 //=================================================================
1986 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1988 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1991 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1994 if ( ic->HasOpenedContext() )
1995 ic->CloseAllContexts();
2000 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2002 UpdateColorScale(false,false);
2005 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2007 LightApp_Displayer::BeforeErase( v, p );
2008 releaseTextures( p );
2011 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2013 LightApp_Displayer::AfterErase( v, p );
2014 UpdateColorScale(false,false);
2017 //=================================================================
2019 * GEOM_Displayer::SetColor
2020 * Set color for shape displaying. If it is equal -1 then default color is used.
2021 * Available values are from Quantity_NameOfColor enumeration
2023 //=================================================================
2024 void GEOM_Displayer::SetColor( const int color )
2031 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2035 int GEOM_Displayer::GetColor() const
2040 bool GEOM_Displayer::HasColor() const
2042 return myColor != -1;
2045 void GEOM_Displayer::UnsetColor()
2049 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2050 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2051 myShadingColor = SalomeApp_Tools::color( col );
2054 //=================================================================
2056 * GEOM_Displayer::SetTransparency
2057 * Set transparency for shape displaying.
2059 //=================================================================
2060 double GEOM_Displayer::SetTransparency( const double transparency )
2062 double prevTransparency = myTransparency;
2063 myTransparency = transparency;
2064 return prevTransparency;
2067 //=================================================================
2069 * GEOM_Displayer::GetTransparency
2070 * Get transparency for shape displaying.
2072 //=================================================================
2073 double GEOM_Displayer::GetTransparency() const
2075 return myTransparency;
2078 //=================================================================
2080 * GEOM_Displayer::HasTransparency
2081 * Check if transparency for shape displaying is set.
2083 //=================================================================
2084 bool GEOM_Displayer::HasTransparency() const
2086 return myTransparency >= 0;
2089 //=================================================================
2091 * GEOM_Displayer::UnsetTransparency
2092 * Unset transparency for shape displaying.
2094 //=================================================================
2095 double GEOM_Displayer::UnsetTransparency()
2097 return SetTransparency( -1 );
2100 //=================================================================
2102 * GEOM_Displayer::SetTexture
2104 //=================================================================
2105 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2107 myTexture = texureFileName;
2110 bool GEOM_Displayer::HasTexture() const
2112 return myTexture != "";
2115 std::string GEOM_Displayer::GetTexture() const
2120 //=================================================================
2122 * GEOM_Displayer::SetWidth
2123 * Set width of shape displaying. If it is equal -1 then default width is used.
2125 //=================================================================
2126 void GEOM_Displayer::SetWidth( const double width )
2131 double GEOM_Displayer::GetWidth() const
2136 bool GEOM_Displayer::HasWidth() const
2138 return myWidth != -1;
2141 void GEOM_Displayer::UnsetWidth()
2146 int GEOM_Displayer::GetIsosWidth() const
2151 void GEOM_Displayer::SetIsosWidth(const int width)
2153 myIsosWidth = width;
2156 bool GEOM_Displayer::HasIsosWidth() const
2158 return myIsosWidth != -1;
2161 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2163 int prevNbIsos = myNbIsos;
2168 int GEOM_Displayer::UnsetNbIsos()
2170 return SetNbIsos( -1 );
2173 int GEOM_Displayer::GetNbIsos() const
2178 bool GEOM_Displayer::HasNbIsos() const
2180 return myNbIsos >= 0;
2183 int GEOM_Displayer::SetIsosColor( const int color )
2185 int prevColor = myIsosColor;
2186 myIsosColor = color;
2190 int GEOM_Displayer::GetIsosColor() const
2195 bool GEOM_Displayer::HasIsosColor() const
2197 return myIsosColor != -1;
2200 int GEOM_Displayer::UnsetIsosColor()
2202 return SetIsosColor( -1 );
2205 //=================================================================
2207 * GEOM_Displayer::SetToActivate
2208 * This method is used for activisation/deactivisation of objects to be displayed
2210 //=================================================================
2211 void GEOM_Displayer::SetToActivate( const bool toActivate )
2213 myToActivate = toActivate;
2215 bool GEOM_Displayer::ToActivate() const
2217 return myToActivate;
2220 //=================================================================
2222 * GEOM_Displayer::clearTemporary
2223 * Removes from selection temporary objects
2225 //=================================================================
2226 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2228 SALOME_ListIO selected, toSelect;
2229 theSelMgr->selectedObjects( selected );
2231 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2232 Handle(SALOME_InteractiveObject) io = it.Value();
2233 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2234 toSelect.Append( it.Value() );
2237 theSelMgr->setSelectedObjects( toSelect, true );
2240 void GEOM_Displayer::SetName( const char* theName )
2245 void GEOM_Displayer::UnsetName()
2250 SalomeApp_Study* GEOM_Displayer::getStudy() const
2252 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2255 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2260 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2265 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2266 const int theFieldDimension,
2267 const QList<QVariant>& theFieldStepData,
2268 const TCollection_AsciiString& theFieldStepName,
2269 const double theFieldStepRangeMin,
2270 const double theFieldStepRangeMax )
2272 myFieldDataType = theFieldDataType;
2273 myFieldDimension = theFieldDimension;
2274 myFieldStepData = theFieldStepData;
2275 myFieldStepName = theFieldStepName;
2276 myFieldStepRangeMin = theFieldStepRangeMin;
2277 myFieldStepRangeMax = theFieldStepRangeMax;
2280 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2282 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2283 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2284 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2285 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2286 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2287 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2290 int GEOM_Displayer::SetDisplayMode( const int theMode )
2292 int aPrevMode = myDisplayMode;
2293 if ( theMode != -1 ) {
2294 myDisplayMode = theMode;
2295 myHasDisplayMode = true;
2303 int GEOM_Displayer::GetDisplayMode() const
2305 return myDisplayMode;
2308 int GEOM_Displayer::UnsetDisplayMode()
2310 int aPrevMode = myDisplayMode;
2311 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2312 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2313 myHasDisplayMode = false;
2317 bool GEOM_Displayer::HasDisplayMode() const
2319 return myHasDisplayMode;
2322 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2324 static QList<QColor> colors;
2326 if ( colors.isEmpty() ) {
2328 for (int s = 0; s < 2 ; s++)
2330 for (int v = 100; v >= 40; v = v - 20)
2332 for (int h = 0; h < 359 ; h = h + 60)
2334 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2340 static int currentColor = randomize( colors.size() );
2342 SALOMEDS::Color color;
2343 color.R = (double)colors[currentColor].red() / 255.0;
2344 color.G = (double)colors[currentColor].green() / 255.0;
2345 color.B = (double)colors[currentColor].blue() / 255.0;
2347 currentColor = (currentColor+1) % colors.count();
2352 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2355 int aTolerance = 64;
2356 int anIterations = 0;
2362 if( anIterations % aPeriod == 0 )
2365 if( aTolerance < 1 )
2368 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2370 aHue = (int)( 360.0 * rand() / RAND_MAX );
2371 //std::cout << "Hue = " << aHue << std::endl;
2373 //std::cout << "Auto colors : ";
2375 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2376 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2377 for( ; it != itEnd; ++it )
2379 SALOMEDS::Color anAutoColor = *it;
2380 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2383 aQColor.getHsv( &h, &s, &v );
2384 //std::cout << h << " ";
2385 if( abs( h - aHue ) < aTolerance )
2388 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2392 //std::cout << std::endl;
2398 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2400 aColor.setHsv( aHue, 255, 255 );
2402 SALOMEDS::Color aSColor;
2403 aSColor.R = (double)aColor.red() / 255.0;
2404 aSColor.G = (double)aColor.green() / 255.0;
2405 aSColor.B = (double)aColor.blue() / 255.0;
2410 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2411 const QString& entry,
2414 // get default properties for the explicitly specified default view type
2415 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2417 if ( study && view ) {
2418 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2419 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2420 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2422 if ( viewModel && viewId != -1 ) {
2423 // get properties from the study
2424 PropMap storedMap = study->getObjectProperties( viewId, entry );
2425 // overwrite default properties from stored ones (that are specified)
2426 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2427 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2428 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2429 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2431 // ... specific processing for color
2432 // ... current implementation is to use same stored color for all aspects
2433 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2434 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2435 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2436 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2437 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2438 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2439 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2442 if ( !entry.isEmpty() ) {
2443 // get CORBA reference to geom object
2444 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2446 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2447 if ( !CORBA::is_nil( object ) ) {
2448 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2449 if ( !CORBA::is_nil( geomObject ) ) { // to check
2450 // check that geom object has color properly set
2451 bool hasColor = false;
2452 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2453 // set color from geometry object (only once, if it is not yet set in GUI)
2454 // current implementation is to use same color for all aspects
2455 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2456 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2457 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2458 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2459 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2460 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2461 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2462 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2464 // check that object has point marker properly set
2465 GEOM::marker_type mType = geomObject->GetMarkerType();
2466 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2467 int mTextureId = geomObject->GetMarkerTexture();
2468 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2469 ( mType == GEOM::MT_USER && mTextureId > 0 );
2470 // set point marker from geometry object (only once, if it is not yet set in GUI)
2471 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2472 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2474 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2475 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2477 else if ( mType == GEOM::MT_USER ) {
2479 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2491 PropMap GEOM_Displayer::getDefaultPropertyMap()
2495 // get resource manager
2496 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2498 // fill in the properties map with default values
2500 // - visibility (false by default)
2501 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2503 // - nb isos (take default value from preferences)
2504 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2505 QString( "%1%2%3" ).
2506 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2507 arg( GEOM::subSectionSeparator() ).
2508 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2510 // - transparency (opacity = 1-transparency)
2511 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2512 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2514 // - display mode (take default value from preferences)
2515 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2516 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2518 // - show edges direction flag (false by default)
2519 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2521 // - show vertices flag (false by default)
2522 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2524 // - shading color (take default value from preferences)
2525 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2526 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2528 // - wireframe color (take default value from preferences)
2529 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2530 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2532 // - standalone edges color (take default value from preferences)
2533 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2534 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2536 // - free boundaries color (take default value from preferences)
2537 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2538 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2540 // - points color (take default value from preferences)
2541 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2542 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2544 // - isos color (take default value from preferences)
2545 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2546 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2548 // - outlines color (take default value from preferences)
2549 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2550 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2552 // - deflection coefficient (take default value from preferences)
2553 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2554 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2556 // - material (take default value from preferences)
2557 Material_Model material;
2558 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2559 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2561 // - edge width (take default value from preferences)
2562 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2563 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2565 // - isos width (take default value from preferences)
2566 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2567 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2569 // - point marker (take default value from preferences)
2570 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2571 QString( "%1%2%3" ).
2572 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2573 arg( GEOM::subSectionSeparator() ).
2574 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2576 // - top-level flag (false by default)
2577 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2582 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2583 SALOMEDS::Color aSColor;
2586 SUIT_Session* session = SUIT_Session::session();
2587 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2589 if ( app && !theGeomObject->_is_nil()) {
2590 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2593 _PTR(Study) aStudy = study->studyDS();
2594 aSColor = theGeomObject->GetColor();
2595 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2597 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2598 bool general_autocolor = true;
2599 #else // auto-color for groups only
2600 bool general_autocolor = false;
2601 #endif // GENERAL_AUTOCOLOR
2602 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2603 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2604 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2605 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2606 aSColor = getPredefinedUniqueColor();
2608 #else // old algorithm for auto-colors
2609 QList<SALOMEDS::Color> aReservedColors;
2610 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2611 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2612 if ( aMainSObject ) {
2613 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2614 for ( ; it->More(); it->Next() ) {
2615 _PTR(SObject) aChildSObject( it->Value() );
2616 GEOM::GEOM_Object_var aChildObject =
2617 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2618 if ( CORBA::is_nil( aChildObject ) )
2621 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2622 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2623 aReservedColors.append( aReservedColor );
2626 aSColor = getUniqueColor( aReservedColors );
2628 #endif // SIMPLE_AUTOCOLOR
2638 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2639 const bool eraseOnlyChildren) {
2640 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2644 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2648 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2653 // Erase from all views
2654 QList<SALOME_View*> views;
2656 ViewManagerList vmans = app->viewManagers();
2657 SUIT_ViewManager* vman;
2658 foreach ( vman, vmans ) {
2659 SUIT_ViewModel* vmod = vman->getViewModel();
2660 view = dynamic_cast<SALOME_View*> ( vmod );
2662 views.append( view );
2665 if( views.count() == 0 )
2668 //Erase childrens w/o update views
2669 DataObjectList listObj = parent->children( true );
2670 SUIT_DataObject* obj;
2671 foreach( obj, listObj ) {
2672 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2674 foreach ( view, views ) {
2675 Handle(SALOME_InteractiveObject) anIO =
2676 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2677 Erase(anIO, false, false, view);
2681 //Erase parent with view update or repaint views
2682 foreach ( view, views ) {
2683 if(!eraseOnlyChildren)
2684 Erase(theIO, false, true, view);
2690 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2692 if( theGeomFieldStep->_is_nil() )
2695 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2696 if( aGeomField->_is_nil() )
2699 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2700 if( aGeomFieldShape->_is_nil() )
2703 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2704 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2705 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2707 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2709 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2711 int aFieldDimension = aGeomField->GetDimension();
2713 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2714 int aFieldNbComponents = aFieldComponents->length();
2716 QList<QVariant> aFieldStepData;
2717 if( aFieldDataType == GEOM::FDT_Bool )
2719 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2720 if ( !aGeomBoolFieldStep->_is_nil() )
2722 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2723 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2724 aFieldStepData << (bool)aValues[i];
2727 else if( aFieldDataType == GEOM::FDT_Int )
2729 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2730 if ( !aGeomIntFieldStep->_is_nil() )
2732 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2733 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2734 aFieldStepData << (qlonglong)aValues[i];
2737 else if( aFieldDataType == GEOM::FDT_Double )
2739 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2740 if ( !aGeomDoubleFieldStep->_is_nil() )
2742 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2743 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2744 aFieldStepData << (double)aValues[i];
2747 else if( aFieldDataType == GEOM::FDT_String )
2749 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2750 if ( !aGeomStringFieldStep->_is_nil() )
2752 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2753 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2754 aFieldStepData << QString( aValues[i] );
2758 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2759 aFieldStepData = groupFieldData( aFieldStepData,
2761 aFieldDataType == GEOM::FDT_String,
2763 aFieldStepRangeMax );
2765 setFieldStepInfo( aFieldDataType,
2770 aFieldStepRangeMax );
2773 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2774 const int theFieldNbComponents,
2775 const bool theIsString,
2776 double& theFieldStepRangeMin,
2777 double& theFieldStepRangeMax )
2779 QList<QVariant> aResultList;
2780 theFieldStepRangeMin = 0;
2781 theFieldStepRangeMax = 0;
2783 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2786 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2788 QList<QVariant> aGroupedList;
2790 bool anIsBoolean = false;
2791 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2794 QStringList aStringList;
2796 int aBaseIndex = aSubShape * theFieldNbComponents;
2797 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2799 int anIndex = aComponent + aBaseIndex;
2801 const QVariant& aVariant = theFieldStepData[ anIndex ];
2804 if( aVariant.type() == QVariant::String )
2805 aStringList << aVariant.toString();
2810 if( aVariant.type() == QVariant::Bool )
2812 aValue = aVariant.toBool() ? 1.0 : 0.0;
2818 if( aVariant.type() == QVariant::LongLong )
2819 aValue = double( aVariant.toLongLong() );
2820 else if( aVariant.type() == QVariant::Double )
2821 aValue = aVariant.toDouble();
2822 aNorm += aValue * aValue;
2828 aGroupedList << aStringList.join( "\n" );
2832 aNorm /= theFieldNbComponents;
2834 aNorm = pow( aNorm, 0.5 );
2836 if( aGroupedList.isEmpty() )
2837 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2840 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2841 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2844 aGroupedList << aNorm;
2850 theFieldStepRangeMin = 0.0;
2851 theFieldStepRangeMax = 1.0;
2854 SUIT_Session* session = SUIT_Session::session();
2855 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2856 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2858 QListIterator<QVariant> anIter( aGroupedList );
2859 while( anIter.hasNext() )
2861 const QVariant& aVariant = anIter.next();
2863 aResultList << aVariant;
2867 Quantity_Color aColor;
2868 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2869 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2870 aResultList << aQColor;
2876 // Note: the method is copied from Aspect_ColorScale class
2877 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2878 const Standard_Integer aMin,
2879 const Standard_Integer aMax )
2881 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2883 Standard_Integer aHue = maxLimit;
2885 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2887 aHue = Min( Max( minLimit, aHue ), maxLimit );
2892 // Note: the method is copied from Aspect_ColorScale class
2893 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2894 const Standard_Real aMin,
2895 const Standard_Real aMax,
2896 const Standard_Integer ColorsCount,
2897 Quantity_Color& aColor )
2899 if( aValue<aMin || aValue>aMax || aMax<aMin )
2900 return Standard_False;
2904 Standard_Real IntervNumber = 0;
2907 else if( aValue>aMax )
2908 IntervNumber = ColorsCount-1;
2909 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2910 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2912 Standard_Integer Interv = Standard_Integer( IntervNumber );
2914 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2916 return Standard_True;
2920 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2922 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2926 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2930 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2931 if( aViewer.IsNull() )
2934 aViewer->InitActiveViews();
2935 if( !aViewer->MoreActiveViews() )
2938 Handle(V3d_View) aView = aViewer->ActiveView();
2939 if( aView.IsNull() )
2942 Standard_Boolean anIsDisplayColorScale = Standard_False;
2943 TCollection_AsciiString aColorScaleTitle;
2944 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2945 Standard_Boolean anIsBoolean = Standard_False;
2947 SALOME_ListIO aSelectedObjects;
2948 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2949 if( aSelectedObjects.Extent() == 1 )
2951 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2952 if( !anIO.IsNull() )
2954 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2957 AIS_ListOfInteractive aList;
2958 aPrs->GetObjects( aList );
2959 AIS_ListIteratorOfListOfInteractive anIter( aList );
2960 for( ; anIter.More(); anIter.Next() )
2962 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2963 if( !aShape.IsNull() )
2965 GEOM::field_data_type aFieldDataType;
2966 int aFieldDimension;
2967 QList<QVariant> aFieldStepData;
2968 TCollection_AsciiString aFieldStepName;
2969 double aFieldStepRangeMin, aFieldStepRangeMax;
2970 aShape->getFieldStepInfo( aFieldDataType,
2975 aFieldStepRangeMax );
2976 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2978 anIsDisplayColorScale = Standard_True;
2979 aColorScaleTitle = aFieldStepName;
2980 aColorScaleMin = aFieldStepRangeMin;
2981 aColorScaleMax = aFieldStepRangeMax;
2982 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2990 if( anIsDisplayColorScale )
2992 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2993 if( !aColorScale.IsNull() )
2995 SUIT_Session* session = SUIT_Session::session();
2996 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2998 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2999 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3000 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3001 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3002 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3003 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3005 aColorScale->SetXPosition( anXPos );
3006 aColorScale->SetYPosition( anYPos );
3007 aColorScale->SetWidth( aWidth );
3008 aColorScale->SetHeight( aHeight );
3010 aColorScale->SetTextHeight( aTextHeight );
3011 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3013 aColorScale->SetTitle( aColorScaleTitle );
3014 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3016 if( !aView->ColorScaleIsDisplayed() )
3017 aView->ColorScaleDisplay();
3021 if( aView->ColorScaleIsDisplayed() )
3022 aView->ColorScaleErase();
3025 if( theIsRedisplayFieldSteps )
3027 _PTR(Study) aStudyDS = aStudy->studyDS();
3028 QList<SUIT_ViewManager*> vmList;
3029 myApp->viewManagers( vmList );
3030 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3032 if( SUIT_ViewManager* aViewManager = *vmIt )
3034 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3035 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3037 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3040 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3041 if( !CORBA::is_nil( anObject ) )
3043 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3044 if( !aFieldStep->_is_nil() )
3046 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3047 Handle(SALOME_InteractiveObject) aStepIO =
3048 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3049 Redisplay( aStepIO, false, false );