1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
28 #include "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
59 #include <Basics_OCCTVersion.hxx>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
68 #include <SALOME_ListIteratorOfListIO.hxx>
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
73 #include <SOCC_ViewModel.h>
76 #include <SVTK_ViewModel.h>
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
80 #include <OCCViewer_Utilities.h>
83 #include <AIS_Drawer.hxx>
84 #include <AIS_Dimension.hxx>
85 #include <AIS_LengthDimension.hxx>
86 #include <AIS_DiameterDimension.hxx>
87 #include <AIS_AngleDimension.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <Aspect_PolygonOffsetMode.hxx>
90 #include <Aspect_ColorScale.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <StdSelect_TypeOfEdge.hxx>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <StdSelect_DisplayMode.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <BRep_Tool.hxx>
98 #include <Geom_Plane.hxx>
99 #include <Geom_Axis2Placement.hxx>
100 #include <Graphic3d_AspectFillArea3d.hxx>
101 #include <gp_Pln.hxx>
102 #include <TColStd_MapOfInteger.hxx>
103 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
104 #include <TopoDS_Iterator.hxx>
105 #include <Graphic3d_AspectMarker3d.hxx>
106 #include <TopTools_MapOfShape.hxx>
107 #include <TopTools_ListOfShape.hxx>
108 #include <TopTools_ListIteratorOfListOfShape.hxx>
109 #include <TopoDS.hxx>
110 #include <NCollection_DataMap.hxx>
111 #include <NCollection_Map.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
127 #include <TColStd_HArray1OfByte.hxx>
129 #include <Graphic3d_HArray1OfBytes.hxx>
132 // If the next macro is defined, autocolor feature works for all sub-shapes;
133 // if it is undefined, autocolor feature works for groups only
134 #define GENERAL_AUTOCOLOR
135 // Below macro, when uncommented, switches on simplified (more performant) algorithm
136 // of auto-color picking up
137 #define SIMPLE_AUTOCOLOR
139 // Hard-coded value of shape deflection coefficient for VTK viewer
140 const double VTK_MIN_DEFLECTION = 0.001;
142 #if OCC_VERSION_LARGE > 0x06070000
143 // Pixmap caching support
146 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
147 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
148 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
150 static inline PixmapUsageMap& getPixmapUsageMap()
152 static PixmapUsageMap aMap;
156 static inline PixmapCacheMap& getPixmapCacheMap()
158 static PixmapCacheMap aMap;
162 //===========================================================================
163 // Function : getDefaultTexture
164 // Purpose : Get default texture
165 //===========================================================================
166 static inline Handle(Image_PixMap) getDefaultTexture()
168 static Handle(Image_PixMap) aPixmap;
169 if ( aPixmap.IsNull() ) {
170 QPixmap px(":images/default_texture.png");
172 aPixmap = imageToPixmap( px.toImage() );
177 //===========================================================================
178 // Function : cacheTextureFor
179 // Purpose : Load and cache image for the specified presentation.
180 //===========================================================================
181 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
182 const Handle(GEOM_AISShape)& theShape )
184 if ( thePath.isEmpty() )
187 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
188 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
190 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
191 if ( !aPixmap.IsNull() ) {
192 // point that the texture is used by the presentation
193 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
194 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
196 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
201 // convert texture to compatible image format
202 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
203 if ( anImage.isNull() )
206 aPixmap = imageToPixmap( anImage );
208 aPixmapCacheMap.insert( thePath, aPixmap );
210 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
211 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
213 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
218 //===========================================================================
219 // Function : releaseTextures
220 // Purpose : Releases cached textures found for the specified presentation.
221 //===========================================================================
222 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
224 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
226 AIS_ListOfInteractive aListOfIO;
228 anOccPrs->GetObjects( aListOfIO );
230 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
232 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
233 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
235 for ( ; aIterateIO.More(); aIterateIO.Next() )
237 Handle(GEOM_AISShape) aAISShape =
238 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
240 if ( aAISShape.IsNull() )
243 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
244 if ( aPixmap.IsNull() )
247 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
250 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
252 aUsersShapes.Remove( aAISShape );
254 if ( aUsersShapes.IsEmpty() ) {
255 aPixmapUsersMap.UnBind( aPixmap );
256 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
263 //================================================================
264 // Function : getActiveStudy
265 // Purpose : Get active study, returns 0 if no open study frame
266 //================================================================
267 static inline SalomeApp_Study* getActiveStudy()
269 SUIT_Session* session = SUIT_Session::session();
270 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
272 return ( SalomeApp_Study* )app->activeStudy();
276 static inline int getViewManagerId( SALOME_View* theViewFrame) {
277 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
278 SUIT_ViewManager* aViewMgr = 0;
280 aViewMgr = aModel->getViewManager();
281 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
284 //================================================================
285 // Function : getTopAbsMode
286 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
287 // one from GEOMImpl_Types.h
288 //================================================================
289 static inline int getTopAbsMode( const int implType )
293 case GEOM_COMPOUND : return TopAbs_COMPOUND;
294 case GEOM_SOLID : return TopAbs_SOLID;
295 case GEOM_SHELL : return TopAbs_SHELL;
296 case GEOM_FACE : return TopAbs_FACE;
297 case GEOM_WIRE : return TopAbs_WIRE;
298 case GEOM_EDGE : return TopAbs_EDGE;
299 case GEOM_POINT : return TopAbs_VERTEX;
304 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
306 if ( shape.IsNull() )
309 int ret = shape.ShapeType();
311 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
312 TopoDS_Iterator it(shape, Standard_True, Standard_False);
313 for (; it.More(); it.Next()) {
314 TopoDS_Shape sub_shape = it.Value();
315 if ( sub_shape.IsNull() ) continue;
316 int stype = getMinMaxShapeType( sub_shape, ismin );
317 if ( stype == TopAbs_SHAPE ) continue;
318 if ( ismin && stype > ret )
320 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
328 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
330 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
333 //================================================================
334 // Function : getFilter
335 // Purpose : Get filter corresponding to the type of object
336 // from GEOMImpl_Types.h
337 //================================================================
338 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
340 SUIT_SelectionFilter* aFilter;
342 int aTopAbsMode = getTopAbsMode( theMode );
343 if ( aTopAbsMode != -1 )
344 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
348 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
349 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
351 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
352 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
353 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
354 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
355 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
356 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
358 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
360 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
361 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
363 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
369 //================================================================
370 // Function : getComplexFilter
371 // Purpose : Get compound filter corresponding to the type of
372 // object from GEOMImpl_Types.h
373 //================================================================
374 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
376 GEOM_CompoundFilter* aFilter;
378 if(aSubShapes != NULL ) {
379 aFilter = new GEOM_CompoundFilter(getStudy());
380 QList<int> aTopAbsTypes;
381 QList<int>::const_iterator it;
382 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
383 int topAbsMode = getTopAbsMode(*it);
384 if(topAbsMode != -1 )
385 aTopAbsTypes.append(topAbsMode);
387 aFilter->addSubTypes(aTopAbsTypes);
393 //================================================================
394 // Function : getEntry
396 //================================================================
397 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
399 SUIT_Session* session = SUIT_Session::session();
400 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
403 CORBA::String_var IOR = app->orb()->object_to_string( object );
404 if ( strcmp(IOR.in(), "") != 0 )
406 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
407 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
415 //================================================================
416 // Function : getName
418 //================================================================
419 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
421 SUIT_Session* session = SUIT_Session::session();
422 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
425 CORBA::String_var IOR = app->orb()->object_to_string( object );
426 if ( strcmp(IOR.in(), "") != 0 )
428 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
429 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
431 _PTR(GenericAttribute) anAttr;
433 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
435 _PTR(AttributeName) aNameAttr( anAttr );
436 return aNameAttr->Value();
444 //=================================================================
446 * GEOM_Displayer::GEOM_Displayer
449 //=================================================================
450 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
453 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
458 SUIT_Session* session = SUIT_Session::session();
459 SUIT_ResourceMgr* resMgr = session->resourceMgr();
461 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
462 myShadingColor = SalomeApp_Tools::color( col );
464 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
465 myHasDisplayMode = false;
467 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
468 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
469 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
471 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
472 myHasTransparency = false;
474 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
475 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
476 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
479 // This color is used for shape displaying. If it is equal -1 then
480 // default color is used.
486 // This parameter is used for activisation/deactivisation of objects to be displayed
488 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
489 // Activate parallel vizualisation only for testing purpose
490 // and if the corresponding env variable is set to 1
491 char* parallel_visu = getenv("PARALLEL_VISU");
492 if (parallel_visu && atoi(parallel_visu))
494 MESSAGE("Parallel visualisation on");
495 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
501 myFieldDataType = GEOM::FDT_Double;
502 myFieldDimension = 0;
503 myFieldStepRangeMin = 0;
504 myFieldStepRangeMax = 0;
507 //=================================================================
509 * GEOM_Displayer::~GEOM_Displayer
512 //=================================================================
513 GEOM_Displayer::~GEOM_Displayer()
517 //=================================================================
519 * GEOM_Displayer::Display
520 * Display interactive object in the current viewer
522 //=================================================================
523 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
524 const bool updateViewer,
525 SALOME_View* theViewFrame )
527 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
530 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
534 vf->BeforeDisplay( this, prs );
536 vf->AfterDisplay( this, prs );
541 int aMgrId = getViewManagerId(vf);
542 SalomeApp_Study* aStudy = getStudy();
543 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
545 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
547 delete prs; // delete presentation because displayer is its owner
552 //=================================================================
554 * GEOM_Displayer::Display
555 * This overloaded Display() method can be useful for operations
556 * not using dialog boxes.
558 //=================================================================
559 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
561 if ( theObj->_is_nil() )
564 std::string entry = getEntry( theObj );
566 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
571 //=================================================================
573 * GEOM_Displayer::Erase
574 * Erase interactive object in the current viewer
576 //=================================================================
577 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
579 const bool updateViewer,
580 SALOME_View* theViewFrame )
582 if ( theIO.IsNull() )
585 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
588 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
590 vf->BeforeErase( this, prs );
591 vf->Erase( prs, forced );
592 vf->AfterErase( this, prs );
595 delete prs; // delete presentation because displayer is its owner
597 int aMgrId = getViewManagerId(vf);
598 SalomeApp_Study* aStudy = getStudy();
599 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
601 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
606 //=================================================================
608 * GEOM_Displayer::Erase
609 * Erase geometry object in the current viewer
611 //=================================================================
612 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
614 const bool updateViewer,
615 SALOME_View* theViewFrame)
617 std::string entry = getEntry( theObj );
620 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
621 forced, updateViewer, theViewFrame);
625 //=================================================================
627 * GEOM_Displayer::Redisplay
628 * Redisplay (erase and then display again) interactive object
629 * in the current viewer
631 //=================================================================
632 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
633 const bool updateViewer,
634 const bool checkActiveViewer )
636 // Remove the object permanently (<forced> == true)
637 SUIT_Session* ses = SUIT_Session::session();
638 SUIT_Application* app = ses->activeApplication();
641 SUIT_Desktop* desk = app->desktop();
642 QList<SUIT_ViewWindow*> wnds = desk->windows();
643 SUIT_ViewWindow* wnd;
644 QListIterator<SUIT_ViewWindow*> it( wnds );
645 while ( it.hasNext() && (wnd = it.next()) )
647 SUIT_ViewManager* vman = wnd->getViewManager();
650 SUIT_ViewModel* vmodel = vman->getViewModel();
653 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
656 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
658 Redisplay( theIO, updateViewer, view );
667 //=================================================================
669 * GEOM_Displayer::Redisplay
670 * Redisplay (erase and then display again) interactive object
671 * in the specified view
673 //=================================================================
674 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
675 const bool theUpdateViewer,
676 SALOME_View* theViewFrame )
678 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
684 Erase( theIO, true, false, theViewFrame );
685 Display( theIO, theUpdateViewer, theViewFrame );
688 //=================================================================
690 * GEOM_Displayer::Display
691 * Calls Display() method for each object in the given list
693 //=================================================================
694 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
696 SALOME_ListIteratorOfListIO Iter( theIOList );
697 for ( ; Iter.More(); Iter.Next() ) {
698 Display( Iter.Value(), false );
704 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
706 // VSR: this method can be improved in future:
707 // to improve performance, the default values from resource manager should be cached in the displayer
708 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
711 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
713 // VSR: this method can be improved in future:
714 // to improve performance, the default values from resource manager should be cached in the displayer
715 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
718 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
720 // check that shape is not null
721 if ( AISShape.IsNull() ) return;
723 // check that study is active
724 SalomeApp_Study* study = getStudy();
725 if ( !study ) return;
727 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
728 !TopoDS_Iterator(myShape).More() )
729 return; // NPAL15983 (Bug when displaying empty groups)
731 // set interactive object
733 Handle( SALOME_InteractiveObject ) anIO;
735 if ( !myIO.IsNull() ) {
736 AISShape->setIO( myIO );
737 AISShape->SetOwner( myIO );
740 else if ( !myName.empty() ) {
741 // workaround to allow selection of temporary objects
742 static int tempId = 0;
743 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
744 AISShape->setIO( anIO );
745 AISShape->SetOwner( anIO );
748 // flag: only vertex or compound of vertices is processed (specific handling)
749 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
750 // presentation study entry (empty for temporary objects like preview)
751 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
752 // flag: temporary object
753 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
754 // currently active view window's ID (-1 if no active view)
755 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
757 // get presentation properties
758 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
760 // Temporary staff: vertex must be infinite for correct visualization
761 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
764 Material_Model material;
765 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
767 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
768 // - set front material properties
769 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
770 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
771 // - set back material properties
772 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
773 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
774 // - switch to default (both sides) facing mode
775 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
781 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
782 // we set it to the shape not taking into account material properties
783 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
785 else if ( !material.isPhysical() ) {
786 // shading color from properties is used only for non-physical materials
787 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
791 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
792 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
793 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
794 AISShape->Attributes()->SetLineAspect( anAspect );
796 // - unfree boundaries color
797 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
798 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
799 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
800 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
802 // - free boundaries color
803 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
804 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
805 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
806 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
808 // - standalone edges color
809 anAspect = AISShape->Attributes()->WireAspect();
810 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
811 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
812 AISShape->Attributes()->SetWireAspect( anAspect );
814 // - color for edges in shading+edges mode
815 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
818 AISShape->SetDisplayMode( HasDisplayMode() ?
819 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
821 // display mode from properties
822 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
824 // - face boundaries color
825 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
826 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
827 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
828 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
829 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
831 // set display vectors flag
832 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
834 // set display vertices flag
835 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
836 AISShape->SetDisplayVertices( isVerticesMode );
839 if( HasTransparency() ) {
840 AISShape->SetTransparency( GetTransparency() );
842 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
845 // set iso properties
846 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
847 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
848 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
849 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
850 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
851 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
852 uIsoAspect->SetColor( isosColor );
853 uIsoAspect->SetWidth( isosWidth );
854 uIsoAspect->SetNumber( uIsos );
855 vIsoAspect->SetColor( isosColor );
856 vIsoAspect->SetWidth( isosWidth );
857 vIsoAspect->SetNumber( vIsos );
858 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
859 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
861 // set deflection coefficient
862 // ... to avoid to small values of the coefficient, its lower value is limited
863 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
867 if ( HasTexture() ) {
868 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
869 aImagePath = GetTexture().c_str();
870 if ( ! entry.isEmpty() ) {
871 // check that study is active
872 SalomeApp_Study* study = getActiveStudy();
874 // Store the texture in object properties for next displays
875 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
876 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
878 // Update propeties map
879 propMap = getObjectProperties( study, entry, myViewFrame );
884 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
887 #if OCC_VERSION_LARGE > 0x06070000
888 Handle(Image_PixMap) aPixmap;
889 if ( !aImagePath.isEmpty() )
890 aPixmap = cacheTextureFor( aImagePath, AISShape );
892 aPixmap = getDefaultTexture();
894 // apply image to shape
895 if ( !aPixmap.IsNull() ) {
896 AISShape->SetTexturePixMap( aPixmap );
897 AISShape->SetTextureMapOn();
898 AISShape->DisableTextureModulate();
901 AISShape->SetTextureMapOff();
904 if ( !aImagePath.isEmpty() ) {
905 AISShape->SetTextureFileName( TCollection_AsciiString( aImagePath.toUtf8().constData() ) );
906 AISShape->SetTextureMapOn();
907 AISShape->DisableTextureModulate();
912 AISShape->SetWidth( HasWidth() ?
913 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
915 // libe width from properties
916 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
918 // set top-level flag
919 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
921 // set point marker (for vertex / compound of vertices only)
922 if ( onlyVertex || isVerticesMode ) {
923 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
924 if ( aList.size() == 2 ) {
925 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
926 int aTypeOfMarker = aList[0].toInt();
927 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
928 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
929 anAspect->SetScale( aScaleOfMarker );
930 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
931 anAspect->SetColor( HasColor() ?
932 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
933 (Quantity_NameOfColor)GetColor() :
934 // color from properties
935 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
936 AISShape->Attributes()->SetPointAspect( anAspect );
938 else if ( aList.size() == 1 ) {
939 // custom marker string contains "IdOfTexture"
940 int textureId = aList[0].toInt();
941 Standard_Integer aWidth, aHeight;
942 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
943 Handle(TColStd_HArray1OfByte) aTexture =
945 Handle(Graphic3d_HArray1OfBytes) aTexture =
947 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
948 if ( !aTexture.IsNull() ) {
949 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
950 Handle(Prs3d_PointAspect) aTextureAspect =
951 new Prs3d_PointAspect( HasColor() ?
952 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
953 (Quantity_NameOfColor)GetColor() :
954 // color from properties
955 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
960 Handle(Prs3d_PointAspect) aTextureAspect =
961 new Prs3d_PointAspect( HasColor() ?
962 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
963 (Quantity_NameOfColor)GetColor() :
964 // color from properties
965 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
970 AISShape->Attributes()->SetPointAspect( aTextureAspect );
975 // set field step data
976 AISShape->setFieldStepInfo( myFieldDataType,
981 myFieldStepRangeMax );
983 if ( create && !isTemporary && aMgrId != -1 ) {
984 // set properties to the study
985 study->setObjectPropMap( aMgrId, entry, propMap );
988 // AISShape->SetName(???); ??? necessary to set name ???
991 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
993 // check that actor is not null
994 if ( !actor ) return;
996 // check that study is active
997 SalomeApp_Study* study = getStudy();
998 if ( !study ) return;
1000 // set interactive object
1002 Handle( SALOME_InteractiveObject ) anIO;
1004 if ( !myIO.IsNull() ) {
1005 actor->setIO( myIO );
1008 else if ( !myName.empty() ) {
1009 // workaround to allow selection of temporary objects
1010 static int tempId = 0;
1011 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1012 actor->setIO( anIO );
1015 // presentation study entry (empty for temporary objects like preview)
1016 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1017 // flag: temporary object
1018 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1019 // currently active view window's ID (-1 if no active view)
1020 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1022 // get presentation properties
1023 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1026 /////////////////////////////////////////////////////////////////////////
1027 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1028 // due to performance problem
1029 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1030 /////////////////////////////////////////////////////////////////////////
1031 if ( !actor->getTopo().IsSame( myShape ) )
1032 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1035 Material_Model material;
1036 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1037 std::vector<vtkProperty*> mprops;
1038 mprops.push_back( material.getMaterialVTKProperty( true ) );
1039 mprops.push_back( material.getMaterialVTKProperty( false) );
1040 actor->SetMaterial( mprops );
1042 // set iso-lines properties
1044 // - set number of iso-lines
1045 int nbIsos[2]= { 1, 1 };
1046 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1047 nbIsos[0] = isos[0].toInt();
1048 nbIsos[1] = isos[1].toInt();
1049 actor->SetNbIsos( nbIsos );
1051 // - set iso-lines width
1052 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1054 // - set iso-lines color
1055 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1056 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1061 // - same color for all sub-actors
1062 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1063 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1066 // shading color (for non-physical materials)
1067 if ( !material.isPhysical() ) {
1068 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1069 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1070 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1073 // - standalone edge color
1074 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1075 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1077 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1078 // - shared edges color ???
1079 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1081 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1082 // - free edges color ???
1083 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1086 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1087 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1090 // - color for edges in shading+edges mode
1091 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1092 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1095 if( HasTransparency() ) {
1096 actor->SetOpacity( 1.0 - GetTransparency() );
1098 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1102 actor->SetWidth( HasWidth() ?
1103 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1105 // libe width from properties
1106 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1108 // set display vectors flag
1109 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1111 // set display vertices flag
1112 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1115 int displayMode = HasDisplayMode() ?
1116 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1118 // display mode from properties
1119 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1121 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1122 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1123 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1124 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1126 if ( displayMode == 2 )
1127 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1128 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1130 actor->setDisplayMode( displayMode );
1133 actor->PickableOn();
1135 actor->PickableOff();
1137 if ( create && !isTemporary && aMgrId != -1 ) {
1138 // set properties to the study
1139 study->setObjectPropMap( aMgrId, entry, propMap );
1143 //=================================================================
1145 * GEOM_Displayer::updateDimensions
1146 * Creates or renews dimension presentation for the IO.
1148 //=================================================================
1149 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1150 SALOME_OCCPrs* thePrs,
1151 const gp_Ax3& theShapeLCS )
1153 SalomeApp_Study* aStudy = getStudy();
1159 if ( theIO.IsNull() )
1164 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1166 AIS_ListOfInteractive aListOfIO;
1168 anOccPrs->GetObjects( aListOfIO );
1170 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1172 // remove outdated presentations of dimensions
1173 for ( ; aIterateIO.More(); aIterateIO.Next() )
1175 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1176 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1181 aListOfIO.Remove( aIterateIO );
1183 if ( !aIterateIO.More() )
1189 // prepare dimension styling
1190 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1192 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1193 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1194 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1195 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1196 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1197 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1198 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1200 // restore dimension presentation from saved attribute or property data
1201 AIS_ListOfInteractive aRestoredDimensions;
1203 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1205 GEOM::propertyName( GEOM::Dimensions ),
1208 GEOMGUI_DimensionProperty aRecords;
1210 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1212 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1216 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1219 // create up-to-date dimension presentations
1220 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1222 if ( !aRecords.IsVisible( aPrsIt ) )
1227 // init dimension by type
1228 Handle(AIS_Dimension) aPrs;
1229 switch( aRecords.GetType( aPrsIt ) )
1231 case GEOMGUI_DimensionProperty::DimensionType_Length :
1233 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1234 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1239 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1241 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1242 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1247 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1249 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1250 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1256 aPrs->SetOwner( theIO );
1258 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1260 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1262 aStyle->SetCommonColor( aColor );
1263 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1264 aStyle->MakeText3d( Standard_True );
1265 aStyle->MakeTextShaded( Standard_True );
1266 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1267 aStyle->TextAspect()->SetHeight( aFontHeight );
1268 aStyle->ArrowAspect()->SetLength( anArrowLength );
1269 aStyle->LineAspect()->SetWidth( aLineWidth );
1270 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1271 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1272 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1273 aPrs->SetDimensionAspect( aStyle );
1274 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1275 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1276 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1278 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1280 // show degree symbol for dimension instead of label "deg"
1281 if ( aUnitsAngle == "deg" )
1283 aPrs->SetSpecialSymbol(0xB0);
1284 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1285 aStyle->MakeUnitsDisplayed(Standard_False);
1289 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1290 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1295 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1298 aListOfIO.Append( aPrs );
1301 // update presentation
1304 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1306 anOccPrs->AddObject( aIterateIO.Value() );
1310 //=================================================================
1312 * GEOM_Displayer::Erase
1313 * Calls Erase() method for each object in the given list
1315 //=================================================================
1316 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1318 const bool updateViewer )
1320 SALOME_ListIteratorOfListIO Iter( theIOList );
1321 for ( ; Iter.More(); Iter.Next() )
1322 Erase( Iter.Value(), forced, false );
1328 //=================================================================
1330 * GEOM_Displayer::Redisplay
1331 * Calls Redisplay() method for each object in the given list
1333 //=================================================================
1334 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1335 const bool updateViewer,
1336 const bool checkActiveViewer )
1338 SALOME_ListIteratorOfListIO Iter( theIOList );
1339 for ( ; Iter.More(); Iter.Next() )
1340 Redisplay( Iter.Value(), false, checkActiveViewer );
1346 //=================================================================
1348 * GEOM_Displayer::Redisplay
1349 * Calls Redisplay() method for each object in the given list
1351 //=================================================================
1352 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1353 const bool theUpdateViewer,
1354 SALOME_View* theViewFrame )
1356 SALOME_ListIteratorOfListIO anIter( theIOList );
1357 for ( ; anIter.More(); anIter.Next() )
1359 Redisplay( anIter.Value(), false, theViewFrame );
1362 if ( theUpdateViewer )
1368 //=================================================================
1370 * GEOM_Displayer::Update
1371 * Update OCC presentaion
1372 * [ Reimplemented from SALOME_Displayer ]
1374 //=================================================================
1375 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1377 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1378 SalomeApp_Study* study = getStudy();
1380 if ( !occPrs || myShape.IsNull() || !study )
1383 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1386 // specific processing for local coordinate system presentation
1389 TopoDS_Face aFace = TopoDS::Face( myShape );
1390 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1391 if ( !aPlane.IsNull() )
1393 gp_Ax3 aPos = aPlane->Pln().Position();
1394 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1396 Handle(GEOM_AISTrihedron) aTrh;
1398 if ( occPrs->IsNull() )
1400 // new presentation is being created
1401 aTrh = new GEOM_AISTrihedron( aPlc );
1402 occPrs->AddObject( aTrh );
1406 // presentation is being updated
1407 AIS_ListOfInteractive aList;
1408 occPrs->GetObjects( aList );
1409 AIS_ListIteratorOfListOfInteractive anIter( aList );
1410 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1411 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1415 if ( !aTrh.IsNull() ) {
1416 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1418 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1419 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1421 aTrh->SetWidth( GetWidth() );
1423 if ( !myIO.IsNull() )
1425 aTrh->setIO( myIO );
1426 aTrh->SetOwner( myIO );
1428 aTrh->SetComponent( aPlc );
1429 aTrh->SetToUpdate();
1431 occPrs->SetToActivate( ToActivate() );
1437 // processing for usual geometry presentation
1440 // if presentation is empty we try to create new one
1441 if ( occPrs->IsNull() )
1443 // create presentation (specific for vectors)
1444 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1445 : new GEOM_AISShape ( myShape, "" );
1447 if( myType == GEOM_FIELD_STEP )
1448 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1449 // update shape properties
1450 updateShapeProperties( AISShape, true );
1452 // add shape to the presentation
1453 occPrs->AddObject( AISShape );
1455 // In accordance with ToActivate() value object will be activated/deactivated
1456 // when it will be displayed
1457 occPrs->SetToActivate( ToActivate() );
1459 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1460 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1462 // create additional wireframe shape
1463 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1464 aWirePrs->SetWidth(AISShape->Width());
1465 if ( !myIO.IsNull() ) {
1466 aWirePrs->setIO( myIO );
1467 aWirePrs->SetOwner( myIO );
1470 // add shape to the presentation
1471 occPrs->AddObject( aWirePrs );
1474 // if presentation is found -> set again shape for it
1477 AIS_ListOfInteractive IOList;
1478 occPrs->GetObjects( IOList );
1479 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1480 for ( ; Iter.More(); Iter.Next() )
1482 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1483 if ( AISShape.IsNull() )
1486 // re-set shape (it might be changed)
1487 if ( AISShape->Shape() != myShape )
1488 AISShape->Set( myShape );
1490 // update shape properties
1491 updateShapeProperties( AISShape, false );
1494 AISShape->UpdateSelection();
1495 AISShape->SetToUpdate();
1499 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1503 //=================================================================
1505 * GEOM_Displayer::Update
1506 * Update VTK presentaion
1507 * [ Reimplemented from SALOME_Displayer ]
1509 //=================================================================
1510 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1512 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1513 SalomeApp_Study* study = getStudy();
1515 if ( !vtkPrs || myShape.IsNull() || !study )
1518 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1521 // specific processing for local coordinate system presentation
1524 TopoDS_Face aFace = TopoDS::Face( myShape );
1525 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1526 if ( !aPlane.IsNull() ) {
1527 gp_Ax3 aPos = aPlane->Pln().Position();
1528 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1530 GEOM_VTKTrihedron* aTrh = 0;
1532 if ( vtkPrs->IsNull() ) {
1533 // new presentation is being created
1534 aTrh = GEOM_VTKTrihedron::New();
1535 vtkPrs->AddObject( aTrh );
1538 // presentation is being updated
1539 vtkActorCollection* actors = vtkPrs->GetObjects();
1541 actors->InitTraversal();
1542 vtkActor* a = actors->GetNextActor();
1543 while ( a && !aTrh ) {
1544 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1545 a = actors->GetNextActor();
1551 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1553 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1554 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1556 #ifdef VTK_TRIHEDRON_WIDTH
1558 // VSR: currently isn't supported
1560 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1562 aTrh->SetWidth( GetWidth() );
1565 if ( !myIO.IsNull() )
1566 aTrh->setIO( myIO );
1568 aTrh->SetPlacement( aPlc );
1575 // processing for usual geometry presentation
1578 // if presentation is empty we try to create new one
1579 if ( vtkPrs->IsNull() )
1582 GEOM_Actor* actor = GEOM_Actor::New();
1583 // update actor properties
1584 updateActorProperties( actor, true );
1585 // add actor to the presentation
1586 vtkPrs->AddObject( actor );
1589 // presentation is being updated
1590 vtkActorCollection* actors = vtkPrs->GetObjects();
1592 actors->InitTraversal();
1593 vtkActor* a = actors->GetNextActor();
1595 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1597 // update actor properties
1598 updateActorProperties( actor, false );
1599 a = actors->GetNextActor();
1607 //=================================================================
1609 * GEOM_Displayer::BuildPrs
1610 * Build presentation accordint to the current viewer type
1612 //=================================================================
1613 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1615 if ( theObj->_is_nil() )
1618 myViewFrame = GetActiveView();
1619 if ( myViewFrame == 0 )
1622 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1627 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1628 myType = theObj->GetType();
1630 // Update presentation
1636 //=================================================================
1638 * GEOM_Displayer::BuildPrs
1639 * Build presentation accordint to the current viewer type
1641 //=================================================================
1642 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1644 myViewFrame = GetActiveView();
1645 if ( theShape.IsNull() || myViewFrame == 0 )
1648 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1653 setShape( theShape );
1661 //=================================================================
1663 * GEOM_Displayer::buildPresentation
1664 * Builds/finds object's presentation for the current viewer
1665 * Calls corresponding Update() method by means of double dispatch
1668 //=================================================================
1669 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1670 SALOME_View* theViewFrame )
1672 SALOME_Prs* prs = 0;
1675 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1679 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1682 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1683 theIO->setEntry( entry.toLatin1().constData() );
1684 if ( !theIO.IsNull() )
1686 // set interactive object
1688 // Find SOBject (because shape should be published previously)
1689 SUIT_Session* session = SUIT_Session::session();
1690 SUIT_Application* app = session->activeApplication();
1693 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1696 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1699 // get CORBA reference to data object
1700 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1701 if ( !CORBA::is_nil( object ) )
1703 // downcast to GEOM base object
1704 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1705 if ( !GeomBaseObject->_is_nil() )
1707 myType = GeomBaseObject->GetType();
1709 // downcast to GEOM object
1710 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1711 if ( myType == GEOM_FIELD_STEP )
1713 // get the GEOM object from the field's shape
1714 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1715 if ( !GeomFieldStep->_is_nil() )
1717 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1718 if ( !GeomField->_is_nil() )
1719 GeomObject = GeomField->GetShape();
1722 // read the field step information
1723 readFieldStepInfo( GeomFieldStep );
1726 if ( !GeomObject->_is_nil() )
1728 // finally set shape
1729 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1737 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1743 //=================================================================
1745 * GEOM_Displayer::buildSubshapePresentation
1746 * Builds/finds object's presentation for the current viewer
1747 * Calls corresponding Update() method by means of double dispatch
1748 * For not published objects (for Mantis issue 0020435)
1750 //=================================================================
1751 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1752 const QString& entry,
1753 SALOME_View* theViewFrame)
1755 SALOME_Prs* prs = 0;
1758 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1762 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1765 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1766 theIO->setEntry(entry.toLatin1().constData());
1767 if (!theIO.IsNull())
1769 // set interactive object
1771 // finally set shape
1773 myType = GEOM_SUBSHAPE;
1775 UpdatePrs(prs); // Update presentation by using of the double dispatch
1781 //=================================================================
1783 * GEOM_Displayer::internalReset
1784 * Resets internal data
1787 //=================================================================
1788 void GEOM_Displayer::internalReset()
1793 myFieldDataType = GEOM::FDT_Double;
1794 myFieldDimension = 0;
1795 myFieldStepData.clear();
1796 myFieldStepName.Clear();
1797 myFieldStepRangeMin = 0;
1798 myFieldStepRangeMax = 0;
1801 //=================================================================
1803 * GEOM_Displayer::LocalSelection
1804 * Activate selection of CAD shapes with activisation of selection
1805 * of their sub-shapes (with opened local context for OCC viewer)
1807 //=================================================================
1808 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1810 SUIT_Session* session = SUIT_Session::session();
1811 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1815 LightApp_SelectionMgr* sm = app->selectionMgr();
1817 // remove all filters from selection
1820 SALOME_View* vf = GetActiveView();
1822 if (!theIO.IsNull() && !vf->isVisible(theIO))
1824 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1825 vf->LocalSelection( prs, theMode );
1826 delete prs; // delete presentation because displayer is its owner
1830 //=================================================================
1832 * GEOM_Displayer::globalSelection
1833 * Activate selection of CAD shapes without activisation of selection
1834 * of their sub-shapes (without opened local context for OCC viewer)
1836 //=================================================================
1837 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1839 TColStd_MapOfInteger aModes;
1840 aModes.Add( theMode );
1841 GlobalSelection( aModes, update );
1844 //=================================================================
1846 * GEOM_Displayer::globalSelection
1847 * Activate selection of CAD shapes without activisation of selection
1848 * of their sub-shapes (without opened local context for OCC viewer)
1850 //=================================================================
1851 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1852 const bool update, const QList<int>* theSubShapes )
1854 SUIT_Session* session = SUIT_Session::session();
1855 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1859 SALOME_View* vf = GetActiveView();
1863 // Close local context
1864 vf->GlobalSelection( update );
1866 // Set selection filters in accordance with current mode
1867 LightApp_SelectionMgr* sm = app->selectionMgr();
1871 // Remove from selection temporary objects if necessary
1872 if ( !theModes.Contains( GEOM_PREVIEW ) )
1873 clearTemporary( sm );
1875 //@ aSel->ClearIndex();
1879 // Remove filters from AIS_InteractiveContext
1880 Handle(AIS_InteractiveContext) ic;
1881 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1884 ic = viewer->getAISContext();
1886 ic->RemoveFilters();
1889 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1892 SUIT_SelectionFilter* aFilter;
1893 if ( theModes.Extent() == 1 )
1895 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1897 if ( aMode == GEOM_COMPOUNDFILTER )
1898 aFilter = getComplexFilter( theSubShapes );
1900 aFilter = getFilter( aMode );
1902 else if ( theModes.Extent() > 1 )
1904 TColStd_MapOfInteger aTopAbsModes;
1905 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1906 QList<SUIT_SelectionFilter*> aListOfFilters;
1907 for ( ; anIter.More(); anIter.Next() )
1909 SUIT_SelectionFilter* aFilter;
1910 int aMode = anIter.Key();
1911 if ( aMode == GEOM_COMPOUNDFILTER )
1912 aFilter = getComplexFilter( theSubShapes );
1914 aFilter = getFilter( aMode );
1917 aListOfFilters.append( aFilter );
1920 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1927 sm->installFilter( aFilter );
1930 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1931 ic->AddFilter( anOCCFilter );
1936 //=================================================================
1938 * GEOM_Displayer::LocalSelection
1939 * Activate selection of CAD shapes with activisation of selection
1940 * of their sub-shapes (with opened local context for OCC viewer)
1942 //=================================================================
1943 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1945 SALOME_ListIteratorOfListIO Iter( theIOList );
1946 for ( ; Iter.More(); Iter.Next() )
1947 LocalSelection( Iter.Value(), theMode );
1950 //=================================================================
1952 * GEOM_Displayer::BeforeDisplay
1953 * Called before displaying of pars. Close local context
1954 * [ Reimplemented from SALOME_Displayer ]
1956 //=================================================================
1957 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1959 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1962 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1965 if ( ic->HasOpenedContext() )
1966 ic->CloseAllContexts();
1971 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1973 UpdateColorScale(false,false);
1976 #if OCC_VERSION_LARGE > 0x06070000
1977 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1979 LightApp_Displayer::BeforeErase( v, p );
1980 releaseTextures( p );
1984 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1986 LightApp_Displayer::AfterErase( v, p );
1987 UpdateColorScale(false,false);
1990 //=================================================================
1992 * GEOM_Displayer::SetColor
1993 * Set color for shape displaying. If it is equal -1 then default color is used.
1994 * Available values are from Quantity_NameOfColor enumeration
1996 //=================================================================
1997 void GEOM_Displayer::SetColor( const int color )
2004 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2008 int GEOM_Displayer::GetColor() const
2013 bool GEOM_Displayer::HasColor() const
2015 return myColor != -1;
2018 void GEOM_Displayer::UnsetColor()
2022 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2023 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2024 myShadingColor = SalomeApp_Tools::color( col );
2027 //=================================================================
2029 * GEOM_Displayer::SetTransparency
2030 * Set transparency for shape displaying.
2032 //=================================================================
2033 double GEOM_Displayer::SetTransparency( const double transparency )
2035 double aPrevTransparency = myTransparency;
2036 if ( transparency < 0 ) {
2037 UnsetTransparency();
2040 myTransparency = transparency;
2041 myHasTransparency = true;
2043 return aPrevTransparency;
2046 //=================================================================
2048 * GEOM_Displayer::GetTransparency
2049 * Get transparency for shape displaying.
2051 //=================================================================
2052 double GEOM_Displayer::GetTransparency() const
2054 return myTransparency;
2057 //=================================================================
2059 * GEOM_Displayer::HasTransparency
2060 * Check if transparency for shape displaying is set.
2062 //=================================================================
2063 bool GEOM_Displayer::HasTransparency() const
2065 return myHasTransparency;
2068 //=================================================================
2070 * GEOM_Displayer::UnsetTransparency
2071 * Unset transparency for shape displaying.
2073 //=================================================================
2074 double GEOM_Displayer::UnsetTransparency()
2076 double aPrevTransparency = myTransparency;
2077 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2078 myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
2079 myHasTransparency = false;
2080 return aPrevTransparency;
2084 //=================================================================
2086 * GEOM_Displayer::SetTexture
2087 * Set color for shape displaying. If it is equal -1 then default color is used.
2088 * Available values are from Quantity_NameOfColor enumeration
2090 //=================================================================
2091 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2093 if(texureFileName!="")
2095 myTexture = texureFileName;
2099 bool GEOM_Displayer::HasTexture() const
2101 return myTexture != "";
2104 std::string GEOM_Displayer::GetTexture() const
2109 //=================================================================
2111 * GEOM_Displayer::SetWidth
2112 * Set width of shape displaying. If it is equal -1 then default width is used.
2114 //=================================================================
2115 void GEOM_Displayer::SetWidth( const double width )
2120 double GEOM_Displayer::GetWidth() const
2125 bool GEOM_Displayer::HasWidth() const
2127 return myWidth != -1;
2130 void GEOM_Displayer::UnsetWidth()
2136 int GEOM_Displayer::GetIsosWidth() const
2141 void GEOM_Displayer::SetIsosWidth(const int width)
2143 myIsosWidth = width;
2146 bool GEOM_Displayer::HasIsosWidth() const
2148 return myIsosWidth != -1;
2152 //=================================================================
2154 * GEOM_Displayer::SetToActivate
2155 * This method is used for activisation/deactivisation of objects to be displayed
2157 //=================================================================
2158 void GEOM_Displayer::SetToActivate( const bool toActivate )
2160 myToActivate = toActivate;
2162 bool GEOM_Displayer::ToActivate() const
2164 return myToActivate;
2167 //=================================================================
2169 * GEOM_Displayer::clearTemporary
2170 * Removes from selection temporary objects
2172 //=================================================================
2173 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2175 SALOME_ListIO selected, toSelect;
2176 theSelMgr->selectedObjects( selected );
2178 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2179 Handle(SALOME_InteractiveObject) io = it.Value();
2180 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2181 toSelect.Append( it.Value() );
2184 theSelMgr->setSelectedObjects( toSelect, true );
2187 void GEOM_Displayer::SetName( const char* theName )
2192 void GEOM_Displayer::UnsetName()
2197 SalomeApp_Study* GEOM_Displayer::getStudy() const
2199 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2202 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2207 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2212 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2213 const int theFieldDimension,
2214 const QList<QVariant>& theFieldStepData,
2215 const TCollection_AsciiString& theFieldStepName,
2216 const double theFieldStepRangeMin,
2217 const double theFieldStepRangeMax )
2219 myFieldDataType = theFieldDataType;
2220 myFieldDimension = theFieldDimension;
2221 myFieldStepData = theFieldStepData;
2222 myFieldStepName = theFieldStepName;
2223 myFieldStepRangeMin = theFieldStepRangeMin;
2224 myFieldStepRangeMax = theFieldStepRangeMax;
2227 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2229 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2230 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2231 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2232 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2233 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2234 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2237 int GEOM_Displayer::SetDisplayMode( const int theMode )
2239 int aPrevMode = myDisplayMode;
2240 if ( theMode != -1 ) {
2241 myDisplayMode = theMode;
2242 myHasDisplayMode = true;
2250 int GEOM_Displayer::GetDisplayMode() const
2252 return myDisplayMode;
2255 int GEOM_Displayer::UnsetDisplayMode()
2257 int aPrevMode = myDisplayMode;
2258 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2259 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2260 myHasDisplayMode = false;
2264 bool GEOM_Displayer::HasDisplayMode() const
2266 return myHasDisplayMode;
2269 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2271 static QList<QColor> colors;
2273 if ( colors.isEmpty() ) {
2275 for (int s = 0; s < 2 ; s++)
2277 for (int v = 100; v >= 40; v = v - 20)
2279 for (int h = 0; h < 359 ; h = h + 60)
2281 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2287 static int currentColor = 0;
2289 SALOMEDS::Color color;
2290 color.R = (double)colors[currentColor].red() / 255.0;
2291 color.G = (double)colors[currentColor].green() / 255.0;
2292 color.B = (double)colors[currentColor].blue() / 255.0;
2294 currentColor = (currentColor+1) % colors.count();
2299 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2302 int aTolerance = 64;
2303 int anIterations = 0;
2309 if( anIterations % aPeriod == 0 )
2312 if( aTolerance < 1 )
2315 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2317 aHue = (int)( 360.0 * rand() / RAND_MAX );
2318 //std::cout << "Hue = " << aHue << std::endl;
2320 //std::cout << "Auto colors : ";
2322 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2323 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2324 for( ; it != itEnd; ++it )
2326 SALOMEDS::Color anAutoColor = *it;
2327 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2330 aQColor.getHsv( &h, &s, &v );
2331 //std::cout << h << " ";
2332 if( abs( h - aHue ) < aTolerance )
2335 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2339 //std::cout << std::endl;
2345 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2347 aColor.setHsv( aHue, 255, 255 );
2349 SALOMEDS::Color aSColor;
2350 aSColor.R = (double)aColor.red() / 255.0;
2351 aSColor.G = (double)aColor.green() / 255.0;
2352 aSColor.B = (double)aColor.blue() / 255.0;
2357 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2358 const QString& entry,
2361 // get default properties for the explicitly specified default view type
2362 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2364 if ( study && view ) {
2365 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2366 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2367 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2369 if ( viewModel && viewId != -1 ) {
2370 // get properties from the study
2371 PropMap storedMap = study->getObjectPropMap( viewId, entry );
2372 // overwrite default properties from stored ones (that are specified)
2373 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2374 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2375 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2376 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2378 // ... specific processing for color
2379 // ... current implementation is to use same stored color for all aspects
2380 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2381 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2382 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2383 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2384 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2385 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2386 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2389 if ( !entry.isEmpty() ) {
2390 // get CORBA reference to geom object
2391 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2393 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2394 if ( !CORBA::is_nil( object ) ) {
2395 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2396 if ( !CORBA::is_nil( geomObject ) ) { // to check
2397 // check that geom object has color properly set
2398 bool hasColor = false;
2399 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2400 // set color from geometry object (only once, if it is not yet set in GUI)
2401 // current implementation is to use same color for all aspects
2402 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2403 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2404 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2405 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2406 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2407 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2408 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2409 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2411 // check that object has point marker properly set
2412 GEOM::marker_type mType = geomObject->GetMarkerType();
2413 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2414 int mTextureId = geomObject->GetMarkerTexture();
2415 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2416 ( mType == GEOM::MT_USER && mTextureId > 0 );
2417 // set point marker from geometry object (only once, if it is not yet set in GUI)
2418 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2419 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2421 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2422 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2424 else if ( mType == GEOM::MT_USER ) {
2426 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2438 PropMap GEOM_Displayer::getDefaultPropertyMap()
2442 // get resource manager
2443 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2445 // fill in the properties map with default values
2447 // - visibility (false by default)
2448 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2450 // - nb isos (take default value from preferences)
2451 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2452 QString( "%1%2%3" ).
2453 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2454 arg( GEOM::subSectionSeparator() ).
2455 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2457 // - transparency (opacity = 1-transparency)
2458 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2459 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2461 // - display mode (take default value from preferences)
2462 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2463 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2465 // - show edges direction flag (false by default)
2466 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2468 // - show vertices flag (false by default)
2469 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2471 // - shading color (take default value from preferences)
2472 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2473 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2475 // - wireframe color (take default value from preferences)
2476 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2477 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2479 // - standalone edges color (take default value from preferences)
2480 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2481 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2483 // - free boundaries color (take default value from preferences)
2484 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2485 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2487 // - points color (take default value from preferences)
2488 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2489 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2491 // - isos color (take default value from preferences)
2492 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2493 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2495 // - outlines color (take default value from preferences)
2496 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2497 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2499 // - deflection coefficient (take default value from preferences)
2500 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2501 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2503 // - material (take default value from preferences)
2504 Material_Model material;
2505 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2506 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2508 // - edge width (take default value from preferences)
2509 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2510 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2512 // - isos width (take default value from preferences)
2513 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2514 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2516 // - point marker (take default value from preferences)
2517 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2518 QString( "%1%2%3" ).
2519 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2520 arg( GEOM::subSectionSeparator() ).
2521 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2523 // - top-level flag (false by default)
2524 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2529 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2530 SALOMEDS::Color aSColor;
2533 SUIT_Session* session = SUIT_Session::session();
2534 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2536 if ( app && !theGeomObject->_is_nil()) {
2537 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2540 _PTR(Study) aStudy = study->studyDS();
2541 aSColor = theGeomObject->GetColor();
2542 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2544 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2545 bool general_autocolor = true;
2546 #else // auto-color for groups only
2547 bool general_autocolor = false;
2548 #endif // GENERAL_AUTOCOLOR
2549 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2550 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2551 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2552 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2553 aSColor = getPredefinedUniqueColor();
2555 #else // old algorithm for auto-colors
2556 QList<SALOMEDS::Color> aReservedColors;
2557 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2558 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2559 if ( aMainSObject ) {
2560 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2561 for ( ; it->More(); it->Next() ) {
2562 _PTR(SObject) aChildSObject( it->Value() );
2563 GEOM::GEOM_Object_var aChildObject =
2564 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2565 if ( CORBA::is_nil( aChildObject ) )
2568 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2569 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2570 aReservedColors.append( aReservedColor );
2573 aSColor = getUniqueColor( aReservedColors );
2575 #endif // SIMPLE_AUTOCOLOR
2585 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2586 const bool eraseOnlyChildren) {
2587 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2591 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2595 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2600 // Erase from all views
2601 QList<SALOME_View*> views;
2603 ViewManagerList vmans = app->viewManagers();
2604 SUIT_ViewManager* vman;
2605 foreach ( vman, vmans ) {
2606 SUIT_ViewModel* vmod = vman->getViewModel();
2607 view = dynamic_cast<SALOME_View*> ( vmod );
2609 views.append( view );
2612 if( views.count() == 0 )
2615 //Erase childrens w/o update views
2616 DataObjectList listObj = parent->children( true );
2617 SUIT_DataObject* obj;
2618 foreach( obj, listObj ) {
2619 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2621 foreach ( view, views ) {
2622 Handle(SALOME_InteractiveObject) anIO =
2623 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2624 Erase(anIO, false, false, view);
2628 //Erase parent with view update or repaint views
2629 foreach ( view, views ) {
2630 if(!eraseOnlyChildren)
2631 Erase(theIO, false, true, view);
2637 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2639 if( theGeomFieldStep->_is_nil() )
2642 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2643 if( aGeomField->_is_nil() )
2646 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2647 if( aGeomFieldShape->_is_nil() )
2650 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2651 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2652 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2654 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2656 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2658 int aFieldDimension = aGeomField->GetDimension();
2660 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2661 int aFieldNbComponents = aFieldComponents->length();
2663 QList<QVariant> aFieldStepData;
2664 if( aFieldDataType == GEOM::FDT_Bool )
2666 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2667 if ( !aGeomBoolFieldStep->_is_nil() )
2669 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2670 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2671 aFieldStepData << (bool)aValues[i];
2674 else if( aFieldDataType == GEOM::FDT_Int )
2676 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2677 if ( !aGeomIntFieldStep->_is_nil() )
2679 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2680 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2681 aFieldStepData << (qlonglong)aValues[i];
2684 else if( aFieldDataType == GEOM::FDT_Double )
2686 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2687 if ( !aGeomDoubleFieldStep->_is_nil() )
2689 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2690 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2691 aFieldStepData << (double)aValues[i];
2694 else if( aFieldDataType == GEOM::FDT_String )
2696 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2697 if ( !aGeomStringFieldStep->_is_nil() )
2699 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2700 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2701 aFieldStepData << QString( aValues[i] );
2705 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2706 aFieldStepData = groupFieldData( aFieldStepData,
2708 aFieldDataType == GEOM::FDT_String,
2710 aFieldStepRangeMax );
2712 setFieldStepInfo( aFieldDataType,
2717 aFieldStepRangeMax );
2720 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2721 const int theFieldNbComponents,
2722 const bool theIsString,
2723 double& theFieldStepRangeMin,
2724 double& theFieldStepRangeMax )
2726 QList<QVariant> aResultList;
2727 theFieldStepRangeMin = 0;
2728 theFieldStepRangeMax = 0;
2730 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2733 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2735 QList<QVariant> aGroupedList;
2737 bool anIsBoolean = false;
2738 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2741 QStringList aStringList;
2743 int aBaseIndex = aSubShape * theFieldNbComponents;
2744 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2746 int anIndex = aComponent + aBaseIndex;
2748 const QVariant& aVariant = theFieldStepData[ anIndex ];
2751 if( aVariant.type() == QVariant::String )
2752 aStringList << aVariant.toString();
2757 if( aVariant.type() == QVariant::Bool )
2759 aValue = aVariant.toBool() ? 1.0 : 0.0;
2765 if( aVariant.type() == QVariant::LongLong )
2766 aValue = double( aVariant.toLongLong() );
2767 else if( aVariant.type() == QVariant::Double )
2768 aValue = aVariant.toDouble();
2769 aNorm += aValue * aValue;
2775 aGroupedList << aStringList.join( "\n" );
2779 aNorm /= theFieldNbComponents;
2781 aNorm = pow( aNorm, 0.5 );
2783 if( aGroupedList.isEmpty() )
2784 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2787 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2788 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2791 aGroupedList << aNorm;
2797 theFieldStepRangeMin = 0.0;
2798 theFieldStepRangeMax = 1.0;
2801 SUIT_Session* session = SUIT_Session::session();
2802 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2803 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2805 QListIterator<QVariant> anIter( aGroupedList );
2806 while( anIter.hasNext() )
2808 const QVariant& aVariant = anIter.next();
2810 aResultList << aVariant;
2814 Quantity_Color aColor;
2815 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2816 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2817 aResultList << aQColor;
2823 // Note: the method is copied from Aspect_ColorScale class
2824 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2825 const Standard_Integer aMin,
2826 const Standard_Integer aMax )
2828 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2830 Standard_Integer aHue = maxLimit;
2832 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2834 aHue = Min( Max( minLimit, aHue ), maxLimit );
2839 // Note: the method is copied from Aspect_ColorScale class
2840 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2841 const Standard_Real aMin,
2842 const Standard_Real aMax,
2843 const Standard_Integer ColorsCount,
2844 Quantity_Color& aColor )
2846 if( aValue<aMin || aValue>aMax || aMax<aMin )
2847 return Standard_False;
2851 Standard_Real IntervNumber = 0;
2854 else if( aValue>aMax )
2855 IntervNumber = ColorsCount-1;
2856 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2857 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2859 Standard_Integer Interv = Standard_Integer( IntervNumber );
2861 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2863 return Standard_True;
2867 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2869 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2873 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2877 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2878 if( aViewer.IsNull() )
2881 aViewer->InitActiveViews();
2882 if( !aViewer->MoreActiveViews() )
2885 Handle(V3d_View) aView = aViewer->ActiveView();
2886 if( aView.IsNull() )
2889 Standard_Boolean anIsDisplayColorScale = Standard_False;
2890 TCollection_AsciiString aColorScaleTitle;
2891 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2892 Standard_Boolean anIsBoolean = Standard_False;
2894 SALOME_ListIO aSelectedObjects;
2895 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2896 if( aSelectedObjects.Extent() == 1 )
2898 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2899 if( !anIO.IsNull() )
2901 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2904 AIS_ListOfInteractive aList;
2905 aPrs->GetObjects( aList );
2906 AIS_ListIteratorOfListOfInteractive anIter( aList );
2907 for( ; anIter.More(); anIter.Next() )
2909 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2910 if( !aShape.IsNull() )
2912 GEOM::field_data_type aFieldDataType;
2913 int aFieldDimension;
2914 QList<QVariant> aFieldStepData;
2915 TCollection_AsciiString aFieldStepName;
2916 double aFieldStepRangeMin, aFieldStepRangeMax;
2917 aShape->getFieldStepInfo( aFieldDataType,
2922 aFieldStepRangeMax );
2923 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2925 anIsDisplayColorScale = Standard_True;
2926 aColorScaleTitle = aFieldStepName;
2927 aColorScaleMin = aFieldStepRangeMin;
2928 aColorScaleMax = aFieldStepRangeMax;
2929 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2937 if( anIsDisplayColorScale )
2939 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2940 if( !aColorScale.IsNull() )
2942 SUIT_Session* session = SUIT_Session::session();
2943 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2945 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2946 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2947 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2948 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2949 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2950 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2952 aColorScale->SetXPosition( anXPos );
2953 aColorScale->SetYPosition( anYPos );
2954 aColorScale->SetWidth( aWidth );
2955 aColorScale->SetHeight( aHeight );
2957 aColorScale->SetTextHeight( aTextHeight );
2958 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2960 aColorScale->SetTitle( aColorScaleTitle );
2961 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2963 if( !aView->ColorScaleIsDisplayed() )
2964 aView->ColorScaleDisplay();
2968 if( aView->ColorScaleIsDisplayed() )
2969 aView->ColorScaleErase();
2972 if( theIsRedisplayFieldSteps )
2974 _PTR(Study) aStudyDS = aStudy->studyDS();
2975 QList<SUIT_ViewManager*> vmList;
2976 myApp->viewManagers( vmList );
2977 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2979 if( SUIT_ViewManager* aViewManager = *vmIt )
2981 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2982 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2984 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2987 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2988 if( !CORBA::is_nil( anObject ) )
2990 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2991 if( !aFieldStep->_is_nil() )
2993 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2994 Handle(SALOME_InteractiveObject) aStepIO =
2995 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2996 Redisplay( aStepIO, false, false );