1 // Copyright (C) 2007-2021 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 "GeometryGUI.h"
30 #include <GEOM_Constants.h>
31 #include <GEOM_TypeFilter.h>
32 #include <GEOM_EdgeFilter.h>
33 #include <GEOM_FaceFilter.h>
34 #include <GEOM_CompoundFilter.h>
35 #include <GEOM_PreviewFilter.h>
36 #include <GEOM_LogicalFilter.h>
37 #include <GEOM_OCCFilter.h>
39 #include <GEOM_Actor.h>
40 #include <GEOM_AISDimension.hxx>
41 #include <GEOM_Annotation.hxx>
42 #include <GEOM_TopWireframeShape.hxx>
43 #include <GEOM_AISVector.hxx>
44 #include <GEOM_AISTrihedron.hxx>
45 #include <GEOM_VTKTrihedron.hxx>
46 #include <GEOM_VTKPropertyMaterial.hxx>
48 #include <GEOMGUI_DimensionProperty.h>
49 #include <GEOMGUI_AnnotationAttrs.h>
50 #include <GEOMGUI_AnnotationMgr.h>
52 #include <GEOMUtils.hxx>
54 #include <Material_Model.h>
56 #include <SUIT_Desktop.h>
57 #include <SUIT_ViewWindow.h>
58 #include <SUIT_Session.h>
59 #include <SUIT_ViewManager.h>
60 #include <SUIT_ResourceMgr.h>
62 #include <SalomeApp_Study.h>
63 #include <SalomeApp_Application.h>
64 #include <LightApp_SelectionMgr.h>
65 #include <LightApp_DataObject.h>
66 #include <SalomeApp_TypeFilter.h>
67 #include <SalomeApp_Tools.h>
68 #include "utilities.h"
70 #include <SALOME_ListIO.hxx>
71 #include <SALOME_Prs.h>
72 #include "utilities.h"
75 #include <SOCC_ViewModel.h>
78 #include <SVTK_ViewModel.h>
80 #include <OCCViewer_ViewWindow.h>
81 #include <OCCViewer_ViewPort3d.h>
82 #include <OCCViewer_Utilities.h>
85 #include <AIS_Dimension.hxx>
86 #include <AIS_LengthDimension.hxx>
87 #include <AIS_DiameterDimension.hxx>
88 #include <AIS_AngleDimension.hxx>
89 #include <AIS_ListIteratorOfListOfInteractive.hxx>
90 #include <Aspect_PolygonOffsetMode.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_MapIteratorOfMapOfInteger.hxx>
103 #include <TopoDS_Iterator.hxx>
104 #include <Graphic3d_AspectMarker3d.hxx>
105 #include <TopTools_MapOfShape.hxx>
106 #include <TopTools_ListOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopoDS.hxx>
109 #include <NCollection_DataMap.hxx>
110 #include <NCollection_Map.hxx>
111 #include <Graphic3d_Texture2Dmanual.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
121 #include <Basics_OCCTVersion.hxx>
123 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
125 #include <GEOMImpl_Types.hxx>
127 #include <TColStd_HArray1OfByte.hxx>
129 #if OCC_VERSION_LARGE >= 0x070400ff
130 #include <Image_SupportedFormats.hxx>
133 // If the next macro is defined, autocolor feature works for all sub-shapes;
134 // if it is undefined, autocolor feature works for groups only
135 #define GENERAL_AUTOCOLOR
136 // Below macro, when uncommented, switches on simplified (more performant) algorithm
137 // of auto-color picking up
138 #define SIMPLE_AUTOCOLOR
140 // Hard-coded value of shape deflection coefficient for VTK viewer
141 const double VTK_MIN_DEFLECTION = 0.001;
142 // If the next macro is defined, the deflection coefficient for VTK presentation
143 // is limited by VTK_MIN_DEFLECTION
144 //#define LIMIT_DEFLECTION_FOR_VTK
146 // Pixmap caching support
149 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
150 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
151 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
153 static inline PixmapUsageMap& getPixmapUsageMap()
155 static PixmapUsageMap aMap;
159 static inline PixmapCacheMap& getPixmapCacheMap()
161 static PixmapCacheMap aMap;
165 //===========================================================================
166 // Function : getDefaultTexture
167 // Purpose : Get default texture
168 //===========================================================================
169 static inline Handle(Image_PixMap) getDefaultTexture()
171 static Handle(Image_PixMap) aPixmap;
172 if ( aPixmap.IsNull() ) {
173 QPixmap px(":images/default_texture.png");
175 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
180 //===========================================================================
181 // Function : cacheTextureFor
182 // Purpose : Load and cache image for the specified presentation.
183 //===========================================================================
184 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
185 const Handle(GEOM_AISShape)& theShape )
187 if ( thePath.isEmpty() )
190 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
191 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
193 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
194 if ( !aPixmap.IsNull() ) {
195 // point that the texture is used by the presentation
196 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
197 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
199 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
204 // convert texture to compatible image format
205 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
206 if ( anImage.isNull() )
209 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
211 aPixmapCacheMap.insert( thePath, aPixmap );
213 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
214 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
216 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
221 //===========================================================================
222 // Function : releaseTextures
223 // Purpose : Releases cached textures found for the specified presentation.
224 //===========================================================================
225 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
227 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
229 AIS_ListOfInteractive aListOfIO;
231 anOccPrs->GetObjects( aListOfIO );
233 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
235 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
236 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
238 for ( ; aIterateIO.More(); aIterateIO.Next() )
240 Handle(GEOM_AISShape) aAISShape =
241 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
243 if ( aAISShape.IsNull() )
246 const Handle(Graphic3d_TextureMap)& aTexture = aAISShape->Attributes()->ShadingAspect()->Aspect()->TextureMap();
247 if ( aTexture.IsNull() )
249 #if OCC_VERSION_LARGE >= 0x070400ff
250 Handle(Image_SupportedFormats) aFormats = new Image_SupportedFormats();
251 const Handle(Image_PixMap)& aPixmap = aTexture->GetImage(aFormats);
253 const Handle(Image_PixMap)& aPixmap = aTexture->GetImage();
255 if ( aPixmap.IsNull() )
258 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
261 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
263 aUsersShapes.Remove( aAISShape );
265 if ( aUsersShapes.IsEmpty() ) {
266 aPixmapUsersMap.UnBind( aPixmap );
267 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
272 uint randomize( uint size )
274 static bool initialized = false;
275 if ( !initialized ) {
276 qsrand( QDateTime::currentDateTime().toTime_t() );
280 v = uint( (double)( v ) / RAND_MAX * size );
281 v = qMax( uint(0), qMin ( v, size-1 ) );
286 //================================================================
287 // Function : getActiveStudy
288 // Purpose : Get active study, returns 0 if no open study frame
289 //================================================================
290 static inline SalomeApp_Study* getActiveStudy()
292 SUIT_Session* session = SUIT_Session::session();
293 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
295 return ( SalomeApp_Study* )app->activeStudy();
299 static inline int getViewManagerId( SALOME_View* theViewFrame) {
300 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
301 SUIT_ViewManager* aViewMgr = 0;
303 aViewMgr = aModel->getViewManager();
304 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
307 //================================================================
308 // Function : getTopAbsMode
309 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
310 // one from GEOMImpl_Types.h
311 //================================================================
312 static inline int getTopAbsMode( const int implType )
316 case GEOM_COMPOUND : return TopAbs_COMPOUND;
317 case GEOM_SOLID : return TopAbs_SOLID;
318 case GEOM_SHELL : return TopAbs_SHELL;
319 case GEOM_FACE : return TopAbs_FACE;
320 case GEOM_WIRE : return TopAbs_WIRE;
321 case GEOM_EDGE : return TopAbs_EDGE;
322 case GEOM_POINT : return TopAbs_VERTEX;
327 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
329 if ( shape.IsNull() )
332 int ret = shape.ShapeType();
334 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
335 TopoDS_Iterator it(shape, Standard_True, Standard_False);
336 for (; it.More(); it.Next()) {
337 TopoDS_Shape sub_shape = it.Value();
338 if ( sub_shape.IsNull() ) continue;
339 int stype = getMinMaxShapeType( sub_shape, ismin );
340 if ( stype == TopAbs_SHAPE ) continue;
341 if ( ismin && stype > ret )
343 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
351 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
353 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
356 //================================================================
357 // Function : getFilter
358 // Purpose : Get filter corresponding to the type of object
359 // from GEOMImpl_Types.h
360 //================================================================
361 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
363 SUIT_SelectionFilter* aFilter;
365 int aTopAbsMode = getTopAbsMode( theMode );
366 if ( aTopAbsMode != -1 )
367 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
371 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
372 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
374 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
375 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
376 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
377 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
378 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
379 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
381 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
383 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
384 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
386 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
392 //================================================================
393 // Function : getComplexFilter
394 // Purpose : Get compound filter corresponding to the type of
395 // object from GEOMImpl_Types.h
396 //================================================================
397 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
399 GEOM_CompoundFilter* aFilter = 0;
401 if(aSubShapes != NULL ) {
402 aFilter = new GEOM_CompoundFilter(getStudy());
403 QList<int> aTopAbsTypes;
404 QList<int>::const_iterator it;
405 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
406 int topAbsMode = getTopAbsMode(*it);
407 if(topAbsMode != -1 )
408 aTopAbsTypes.append(topAbsMode);
410 aFilter->addSubTypes(aTopAbsTypes);
416 //================================================================
417 // Function : getEntry
419 //================================================================
420 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
422 SUIT_Session* session = SUIT_Session::session();
423 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
426 CORBA::String_var IOR = app->orb()->object_to_string( object );
427 if ( strcmp(IOR.in(), "") != 0 )
429 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
430 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
438 //================================================================
439 // Function : getName
441 //================================================================
442 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
444 SUIT_Session* session = SUIT_Session::session();
445 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
448 CORBA::String_var IOR = app->orb()->object_to_string( object );
449 if ( strcmp(IOR.in(), "") != 0 )
451 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
452 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
454 _PTR(GenericAttribute) anAttr;
456 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
458 _PTR(AttributeName) aNameAttr( anAttr );
459 return aNameAttr->Value();
467 //=================================================================
469 * GEOM_Displayer::GEOM_Displayer
472 //=================================================================
473 GEOM_Displayer::GEOM_Displayer()
474 : myUpdateColorScale(true), myIsRedisplayed( false )
476 SUIT_Session* session = SUIT_Session::session();
477 myApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
480 SUIT_ResourceMgr* resMgr = session->resourceMgr();
482 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
483 myShadingColor = SalomeApp_Tools::color( col );
485 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
486 myHasDisplayMode = false;
488 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
490 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
491 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
492 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
494 // Next properties provide a way to customize displaying of presentations;
495 // for instance, this is useful for preview
505 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
508 // Activate parallel vizualisation by default.
509 // It can be switched OFF via the environment variable:
510 // export PARALLEL_VISU=0
511 Standard_Boolean parallel_visu = Standard_True;
512 char* parallel_visu_env = getenv("PARALLEL_VISU");
513 if (parallel_visu_env && atoi(parallel_visu_env) == 0)
514 parallel_visu = Standard_False;
515 BRepMesh_IncrementalMesh::SetParallelDefault(parallel_visu);
519 myFieldDataType = GEOM::FDT_Double;
520 myFieldDimension = 0;
521 myFieldStepRangeMin = 0;
522 myFieldStepRangeMax = 0;
525 //=================================================================
527 * GEOM_Displayer::~GEOM_Displayer
530 //=================================================================
531 GEOM_Displayer::~GEOM_Displayer()
535 //=================================================================
537 * GEOM_Displayer::Display
538 * Display interactive object in the current viewer
540 //=================================================================
541 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
542 const bool updateViewer,
543 SALOME_View* theViewFrame )
545 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
548 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
552 vf->BeforeDisplay( this, prs );
553 vf->Display( this, prs );
554 vf->AfterDisplay( this, prs );
559 delete prs; // delete presentation because displayer is its owner
564 //=================================================================
566 * GEOM_Displayer::Display
567 * This overloaded Display() method can be useful for operations
568 * not using dialog boxes.
570 //=================================================================
571 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
573 if ( theObj->_is_nil() )
576 std::string entry = getEntry( theObj );
578 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
583 //=================================================================
585 * GEOM_Displayer::Erase
586 * Erase interactive object in the current viewer
588 //=================================================================
589 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
591 const bool updateViewer,
592 SALOME_View* theViewFrame )
594 if ( theIO.IsNull() )
597 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
600 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
602 vf->BeforeErase( this, prs );
603 vf->Erase( this, prs, forced );
604 vf->AfterErase( this, prs );
607 delete prs; // delete presentation because displayer is its owner
612 //=================================================================
614 * GEOM_Displayer::Erase
615 * Erase geometry object in the current viewer
617 //=================================================================
618 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
620 const bool updateViewer,
621 SALOME_View* theViewFrame)
623 std::string entry = getEntry( theObj );
626 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
627 forced, updateViewer, theViewFrame);
631 //=================================================================
633 * GEOM_Displayer::Redisplay
634 * Redisplay (erase and then display again) interactive object
635 * in the current viewer
637 //=================================================================
638 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
639 const bool updateViewer,
640 const bool checkActiveViewer )
642 bool aRedisplayed = myIsRedisplayed;
643 myIsRedisplayed = true;
644 // Remove the object permanently (<forced> == true)
645 SUIT_Session* ses = SUIT_Session::session();
646 SUIT_Application* app = ses->activeApplication();
649 SUIT_Desktop* desk = app->desktop();
650 QList<SUIT_ViewWindow*> wnds = desk->windows();
651 SUIT_ViewWindow* wnd;
652 QListIterator<SUIT_ViewWindow*> it( wnds );
653 while ( it.hasNext() && (wnd = it.next()) )
655 SUIT_ViewManager* vman = wnd->getViewManager();
658 SUIT_ViewModel* vmodel = vman->getViewModel();
661 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
664 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
666 Redisplay( theIO, updateViewer, view );
673 myIsRedisplayed = aRedisplayed;
676 //=================================================================
678 * GEOM_Displayer::Redisplay
679 * Redisplay (erase and then display again) interactive object
680 * in the specified view
682 //=================================================================
683 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
684 const bool theUpdateViewer,
685 SALOME_View* theViewFrame )
687 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
693 bool aRedisplayed = myIsRedisplayed;
694 myIsRedisplayed = true;
695 Erase( theIO, true, false, theViewFrame );
696 Display( theIO, theUpdateViewer, theViewFrame );
697 myIsRedisplayed = aRedisplayed;
698 // hide annotations for erased presentation
699 SUIT_Session* session = SUIT_Session::session();
700 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
701 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
703 if ( !theViewFrame->isVisible( theIO ) ) {
704 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
707 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
712 //=================================================================
714 * GEOM_Displayer::Display
715 * Calls Display() method for each object in the given list
717 //=================================================================
718 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
720 SALOME_ListIteratorOfListIO Iter( theIOList );
721 for ( ; Iter.More(); Iter.Next() ) {
722 Display( Iter.Value(), false );
728 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
730 SalomeApp_Study* aStudy = getStudy();
732 if ( v ) vId = getViewManagerId( v );
735 QString entry = p->GetEntry();
736 if ( !entry.isEmpty() ) {
738 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
739 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
744 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
749 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
751 // VSR: this method can be improved in future:
752 // to improve performance, the default values from resource manager should be cached in the displayer
753 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
756 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
758 // VSR: this method can be improved in future:
759 // to improve performance, the default values from resource manager should be cached in the displayer
760 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
763 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
765 // check that shape is not null
766 if ( AISShape.IsNull() ) return;
768 // check that study is active
769 SalomeApp_Study* study = getStudy();
770 if ( !study ) return;
772 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
773 !TopoDS_Iterator(myShape).More() )
774 return; // NPAL15983 (Bug when displaying empty groups)
776 // set interactive object
778 Handle( SALOME_InteractiveObject ) anIO;
780 if ( !myIO.IsNull() ) {
781 AISShape->setIO( myIO );
782 AISShape->SetOwner( myIO );
785 else if ( !myName.empty() ) {
786 // workaround to allow selection of temporary objects
787 static int tempId = 0;
788 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toUtf8().data(), "GEOM", myName.c_str() );
789 AISShape->setIO( anIO );
790 AISShape->SetOwner( anIO );
793 // flag: only vertex or compound of vertices is processed (specific handling)
794 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
795 // presentation study entry (empty for temporary objects like preview)
796 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
797 // flag: temporary object
798 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
799 // currently active view window's ID (-1 if no active view)
800 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
802 // get presentation properties
803 PropMap propMap = getObjectProperties( entry, myViewFrame );
805 // Temporary staff: vertex must be infinite for correct visualization
806 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
809 Material_Model material;
810 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
812 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
813 // - set front material properties
814 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
815 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
816 // - set back material properties
817 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
818 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
819 // - switch to default (both sides) facing mode
820 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
826 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
827 // we set it to the shape not taking into account material properties
828 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
830 else if ( !material.isPhysical() ) {
831 // shading color from properties is used only for non-physical materials
832 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
836 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
837 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
838 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
839 AISShape->Attributes()->SetLineAspect( anAspect );
841 // - unfree boundaries color
842 Handle(Prs3d_LineAspect) aUnFreeBoundaryAspect =
843 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
844 *aUnFreeBoundaryAspect->Aspect() = *AISShape->Attributes()->UnFreeBoundaryAspect()->Aspect();
845 aUnFreeBoundaryAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
846 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
847 AISShape->Attributes()->SetUnFreeBoundaryAspect( aUnFreeBoundaryAspect );
849 // - free boundaries color
850 Handle(Prs3d_LineAspect) aFreeBoundaryAspect =
851 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
852 *aFreeBoundaryAspect->Aspect() = *AISShape->Attributes()->FreeBoundaryAspect()->Aspect();
853 aFreeBoundaryAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
854 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
855 AISShape->Attributes()->SetFreeBoundaryAspect( aFreeBoundaryAspect );
857 // - standalone edges color
858 anAspect = AISShape->Attributes()->WireAspect();
859 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
860 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
861 AISShape->Attributes()->SetWireAspect( anAspect );
863 // - color for edges in shading+edges mode
864 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
866 // - color of labels (textual fields and shape name)
867 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
870 int displayMode = HasDisplayMode() ?
871 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
873 // display mode from properties
874 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
875 AISShape->SetDisplayMode( displayMode );
877 // - face boundaries color and line width
878 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
879 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
880 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
881 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
883 // set display vectors flag
884 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
886 // set display vertices flag
887 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
888 AISShape->SetDisplayVertices( isVerticesMode );
890 // set display name flag
891 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
892 AISShape->SetDisplayName( isNameMode );
895 if( HasTransparency() ) {
896 AISShape->SetTransparency( GetTransparency() );
898 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
901 // set iso properties
902 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
903 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
904 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
905 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
906 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
907 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
909 if ( HasIsosColor() ) {
910 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
911 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
914 uIsoAspect->SetColor( isosColor );
915 vIsoAspect->SetColor( isosColor );
918 if ( HasIsosWidth() ) {
919 uIsoAspect->SetWidth( GetIsosWidth() );
920 vIsoAspect->SetWidth( GetIsosWidth() );
923 uIsoAspect->SetWidth( isosWidth );
924 vIsoAspect->SetWidth( isosWidth );
928 uIsoAspect->SetNumber( GetNbIsos() );
929 vIsoAspect->SetNumber( GetNbIsos() );
932 uIsoAspect->SetNumber( uIsos );
933 vIsoAspect->SetNumber( vIsos );
936 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
937 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
939 // set deflection coefficient
940 // ... to avoid to small values of the coefficient, its lower value is limited
941 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
945 if ( HasTexture() ) {
946 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
947 aImagePath = GetTexture().c_str();
948 if ( ! entry.isEmpty() ) {
949 // check that study is active
950 SalomeApp_Study* study = getStudy();
952 // Store the texture in object properties for next displays
953 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
954 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
956 // Update properties map
957 propMap = getObjectProperties( entry, myViewFrame );
962 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
965 Handle(Image_PixMap) aPixmap;
966 if ( !aImagePath.isEmpty() )
967 aPixmap = cacheTextureFor( aImagePath, AISShape );
969 aPixmap = getDefaultTexture();
971 // apply image to shape
972 if ( !aPixmap.IsNull() ) {
973 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) );
975 if ( displayMode == GEOM_AISShape::TexturedShape )
976 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
978 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
981 AISShape->SetWidth( HasWidth() ?
982 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
984 // libe width from properties
985 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
987 // set top-level flag
988 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
990 // set point marker (for vertex / compound of vertices only)
991 if ( onlyVertex || isVerticesMode ) {
992 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
993 if ( aList.size() == 2 ) {
994 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
995 int aTypeOfMarker = aList[0].toInt();
996 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
997 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
998 anAspect->SetScale( aScaleOfMarker );
999 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
1000 anAspect->SetColor( HasColor() ?
1001 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1002 (Quantity_NameOfColor)GetColor() :
1003 // color from properties
1004 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
1005 AISShape->Attributes()->SetPointAspect( anAspect );
1007 else if ( aList.size() == 1 ) {
1008 // custom marker string contains "IdOfTexture"
1009 int textureId = aList[0].toInt();
1010 Standard_Integer aWidth, aHeight;
1011 Handle(TColStd_HArray1OfByte) aTexture =
1012 GeometryGUI::getTexture( textureId, aWidth, aHeight );
1013 if ( !aTexture.IsNull() ) {
1014 Handle(Prs3d_PointAspect) aTextureAspect =
1015 new Prs3d_PointAspect( HasColor() ?
1016 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1017 (Quantity_NameOfColor)GetColor() :
1018 // color from properties
1019 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1022 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1027 // set field step data
1028 AISShape->setFieldStepInfo( myFieldDataType,
1032 myFieldStepRangeMin,
1033 myFieldStepRangeMax );
1035 if ( create && !isTemporary && aMgrId != -1 ) {
1036 // set properties to the study
1037 study->setObjectProperties( aMgrId, entry, propMap );
1040 // AISShape->SetName(???); ??? necessary to set name ???
1043 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1045 // check that actor is not null
1046 if ( !actor ) return;
1048 // check that study is active
1049 SalomeApp_Study* study = getStudy();
1050 if ( !study ) return;
1052 // set interactive object
1054 Handle( SALOME_InteractiveObject ) anIO;
1056 if ( !myIO.IsNull() ) {
1057 actor->setIO( myIO );
1060 else if ( !myName.empty() ) {
1061 // workaround to allow selection of temporary objects
1062 static int tempId = 0;
1063 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toUtf8().data(), "GEOM", myName.c_str() );
1064 actor->setIO( anIO );
1067 // presentation study entry (empty for temporary objects like preview)
1068 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1069 // flag: temporary object
1070 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1071 // currently active view window's ID (-1 if no active view)
1072 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1074 // get presentation properties
1075 PropMap propMap = getObjectProperties( entry, myViewFrame );
1078 /////////////////////////////////////////////////////////////////////////
1079 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1080 // due to performance problem
1081 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1082 /////////////////////////////////////////////////////////////////////////
1083 if ( !actor->getTopo().IsSame( myShape ) )
1084 #ifdef LIMIT_DEFLECTION_FOR_VTK
1085 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1087 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1091 Material_Model material;
1092 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1093 std::vector<vtkProperty*> mprops;
1094 mprops.push_back( material.getMaterialVTKProperty( true ) );
1095 mprops.push_back( material.getMaterialVTKProperty( false) );
1096 actor->SetMaterial( mprops );
1098 // set iso-lines properties
1100 // - set number of iso-lines
1101 int nbIsos[2]= { 1, 1 };
1102 if ( HasNbIsos() ) {
1103 nbIsos[0] = GetNbIsos();
1104 nbIsos[1] = GetNbIsos();
1107 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1108 nbIsos[0] = isos[0].toInt();
1109 nbIsos[1] = isos[1].toInt();
1111 actor->SetNbIsos( nbIsos );
1113 // - set iso-lines width
1114 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1116 // - set iso-lines color
1117 if ( HasIsosColor() )
1118 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1120 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1121 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1126 // - same color for all sub-actors
1127 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1128 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1131 // shading color (for non-physical materials)
1132 if ( !material.isPhysical() ) {
1133 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1134 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1135 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1138 // - standalone edge color
1139 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1140 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1142 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1143 // - shared edges color ???
1144 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1146 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1147 // - free edges color ???
1148 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1151 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1152 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1155 // - color for edges in shading+edges mode
1156 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1157 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1159 // - color of labels (shape name)
1160 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1161 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1164 if( HasTransparency() ) {
1165 actor->SetOpacity( 1.0 - GetTransparency() );
1167 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1171 actor->SetWidth( HasWidth() ?
1172 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1174 // libe width from properties
1175 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1177 // set display vectors flag
1178 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1180 // set display vertices flag
1181 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1183 // set display name flag
1184 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1187 int displayMode = HasDisplayMode() ?
1188 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1190 // display mode from properties
1191 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1193 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1194 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1195 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1196 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1198 if ( displayMode == 2 )
1199 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1200 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1202 actor->setDisplayMode( displayMode );
1205 actor->PickableOn();
1207 actor->PickableOff();
1209 if ( create && !isTemporary && aMgrId != -1 ) {
1210 // set properties to the study
1211 study->setObjectProperties( aMgrId, entry, propMap );
1215 //=================================================================
1217 * GEOM_Displayer::updateDimensions
1218 * Creates or renews dimension presentation for the IO.
1220 //=================================================================
1221 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1222 SALOME_OCCPrs* thePrs,
1223 const gp_Ax3& theShapeLCS )
1225 SalomeApp_Study* aStudy = getStudy();
1231 if ( theIO.IsNull() )
1236 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1238 AIS_ListOfInteractive aListOfIO;
1240 anOccPrs->GetObjects( aListOfIO );
1242 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1244 // remove outdated presentations of dimensions
1245 for ( ; aIterateIO.More(); aIterateIO.Next() )
1247 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1248 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1253 aListOfIO.Remove( aIterateIO );
1255 if ( !aIterateIO.More() )
1261 // prepare dimension styling
1262 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1264 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1265 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1266 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1267 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1268 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1269 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1270 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1271 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1273 // restore dimension presentation from saved attribute or property data
1274 AIS_ListOfInteractive aRestoredDimensions;
1276 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1278 GEOM::propertyName( GEOM::Dimensions ),
1281 GEOMGUI_DimensionProperty aRecords;
1283 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1285 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1289 aRecords.LoadFromAttribute( theIO->getEntry() );
1292 // create up-to-date dimension presentations
1293 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1295 if ( !aRecords.IsVisible( aPrsIt ) )
1300 // init dimension by type
1301 Handle(AIS_Dimension) aPrs;
1302 switch( aRecords.GetType( aPrsIt ) )
1304 case GEOMGUI_DimensionProperty::DimensionType_Length :
1306 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1307 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1312 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1314 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1315 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1320 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1322 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1323 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1329 aPrs->SetOwner( theIO );
1331 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1333 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1335 aStyle->SetCommonColor( aColor );
1336 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1337 aStyle->MakeText3d( aUseText3d );
1338 aStyle->MakeTextShaded( Standard_True );
1339 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1340 aStyle->SetExtensionSize( fsize * 0.5 );
1341 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1342 aStyle->TextAspect()->SetHeight( fsize );
1343 aStyle->ArrowAspect()->SetLength( anArrowLength );
1344 aStyle->LineAspect()->SetWidth( aLineWidth );
1345 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1346 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1347 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1348 aPrs->SetDimensionAspect( aStyle );
1349 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1350 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1351 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1353 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1355 // show degree symbol for dimension instead of label "deg"
1356 if ( aUnitsAngle == "deg" )
1358 aPrs->SetSpecialSymbol(0xB0);
1359 #if OCC_VERSION_LARGE >= 0x070400ff
1360 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? PrsDim_DisplaySpecialSymbol_After :
1361 PrsDim_DisplaySpecialSymbol_No );
1363 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1365 aStyle->MakeUnitsDisplayed(Standard_False);
1369 #if OCC_VERSION_LARGE >= 0x070400ff
1370 aPrs->SetDisplaySpecialSymbol(PrsDim_DisplaySpecialSymbol_No);
1372 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1374 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1379 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1382 aListOfIO.Append( aPrs );
1385 // update presentation
1388 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1390 anOccPrs->AddObject( aIterateIO.Value() );
1394 //=================================================================
1396 * GEOM_Displayer::Erase
1397 * Calls Erase() method for each object in the given list
1399 //=================================================================
1400 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1402 const bool updateViewer )
1404 SALOME_ListIteratorOfListIO Iter( theIOList );
1405 for ( ; Iter.More(); Iter.Next() )
1406 Erase( Iter.Value(), forced, false );
1412 //=================================================================
1414 * GEOM_Displayer::Redisplay
1415 * Calls Redisplay() method for each object in the given list
1417 //=================================================================
1418 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1419 const bool updateViewer,
1420 const bool checkActiveViewer )
1422 SALOME_ListIteratorOfListIO Iter( theIOList );
1423 for ( ; Iter.More(); Iter.Next() )
1424 Redisplay( Iter.Value(), false, checkActiveViewer );
1430 //=================================================================
1432 * GEOM_Displayer::Redisplay
1433 * Calls Redisplay() method for each object in the given list
1435 //=================================================================
1436 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1437 const bool theUpdateViewer,
1438 SALOME_View* theViewFrame )
1440 SALOME_ListIteratorOfListIO anIter( theIOList );
1441 for ( ; anIter.More(); anIter.Next() )
1443 Redisplay( anIter.Value(), false, theViewFrame );
1446 if ( theUpdateViewer )
1452 //=================================================================
1454 * GEOM_Displayer::Update
1455 * Update OCC presentation
1456 * [ Reimplemented from SALOME_Displayer ]
1458 //=================================================================
1459 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1461 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1462 SalomeApp_Study* study = getStudy();
1464 if ( !occPrs || myShape.IsNull() || !study )
1467 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1470 // specific processing for local coordinate system presentation
1473 TopoDS_Face aFace = TopoDS::Face( myShape );
1474 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1475 if ( !aPlane.IsNull() )
1477 gp_Ax3 aPos = aPlane->Pln().Position();
1478 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1480 Handle(GEOM_AISTrihedron) aTrh;
1482 if ( occPrs->IsNull() )
1484 // new presentation is being created
1485 aTrh = new GEOM_AISTrihedron( aPlc );
1486 occPrs->AddObject( aTrh );
1490 // presentation is being updated
1491 AIS_ListOfInteractive aList;
1492 occPrs->GetObjects( aList );
1493 AIS_ListIteratorOfListOfInteractive anIter( aList );
1494 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1495 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1499 if ( !aTrh.IsNull() ) {
1500 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1502 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1503 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1505 aTrh->SetWidth( GetWidth() );
1507 if ( !myIO.IsNull() )
1509 aTrh->setIO( myIO );
1510 aTrh->SetOwner( myIO );
1512 aTrh->SetComponent( aPlc );
1513 aTrh->SetToUpdate();
1515 occPrs->SetToActivate( ToActivate() );
1521 // processing for usual geometry presentation
1524 // if presentation is empty we try to create new one
1525 if ( occPrs->IsNull() )
1527 // create presentation (specific for vectors)
1528 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1529 : new GEOM_AISShape ( myShape, "" );
1531 if( myType == GEOM_FIELD_STEP )
1532 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1533 // update shape properties
1534 updateShapeProperties( AISShape, true );
1536 // add shape to the presentation
1537 occPrs->AddObject( AISShape );
1539 // In accordance with ToActivate() value object will be activated/deactivated
1540 // when it will be displayed
1541 occPrs->SetToActivate( ToActivate() );
1543 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1544 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1546 // create additional wireframe shape
1547 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1548 aWirePrs->SetWidth(AISShape->Width());
1549 if ( !myIO.IsNull() ) {
1550 aWirePrs->setIO( myIO );
1551 aWirePrs->SetOwner( myIO );
1554 // add shape to the presentation
1555 occPrs->AddObject( aWirePrs );
1558 // if presentation is found -> set again shape for it
1561 AIS_ListOfInteractive IOList;
1562 occPrs->GetObjects( IOList );
1563 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1564 for ( ; Iter.More(); Iter.Next() )
1566 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1567 if ( AISShape.IsNull() )
1570 // re-set shape (it might be changed)
1571 if ( AISShape->Shape() != myShape )
1572 AISShape->Set( myShape );
1574 // update shape properties
1575 updateShapeProperties( AISShape, false );
1578 AISShape->UpdateSelection();
1579 AISShape->SetToUpdate();
1583 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1587 //=================================================================
1589 * GEOM_Displayer::Update
1590 * Update VTK presentation
1591 * [ Reimplemented from SALOME_Displayer ]
1593 //=================================================================
1594 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1596 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1597 SalomeApp_Study* study = getStudy();
1599 if ( !vtkPrs || myShape.IsNull() || !study )
1602 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1605 // specific processing for local coordinate system presentation
1608 TopoDS_Face aFace = TopoDS::Face( myShape );
1609 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1610 if ( !aPlane.IsNull() ) {
1611 gp_Ax3 aPos = aPlane->Pln().Position();
1612 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1614 GEOM_VTKTrihedron* aTrh = 0;
1616 if ( vtkPrs->IsNull() ) {
1617 // new presentation is being created
1618 aTrh = GEOM_VTKTrihedron::New();
1619 vtkPrs->AddObject( aTrh );
1622 // presentation is being updated
1623 vtkActorCollection* actors = vtkPrs->GetObjects();
1625 actors->InitTraversal();
1626 vtkActor* a = actors->GetNextActor();
1627 while ( a && !aTrh ) {
1628 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1629 a = actors->GetNextActor();
1635 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1637 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1638 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1640 #ifdef VTK_TRIHEDRON_WIDTH
1642 // VSR: currently isn't supported
1644 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1646 aTrh->SetWidth( GetWidth() );
1649 if ( !myIO.IsNull() )
1650 aTrh->setIO( myIO );
1652 aTrh->SetPlacement( aPlc );
1659 // processing for usual geometry presentation
1662 // if presentation is empty we try to create new one
1663 if ( vtkPrs->IsNull() )
1666 GEOM_Actor* actor = GEOM_Actor::New();
1667 // update actor properties
1668 updateActorProperties( actor, true );
1669 // add actor to the presentation
1670 vtkPrs->AddObject( actor );
1673 // presentation is being updated
1674 vtkActorCollection* actors = vtkPrs->GetObjects();
1676 actors->InitTraversal();
1677 vtkActor* a = actors->GetNextActor();
1679 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1681 // update actor properties
1682 updateActorProperties( actor, false );
1683 a = actors->GetNextActor();
1691 //=================================================================
1693 * GEOM_Displayer::BuildPrs
1694 * Build presentation according to the current viewer type
1696 //=================================================================
1697 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1699 if ( theObj->_is_nil() )
1702 myViewFrame = GetActiveView();
1703 if ( myViewFrame == 0 )
1706 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1711 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1712 myType = theObj->GetType();
1714 // Update presentation
1720 //=================================================================
1722 * GEOM_Displayer::BuildPrs
1723 * Build presentation according to the current viewer type
1725 //=================================================================
1726 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1728 myViewFrame = GetActiveView();
1729 if ( theShape.IsNull() || myViewFrame == 0 )
1732 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1737 setShape( theShape );
1745 //=================================================================
1747 * GEOM_Displayer::buildPresentation
1748 * Builds/finds object's presentation for the current viewer
1749 * Calls corresponding Update() method by means of double dispatch
1752 //=================================================================
1753 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1754 SALOME_View* theViewFrame )
1756 SALOME_Prs* prs = 0;
1759 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1763 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1766 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1767 theIO->setEntry( entry.toUtf8().constData() );
1768 if ( !theIO.IsNull() )
1770 // set interactive object
1772 // Find SOBject (because shape should be published previously)
1775 _PTR(SObject) SO ( getStudy()->studyDS()->FindObjectID( theIO->getEntry() ) );
1776 if ( SO ) //GeometryGUI::IsInGeomComponent( SO ))
1778 // get CORBA reference to data object
1779 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1780 if ( !CORBA::is_nil( object ) )
1782 // downcast to GEOM base object
1783 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1784 if ( !GeomBaseObject->_is_nil() )
1786 myType = GeomBaseObject->GetType();
1788 // downcast to GEOM object
1789 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1790 if ( myType == GEOM_FIELD_STEP )
1792 // get the GEOM object from the field's shape
1793 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1794 if ( !GeomFieldStep->_is_nil() )
1796 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1797 if ( !GeomField->_is_nil() )
1798 GeomObject = GeomField->GetShape();
1801 // read the field step information
1802 readFieldStepInfo( GeomFieldStep );
1805 if ( !GeomObject->_is_nil() )
1807 CORBA::String_var name = GeomObject->GetName();
1808 theIO->setName( name );
1809 // finally set shape
1810 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1817 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1823 //=================================================================
1825 * GEOM_Displayer::buildSubshapePresentation
1826 * Builds/finds object's presentation for the current viewer
1827 * Calls corresponding Update() method by means of double dispatch
1828 * For not published objects (for Mantis issue 0020435)
1830 //=================================================================
1831 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1832 const QString& entry,
1833 SALOME_View* theViewFrame)
1835 SALOME_Prs* prs = 0;
1838 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1842 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1845 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1846 theIO->setEntry(entry.toUtf8().constData());
1847 if (!theIO.IsNull())
1849 // set interactive object
1851 // finally set shape
1853 myType = GEOM_SUBSHAPE;
1855 UpdatePrs(prs); // Update presentation by using of the double dispatch
1861 //=================================================================
1863 * GEOM_Displayer::internalReset
1864 * Resets internal data
1867 //=================================================================
1868 void GEOM_Displayer::internalReset()
1873 myFieldDataType = GEOM::FDT_Double;
1874 myFieldDimension = 0;
1875 myFieldStepData.clear();
1876 myFieldStepName.Clear();
1877 myFieldStepRangeMin = 0;
1878 myFieldStepRangeMax = 0;
1881 //=================================================================
1883 * GEOM_Displayer::LocalSelection
1884 * Activate selection of CAD shapes with activisation of selection
1885 * of their sub-shapes (with opened local context for OCC viewer)
1887 //=================================================================
1888 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1890 SUIT_Session* session = SUIT_Session::session();
1891 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1895 LightApp_SelectionMgr* sm = app->selectionMgr();
1897 // remove all filters from selection
1900 SALOME_View* vf = GetActiveView();
1902 if (!theIO.IsNull() && !vf->isVisible(theIO))
1904 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1905 vf->LocalSelection( prs, modes );
1906 delete prs; // delete presentation because displayer is its owner
1910 //=================================================================
1912 * GEOM_Displayer::LocalSelection
1913 * Activate selection of CAD shapes with activisation of selection
1914 * of their sub-shapes (with opened local context for OCC viewer)
1916 //=================================================================
1917 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1919 std::list<int> modes;
1920 modes.push_back( theMode );
1921 LocalSelection( theIO, modes );
1924 //=================================================================
1926 * GEOM_Displayer::globalSelection
1927 * Activate selection of CAD shapes without activisation of selection
1928 * of their sub-shapes (without opened local context for OCC viewer)
1930 //=================================================================
1931 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1933 TColStd_MapOfInteger aModes;
1934 aModes.Add( theMode );
1935 GlobalSelection( aModes, update );
1938 //=================================================================
1940 * GEOM_Displayer::globalSelection
1941 * Activate selection of CAD shapes without activisation of selection
1942 * of their sub-shapes (without opened local context for OCC viewer)
1944 //=================================================================
1945 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1946 const bool update, const QList<int>* theSubShapes )
1948 SUIT_Session* session = SUIT_Session::session();
1949 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1953 SALOME_View* vf = GetActiveView();
1957 // Close local context
1958 vf->GlobalSelection( update );
1960 // Set selection filters in accordance with current mode
1961 LightApp_SelectionMgr* sm = app->selectionMgr();
1965 // Remove from selection temporary objects if necessary
1966 if ( !theModes.Contains( GEOM_PREVIEW ) )
1967 clearTemporary( sm );
1969 //@ aSel->ClearIndex();
1973 // Remove filters from AIS_InteractiveContext
1974 Handle(AIS_InteractiveContext) ic;
1975 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1978 ic = viewer->getAISContext();
1980 ic->RemoveFilters();
1983 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1986 SUIT_SelectionFilter* aFilter = NULL;
1987 if ( theModes.Extent() > 0 )
1989 TColStd_MapOfInteger aTopAbsModes;
1990 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1991 QList<SUIT_SelectionFilter*> aListOfFilters;
1992 for ( ; anIter.More(); anIter.Next() )
1994 SUIT_SelectionFilter* aFilter = 0;
1995 int aMode = anIter.Key();
1996 if ( aMode == GEOM_COMPOUNDFILTER )
1997 aFilter = getComplexFilter( theSubShapes );
1998 if ( aMode == GEOM_COMPOUND ) {
1999 // always add COMPSOLID filter together with COMPOUND filter
2000 aFilter = new GEOM_TypeFilter( getStudy(), TopAbs_COMPSOLID, true );
2001 aListOfFilters.append( aFilter );
2003 // add the COMPOUND filter itself
2004 aFilter = getFilter( aMode );
2007 aFilter = getFilter( aMode );
2010 aListOfFilters.append( aFilter );
2013 if (aListOfFilters.size() > 1)
2014 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
2021 sm->installFilter( aFilter );
2024 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
2025 ic->AddFilter( anOCCFilter );
2030 //=================================================================
2032 * GEOM_Displayer::LocalSelection
2033 * Activate selection of CAD shapes with activisation of selection
2034 * of their sub-shapes (with opened local context for OCC viewer)
2036 //=================================================================
2037 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2039 SALOME_ListIteratorOfListIO Iter( theIOList );
2040 for ( ; Iter.More(); Iter.Next() )
2041 LocalSelection( Iter.Value(), modes );
2044 //=================================================================
2046 * GEOM_Displayer::LocalSelection
2047 * Activate selection of CAD shapes with activisation of selection
2048 * of their sub-shapes (with opened local context for OCC viewer)
2050 //=================================================================
2051 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2053 std::list<int> modes;
2054 modes.push_back( theMode );
2055 LocalSelection( theIOList, modes );
2058 //=================================================================
2060 * GEOM_Displayer::BeforeDisplay
2061 * Called before displaying of pars. Close local context
2062 * [ Reimplemented from SALOME_Displayer ]
2064 //=================================================================
2065 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2067 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2070 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2079 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2083 // visualize annotations for displayed presentation
2084 SUIT_Session* session = SUIT_Session::session();
2085 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2086 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2088 if ( !myIsRedisplayed ) {
2089 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2091 aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2096 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2098 LightApp_Displayer::BeforeErase( v, p );
2099 releaseTextures( p );
2102 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2104 LightApp_Displayer::AfterErase( v, p );
2107 if ( !myIsRedisplayed ) {
2108 // hide annotations for erased presentation
2109 SUIT_Session* session = SUIT_Session::session();
2110 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2111 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2113 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2117 //=================================================================
2119 * GEOM_Displayer::SetColor
2120 * Set color for shape displaying. If it is equal -1 then default color is used.
2121 * Available values are from Quantity_NameOfColor enumeration
2123 //=================================================================
2124 void GEOM_Displayer::SetColor( const int color )
2131 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2135 int GEOM_Displayer::GetColor() const
2140 bool GEOM_Displayer::HasColor() const
2142 return myColor != -1;
2145 void GEOM_Displayer::UnsetColor()
2149 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2150 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2151 myShadingColor = SalomeApp_Tools::color( col );
2154 //=================================================================
2156 * GEOM_Displayer::SetTransparency
2157 * Set transparency for shape displaying.
2159 //=================================================================
2160 double GEOM_Displayer::SetTransparency( const double transparency )
2162 double prevTransparency = myTransparency;
2163 myTransparency = transparency;
2164 return prevTransparency;
2167 //=================================================================
2169 * GEOM_Displayer::GetTransparency
2170 * Get transparency for shape displaying.
2172 //=================================================================
2173 double GEOM_Displayer::GetTransparency() const
2175 return myTransparency;
2178 //=================================================================
2180 * GEOM_Displayer::HasTransparency
2181 * Check if transparency for shape displaying is set.
2183 //=================================================================
2184 bool GEOM_Displayer::HasTransparency() const
2186 return myTransparency >= 0;
2189 //=================================================================
2191 * GEOM_Displayer::UnsetTransparency
2192 * Unset transparency for shape displaying.
2194 //=================================================================
2195 double GEOM_Displayer::UnsetTransparency()
2197 return SetTransparency( -1 );
2200 //=================================================================
2202 * GEOM_Displayer::SetTexture
2204 //=================================================================
2205 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2207 myTexture = texureFileName;
2210 bool GEOM_Displayer::HasTexture() const
2212 return myTexture != "";
2215 std::string GEOM_Displayer::GetTexture() const
2220 //=================================================================
2222 * GEOM_Displayer::SetWidth
2223 * Set width of shape displaying. If it is equal -1 then default width is used.
2225 //=================================================================
2226 void GEOM_Displayer::SetWidth( const double width )
2231 double GEOM_Displayer::GetWidth() const
2236 bool GEOM_Displayer::HasWidth() const
2238 return myWidth != -1;
2241 void GEOM_Displayer::UnsetWidth()
2246 int GEOM_Displayer::GetIsosWidth() const
2251 void GEOM_Displayer::SetIsosWidth(const int width)
2253 myIsosWidth = width;
2256 bool GEOM_Displayer::HasIsosWidth() const
2258 return myIsosWidth != -1;
2261 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2263 int prevNbIsos = myNbIsos;
2268 int GEOM_Displayer::UnsetNbIsos()
2270 return SetNbIsos( -1 );
2273 int GEOM_Displayer::GetNbIsos() const
2278 bool GEOM_Displayer::HasNbIsos() const
2280 return myNbIsos >= 0;
2283 int GEOM_Displayer::SetIsosColor( const int color )
2285 int prevColor = myIsosColor;
2286 myIsosColor = color;
2290 int GEOM_Displayer::GetIsosColor() const
2295 bool GEOM_Displayer::HasIsosColor() const
2297 return myIsosColor != -1;
2300 int GEOM_Displayer::UnsetIsosColor()
2302 return SetIsosColor( -1 );
2305 //=================================================================
2307 * GEOM_Displayer::SetToActivate
2308 * This method is used for activisation/deactivisation of objects to be displayed
2310 //=================================================================
2311 void GEOM_Displayer::SetToActivate( const bool toActivate )
2313 myToActivate = toActivate;
2315 bool GEOM_Displayer::ToActivate() const
2317 return myToActivate;
2320 //=================================================================
2322 * GEOM_Displayer::clearTemporary
2323 * Removes from selection temporary objects
2325 //=================================================================
2326 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2328 SALOME_ListIO selected, toSelect;
2329 theSelMgr->selectedObjects( selected );
2331 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2332 Handle(SALOME_InteractiveObject) io = it.Value();
2333 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2334 toSelect.Append( it.Value() );
2337 theSelMgr->setSelectedObjects( toSelect, true );
2340 void GEOM_Displayer::SetName( const char* theName )
2345 void GEOM_Displayer::UnsetName()
2350 SalomeApp_Study* GEOM_Displayer::getStudy() const
2352 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2355 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2360 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2365 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2366 const int theFieldDimension,
2367 const QList<QVariant>& theFieldStepData,
2368 const TCollection_AsciiString& theFieldStepName,
2369 const double theFieldStepRangeMin,
2370 const double theFieldStepRangeMax )
2372 myFieldDataType = theFieldDataType;
2373 myFieldDimension = theFieldDimension;
2374 myFieldStepData = theFieldStepData;
2375 myFieldStepName = theFieldStepName;
2376 myFieldStepRangeMin = theFieldStepRangeMin;
2377 myFieldStepRangeMax = theFieldStepRangeMax;
2380 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2382 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toUtf8() );
2383 //if ( ! GeometryGUI::IsInGeomComponent( anObj )) return false;
2384 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2385 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2386 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2387 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2388 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2391 int GEOM_Displayer::SetDisplayMode( const int theMode )
2393 int aPrevMode = myDisplayMode;
2394 if ( theMode != -1 ) {
2395 myDisplayMode = theMode;
2396 myHasDisplayMode = true;
2404 int GEOM_Displayer::GetDisplayMode() const
2406 return myDisplayMode;
2409 int GEOM_Displayer::UnsetDisplayMode()
2411 int aPrevMode = myDisplayMode;
2412 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2413 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2414 myHasDisplayMode = false;
2418 bool GEOM_Displayer::HasDisplayMode() const
2420 return myHasDisplayMode;
2423 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2425 static QList<QColor> colors;
2427 if ( colors.isEmpty() ) {
2429 for (int s = 0; s < 2 ; s++)
2431 for (int v = 100; v >= 40; v = v - 20)
2433 for (int h = 0; h < 359 ; h = h + 60)
2435 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2441 static int currentColor = randomize( colors.size() );
2443 SALOMEDS::Color color;
2444 color.R = (double)colors[currentColor].red() / 255.0;
2445 color.G = (double)colors[currentColor].green() / 255.0;
2446 color.B = (double)colors[currentColor].blue() / 255.0;
2448 currentColor = (currentColor+1) % colors.count();
2453 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2456 int aTolerance = 64;
2457 int anIterations = 0;
2463 if( anIterations % aPeriod == 0 )
2466 if( aTolerance < 1 )
2469 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2471 aHue = (int)( 360.0 * rand() / RAND_MAX );
2472 //std::cout << "Hue = " << aHue << std::endl;
2474 //std::cout << "Auto colors : ";
2476 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2477 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2478 for( ; it != itEnd; ++it )
2480 SALOMEDS::Color anAutoColor = *it;
2481 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2484 aQColor.getHsv( &h, &s, &v );
2485 //std::cout << h << " ";
2486 if( abs( h - aHue ) < aTolerance )
2489 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2493 //std::cout << std::endl;
2499 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2501 aColor.setHsv( aHue, 255, 255 );
2503 SALOMEDS::Color aSColor;
2504 aSColor.R = (double)aColor.red() / 255.0;
2505 aSColor.G = (double)aColor.green() / 255.0;
2506 aSColor.B = (double)aColor.blue() / 255.0;
2511 PropMap GEOM_Displayer::getObjectProperties( const QString& entry,
2514 // get default properties for the explicitly specified default view type
2515 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2517 if ( getStudy() && view ) {
2518 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2519 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2520 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2522 if ( viewModel && viewId != -1 ) {
2523 // get properties from the study
2524 PropMap storedMap = getStudy()->getObjectProperties( viewId, entry );
2525 // overwrite default properties from stored ones (that are specified)
2526 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2527 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2528 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2529 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2531 // ... specific processing for color
2532 // ... current implementation is to use same stored color for all aspects
2533 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2534 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2535 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2536 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2537 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2538 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2539 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2542 if ( !entry.isEmpty() ) {
2543 // get CORBA reference to geom object
2544 _PTR(SObject) SO( getStudy()->studyDS()->FindObjectID( entry.toStdString() ) );
2545 if ( SO ) { //GeometryGUI::IsInGeomComponent( SO )) {
2546 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2547 if ( !CORBA::is_nil( object ) ) {
2548 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2549 if ( !CORBA::is_nil( geomObject ) ) { // to check
2550 // check that geom object has color properly set
2551 bool hasColor = false;
2552 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2553 // set color from geometry object (only once, if it is not yet set in GUI)
2554 // current implementation is to use same color for all aspects
2555 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2556 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2557 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2558 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2559 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2560 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2561 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2562 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2564 // check that object has point marker properly set
2565 GEOM::marker_type mType = geomObject->GetMarkerType();
2566 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2567 int mTextureId = geomObject->GetMarkerTexture();
2568 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2569 ( mType == GEOM::MT_USER && mTextureId > 0 );
2570 // set point marker from geometry object (only once, if it is not yet set in GUI)
2571 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2572 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2574 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2575 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2577 else if ( mType == GEOM::MT_USER ) {
2579 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2591 PropMap GEOM_Displayer::getDefaultPropertyMap()
2595 // get resource manager
2596 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2598 // fill in the properties map with default values
2600 // - visibility (false by default)
2601 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2603 // - nb isos (take default value from preferences)
2604 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2605 QString( "%1%2%3" ).
2606 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2607 arg( GEOM::subSectionSeparator() ).
2608 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2610 // - transparency (opacity = 1-transparency)
2611 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2612 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2614 // - display mode (take default value from preferences)
2615 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2616 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2618 // - show edges direction flag (false by default)
2619 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2621 // - show vertices flag (false by default)
2622 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2624 // - show name flag (false by default)
2625 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2627 // - shading color (take default value from preferences)
2628 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2629 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2631 // - wireframe color (take default value from preferences)
2632 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2633 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2635 // - standalone edges color (take default value from preferences)
2636 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2637 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2639 // - free boundaries color (take default value from preferences)
2640 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2641 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2643 // - points color (take default value from preferences)
2644 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2645 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2647 // - isos color (take default value from preferences)
2648 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2649 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2651 // - outlines color (take default value from preferences)
2652 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2653 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2655 // - deflection coefficient (take default value from preferences)
2656 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2657 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2659 // - material (take default value from preferences)
2660 Material_Model material;
2661 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2662 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2664 // - edge width (take default value from preferences)
2665 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2666 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2668 // - isos width (take default value from preferences)
2669 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2670 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2672 // - point marker (take default value from preferences)
2673 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2674 QString( "%1%2%3" ).
2675 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2676 arg( GEOM::subSectionSeparator() ).
2677 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2679 // - top-level flag (false by default)
2680 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2685 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2686 SALOMEDS::Color aSColor;
2689 SUIT_Session* session = SUIT_Session::session();
2690 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2692 if ( app && !theGeomObject->_is_nil()) {
2693 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2696 _PTR(Study) aStudy = study->studyDS();
2697 aSColor = theGeomObject->GetColor();
2698 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2700 if (!theGeomObject->IsMainShape()) {
2701 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2702 bool general_autocolor = true;
2703 #else // auto-color for groups only
2704 bool general_autocolor = false;
2705 #endif // GENERAL_AUTOCOLOR
2706 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2707 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2708 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2709 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2710 aSColor = getPredefinedUniqueColor();
2712 #else // old algorithm for auto-colors
2713 QList<SALOMEDS::Color> aReservedColors;
2714 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2715 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2716 if ( aMainSObject ) {
2717 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2718 for ( ; it->More(); it->Next() ) {
2719 _PTR(SObject) aChildSObject( it->Value() );
2720 GEOM::GEOM_Object_var aChildObject =
2721 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2722 if ( CORBA::is_nil( aChildObject ) )
2725 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2726 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2727 aReservedColors.append( aReservedColor );
2730 aSColor = getUniqueColor( aReservedColors );
2732 #endif // SIMPLE_AUTOCOLOR
2743 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2744 const bool eraseOnlyChildren)
2746 LightApp_DataObject* parent = getStudy()->findObjectByEntry(theIO->getEntry());
2751 // Erase from all views
2752 QList<SALOME_View*> views;
2754 ViewManagerList vmans = myApp->viewManagers();
2755 SUIT_ViewManager* vman;
2756 foreach ( vman, vmans ) {
2757 SUIT_ViewModel* vmod = vman->getViewModel();
2758 view = dynamic_cast<SALOME_View*> ( vmod );
2760 views.append( view );
2763 if( views.count() == 0 )
2766 //Erase childrens w/o update views
2767 DataObjectList listObj = parent->children( true );
2768 SUIT_DataObject* obj;
2769 foreach( obj, listObj ) {
2770 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2772 foreach ( view, views ) {
2773 Handle(SALOME_InteractiveObject) anIO =
2774 new SALOME_InteractiveObject(qUtf8Printable(l_obj->entry()), "GEOM", "");
2775 Erase(anIO, false, false, view);
2779 //Erase parent with view update or repaint views
2780 foreach ( view, views ) {
2781 if(!eraseOnlyChildren)
2782 Erase(theIO, false, true, view);
2788 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2790 if( theGeomFieldStep->_is_nil() )
2793 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2794 if( aGeomField->_is_nil() )
2797 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2798 if( aGeomFieldShape->_is_nil() )
2801 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2802 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2803 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2805 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2807 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2809 int aFieldDimension = aGeomField->GetDimension();
2811 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2812 int aFieldNbComponents = aFieldComponents->length();
2814 QList<QVariant> aFieldStepData;
2815 if( aFieldDataType == GEOM::FDT_Bool )
2817 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2818 if ( !aGeomBoolFieldStep->_is_nil() )
2820 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2821 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2822 aFieldStepData << (bool)aValues[i];
2825 else if( aFieldDataType == GEOM::FDT_Int )
2827 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2828 if ( !aGeomIntFieldStep->_is_nil() )
2830 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2831 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2832 aFieldStepData << (qlonglong)aValues[i];
2835 else if( aFieldDataType == GEOM::FDT_Double )
2837 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2838 if ( !aGeomDoubleFieldStep->_is_nil() )
2840 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2841 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2842 aFieldStepData << (double)aValues[i];
2845 else if( aFieldDataType == GEOM::FDT_String )
2847 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2848 if ( !aGeomStringFieldStep->_is_nil() )
2850 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2851 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2852 aFieldStepData << QString( aValues[i] );
2856 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2857 aFieldStepData = groupFieldData( aFieldStepData,
2859 aFieldDataType == GEOM::FDT_String,
2861 aFieldStepRangeMax );
2863 setFieldStepInfo( aFieldDataType,
2868 aFieldStepRangeMax );
2871 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2872 const int theFieldNbComponents,
2873 const bool theIsString,
2874 double& theFieldStepRangeMin,
2875 double& theFieldStepRangeMax )
2877 QList<QVariant> aResultList;
2878 theFieldStepRangeMin = 0;
2879 theFieldStepRangeMax = 0;
2881 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2884 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2886 QList<QVariant> aGroupedList;
2888 bool anIsBoolean = false;
2889 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2892 QStringList aStringList;
2894 int aBaseIndex = aSubShape * theFieldNbComponents;
2895 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2897 int anIndex = aComponent + aBaseIndex;
2899 const QVariant& aVariant = theFieldStepData[ anIndex ];
2902 if( aVariant.type() == QVariant::String )
2903 aStringList << aVariant.toString();
2908 if( aVariant.type() == QVariant::Bool )
2910 aValue = aVariant.toBool() ? 1.0 : 0.0;
2916 if( aVariant.type() == QVariant::LongLong )
2917 aValue = double( aVariant.toLongLong() );
2918 else if( aVariant.type() == QVariant::Double )
2919 aValue = aVariant.toDouble();
2920 if ( theFieldNbComponents > 1 )
2921 aNorm += aValue * aValue;
2929 aGroupedList << aStringList.join( "\n" );
2933 aNorm /= theFieldNbComponents;
2934 else if ( theFieldNbComponents > 1 )
2935 aNorm = pow( aNorm, 0.5 );
2937 if( aGroupedList.isEmpty() )
2938 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2941 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2942 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2945 aGroupedList << aNorm;
2951 theFieldStepRangeMin = 0.0;
2952 theFieldStepRangeMax = 1.0;
2955 SUIT_Session* session = SUIT_Session::session();
2956 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2957 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2959 QListIterator<QVariant> anIter( aGroupedList );
2960 while( anIter.hasNext() )
2962 const QVariant& aVariant = anIter.next();
2964 aResultList << aVariant;
2968 Quantity_Color aColor;
2969 if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2970 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2971 aResultList << aQColor;
2977 void GEOM_Displayer::UpdateColorScale()
2979 if ( !myUpdateColorScale )
2982 SUIT_Session* session = SUIT_Session::session();
2983 SUIT_Application* app = session->activeApplication();
2986 Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject();
2988 QList<SUIT_ViewWindow*> windows = app->desktop()->windows();
2989 foreach( SUIT_ViewWindow* window, windows )
2991 OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>( window );
2992 if ( !occWindow ) continue;
2993 if ( !occWindow->getViewManager() ) continue;
2994 if ( !window->getViewManager() ) continue;
2995 if ( !window->getViewManager()->getViewModel() ) continue;
2996 SOCC_Viewer* view = dynamic_cast<SOCC_Viewer*>( window->getViewManager()->getViewModel() );
2997 if ( !view ) continue;
2998 Handle(V3d_Viewer) viewer = view->getViewer3d();
2999 if ( !io.IsNull() && view->isVisible( io ) )
3001 bool visible = false;
3002 SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( view->CreatePrs( io->getEntry() ) );
3005 AIS_ListOfInteractive presentations;
3006 prs->GetObjects( presentations );
3007 AIS_ListIteratorOfListOfInteractive iter( presentations );
3008 for ( ; iter.More(); iter.Next() )
3010 Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() );
3011 if ( shape.IsNull() ) continue;
3012 GEOM::field_data_type fieldDataType;
3014 QList<QVariant> fieldStepData;
3015 TCollection_AsciiString fieldStepName;
3016 Standard_Real fieldStepRangeMin, fieldStepRangeMax;
3017 shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData,
3018 fieldStepName, fieldStepRangeMin, fieldStepRangeMax );
3019 visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String;
3022 SUIT_Session* session = SUIT_Session::session();
3023 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3025 Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3026 Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3027 Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3028 Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3029 Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3030 Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3032 Standard_Integer viewWidth = 0, viewHeight = 0;
3033 occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight );
3035 Handle(AIS_ColorScale) colorScale = view->getColorScale();
3037 colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos );
3038 colorScale->SetBreadth( viewWidth * width );
3039 colorScale->SetHeight( viewHeight * height );
3040 colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax );
3041 colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals );
3042 colorScale->SetTextHeight( textHeight );
3043 colorScale->SetTitle( fieldStepName );
3047 view->setColorScaleShown( visible );
3048 } // if ( view->isVisible( io ) )
3051 view->setColorScaleShown( false );
3053 } // foreach( SUIT_ViewWindow* window, windows )
3056 bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049
3058 bool previous = myUpdateColorScale;
3059 myUpdateColorScale = toUpdate;
3060 if ( myUpdateColorScale && !previous )