1 // Copyright (C) 2007-2019 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>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #include <TColStd_HArray1OfByte.hxx>
128 // If the next macro is defined, autocolor feature works for all sub-shapes;
129 // if it is undefined, autocolor feature works for groups only
130 #define GENERAL_AUTOCOLOR
131 // Below macro, when uncommented, switches on simplified (more performant) algorithm
132 // of auto-color picking up
133 #define SIMPLE_AUTOCOLOR
135 // Hard-coded value of shape deflection coefficient for VTK viewer
136 const double VTK_MIN_DEFLECTION = 0.001;
137 // If the next macro is defined, the deflection coefficient for VTK presentation
138 // is limited by VTK_MIN_DEFLECTION
139 //#define LIMIT_DEFLECTION_FOR_VTK
141 // Pixmap caching support
144 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
145 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
146 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
148 static inline PixmapUsageMap& getPixmapUsageMap()
150 static PixmapUsageMap aMap;
154 static inline PixmapCacheMap& getPixmapCacheMap()
156 static PixmapCacheMap aMap;
160 //===========================================================================
161 // Function : getDefaultTexture
162 // Purpose : Get default texture
163 //===========================================================================
164 static inline Handle(Image_PixMap) getDefaultTexture()
166 static Handle(Image_PixMap) aPixmap;
167 if ( aPixmap.IsNull() ) {
168 QPixmap px(":images/default_texture.png");
170 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
175 //===========================================================================
176 // Function : cacheTextureFor
177 // Purpose : Load and cache image for the specified presentation.
178 //===========================================================================
179 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
180 const Handle(GEOM_AISShape)& theShape )
182 if ( thePath.isEmpty() )
185 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
186 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
188 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
189 if ( !aPixmap.IsNull() ) {
190 // point that the texture is used by the presentation
191 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
192 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
194 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
199 // convert texture to compatible image format
200 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
201 if ( anImage.isNull() )
204 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
206 aPixmapCacheMap.insert( thePath, aPixmap );
208 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
209 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
211 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
216 //===========================================================================
217 // Function : releaseTextures
218 // Purpose : Releases cached textures found for the specified presentation.
219 //===========================================================================
220 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
222 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
224 AIS_ListOfInteractive aListOfIO;
226 anOccPrs->GetObjects( aListOfIO );
228 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
230 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
231 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
233 for ( ; aIterateIO.More(); aIterateIO.Next() )
235 Handle(GEOM_AISShape) aAISShape =
236 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
238 if ( aAISShape.IsNull() )
241 const Handle(Graphic3d_TextureMap)& aTexture = aAISShape->Attributes()->ShadingAspect()->Aspect()->TextureMap();
242 if ( aTexture.IsNull() )
245 const Handle(Image_PixMap)& aPixmap = aTexture->GetImage();
246 if ( aPixmap.IsNull() )
249 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
252 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
254 aUsersShapes.Remove( aAISShape );
256 if ( aUsersShapes.IsEmpty() ) {
257 aPixmapUsersMap.UnBind( aPixmap );
258 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
263 uint randomize( uint size )
265 static bool initialized = false;
266 if ( !initialized ) {
267 qsrand( QDateTime::currentDateTime().toTime_t() );
271 v = uint( (double)( v ) / RAND_MAX * size );
272 v = qMax( uint(0), qMin ( v, size-1 ) );
277 //================================================================
278 // Function : getActiveStudy
279 // Purpose : Get active study, returns 0 if no open study frame
280 //================================================================
281 static inline SalomeApp_Study* getActiveStudy()
283 SUIT_Session* session = SUIT_Session::session();
284 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
286 return ( SalomeApp_Study* )app->activeStudy();
290 static inline int getViewManagerId( SALOME_View* theViewFrame) {
291 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
292 SUIT_ViewManager* aViewMgr = 0;
294 aViewMgr = aModel->getViewManager();
295 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
298 //================================================================
299 // Function : getTopAbsMode
300 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
301 // one from GEOMImpl_Types.h
302 //================================================================
303 static inline int getTopAbsMode( const int implType )
307 case GEOM_COMPOUND : return TopAbs_COMPOUND;
308 case GEOM_SOLID : return TopAbs_SOLID;
309 case GEOM_SHELL : return TopAbs_SHELL;
310 case GEOM_FACE : return TopAbs_FACE;
311 case GEOM_WIRE : return TopAbs_WIRE;
312 case GEOM_EDGE : return TopAbs_EDGE;
313 case GEOM_POINT : return TopAbs_VERTEX;
318 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
320 if ( shape.IsNull() )
323 int ret = shape.ShapeType();
325 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
326 TopoDS_Iterator it(shape, Standard_True, Standard_False);
327 for (; it.More(); it.Next()) {
328 TopoDS_Shape sub_shape = it.Value();
329 if ( sub_shape.IsNull() ) continue;
330 int stype = getMinMaxShapeType( sub_shape, ismin );
331 if ( stype == TopAbs_SHAPE ) continue;
332 if ( ismin && stype > ret )
334 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
342 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
344 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
347 //================================================================
348 // Function : getFilter
349 // Purpose : Get filter corresponding to the type of object
350 // from GEOMImpl_Types.h
351 //================================================================
352 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
354 SUIT_SelectionFilter* aFilter;
356 int aTopAbsMode = getTopAbsMode( theMode );
357 if ( aTopAbsMode != -1 )
358 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
362 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
363 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
365 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
366 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
367 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
368 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
369 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
370 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
372 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
374 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
375 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
377 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
383 //================================================================
384 // Function : getComplexFilter
385 // Purpose : Get compound filter corresponding to the type of
386 // object from GEOMImpl_Types.h
387 //================================================================
388 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
390 GEOM_CompoundFilter* aFilter;
392 if(aSubShapes != NULL ) {
393 aFilter = new GEOM_CompoundFilter(getStudy());
394 QList<int> aTopAbsTypes;
395 QList<int>::const_iterator it;
396 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
397 int topAbsMode = getTopAbsMode(*it);
398 if(topAbsMode != -1 )
399 aTopAbsTypes.append(topAbsMode);
401 aFilter->addSubTypes(aTopAbsTypes);
407 //================================================================
408 // Function : getEntry
410 //================================================================
411 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
413 SUIT_Session* session = SUIT_Session::session();
414 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
417 CORBA::String_var IOR = app->orb()->object_to_string( object );
418 if ( strcmp(IOR.in(), "") != 0 )
420 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
421 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
429 //================================================================
430 // Function : getName
432 //================================================================
433 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
435 SUIT_Session* session = SUIT_Session::session();
436 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
439 CORBA::String_var IOR = app->orb()->object_to_string( object );
440 if ( strcmp(IOR.in(), "") != 0 )
442 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
443 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
445 _PTR(GenericAttribute) anAttr;
447 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
449 _PTR(AttributeName) aNameAttr( anAttr );
450 return aNameAttr->Value();
458 //=================================================================
460 * GEOM_Displayer::GEOM_Displayer
463 //=================================================================
464 GEOM_Displayer::GEOM_Displayer()
465 : myUpdateColorScale(true), myIsRedisplayed( false )
467 SUIT_Session* session = SUIT_Session::session();
468 myApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
471 SUIT_ResourceMgr* resMgr = session->resourceMgr();
473 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
474 myShadingColor = SalomeApp_Tools::color( col );
476 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
477 myHasDisplayMode = false;
479 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
481 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
482 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
483 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
485 // Next properties provide a way to customize displaying of presentations;
486 // for instance, this is useful for preview
496 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
499 // Activate parallel vizualisation by default.
500 // It can be switched OFF via the environment variable:
501 // export PARALLEL_VISU=0
502 Standard_Boolean parallel_visu = Standard_True;
503 char* parallel_visu_env = getenv("PARALLEL_VISU");
504 if (parallel_visu_env && atoi(parallel_visu_env) == 0)
505 parallel_visu = Standard_False;
506 BRepMesh_IncrementalMesh::SetParallelDefault(parallel_visu);
510 myFieldDataType = GEOM::FDT_Double;
511 myFieldDimension = 0;
512 myFieldStepRangeMin = 0;
513 myFieldStepRangeMax = 0;
516 //=================================================================
518 * GEOM_Displayer::~GEOM_Displayer
521 //=================================================================
522 GEOM_Displayer::~GEOM_Displayer()
526 //=================================================================
528 * GEOM_Displayer::Display
529 * Display interactive object in the current viewer
531 //=================================================================
532 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
533 const bool updateViewer,
534 SALOME_View* theViewFrame )
536 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
539 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
543 vf->BeforeDisplay( this, prs );
544 vf->Display( this, prs );
545 vf->AfterDisplay( this, prs );
550 delete prs; // delete presentation because displayer is its owner
555 //=================================================================
557 * GEOM_Displayer::Display
558 * This overloaded Display() method can be useful for operations
559 * not using dialog boxes.
561 //=================================================================
562 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
564 if ( theObj->_is_nil() )
567 std::string entry = getEntry( theObj );
569 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
574 //=================================================================
576 * GEOM_Displayer::Erase
577 * Erase interactive object in the current viewer
579 //=================================================================
580 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
582 const bool updateViewer,
583 SALOME_View* theViewFrame )
585 if ( theIO.IsNull() )
588 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
591 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
593 vf->BeforeErase( this, prs );
594 vf->Erase( this, prs, forced );
595 vf->AfterErase( this, prs );
598 delete prs; // delete presentation because displayer is its owner
603 //=================================================================
605 * GEOM_Displayer::Erase
606 * Erase geometry object in the current viewer
608 //=================================================================
609 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
611 const bool updateViewer,
612 SALOME_View* theViewFrame)
614 std::string entry = getEntry( theObj );
617 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
618 forced, updateViewer, theViewFrame);
622 //=================================================================
624 * GEOM_Displayer::Redisplay
625 * Redisplay (erase and then display again) interactive object
626 * in the current viewer
628 //=================================================================
629 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
630 const bool updateViewer,
631 const bool checkActiveViewer )
633 bool aRedisplayed = myIsRedisplayed;
634 myIsRedisplayed = true;
635 // Remove the object permanently (<forced> == true)
636 SUIT_Session* ses = SUIT_Session::session();
637 SUIT_Application* app = ses->activeApplication();
640 SUIT_Desktop* desk = app->desktop();
641 QList<SUIT_ViewWindow*> wnds = desk->windows();
642 SUIT_ViewWindow* wnd;
643 QListIterator<SUIT_ViewWindow*> it( wnds );
644 while ( it.hasNext() && (wnd = it.next()) )
646 SUIT_ViewManager* vman = wnd->getViewManager();
649 SUIT_ViewModel* vmodel = vman->getViewModel();
652 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
655 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
657 Redisplay( theIO, updateViewer, view );
664 myIsRedisplayed = aRedisplayed;
667 //=================================================================
669 * GEOM_Displayer::Redisplay
670 * Redisplay (erase and then display again) interactive object
671 * in the specified view
673 //=================================================================
674 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
675 const bool theUpdateViewer,
676 SALOME_View* theViewFrame )
678 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
684 bool aRedisplayed = myIsRedisplayed;
685 myIsRedisplayed = true;
686 Erase( theIO, true, false, theViewFrame );
687 Display( theIO, theUpdateViewer, theViewFrame );
688 myIsRedisplayed = aRedisplayed;
689 // hide annotations for erased presentation
690 SUIT_Session* session = SUIT_Session::session();
691 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
692 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
694 if ( !theViewFrame->isVisible( theIO ) ) {
695 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
698 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
703 //=================================================================
705 * GEOM_Displayer::Display
706 * Calls Display() method for each object in the given list
708 //=================================================================
709 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
711 SALOME_ListIteratorOfListIO Iter( theIOList );
712 for ( ; Iter.More(); Iter.Next() ) {
713 Display( Iter.Value(), false );
719 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
721 SalomeApp_Study* aStudy = getStudy();
723 if ( v ) vId = getViewManagerId( v );
726 QString entry = p->GetEntry();
727 if ( !entry.isEmpty() ) {
729 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
730 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
735 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
740 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
742 // VSR: this method can be improved in future:
743 // to improve performance, the default values from resource manager should be cached in the displayer
744 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
747 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
749 // VSR: this method can be improved in future:
750 // to improve performance, the default values from resource manager should be cached in the displayer
751 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
754 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
756 // check that shape is not null
757 if ( AISShape.IsNull() ) return;
759 // check that study is active
760 SalomeApp_Study* study = getStudy();
761 if ( !study ) return;
763 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
764 !TopoDS_Iterator(myShape).More() )
765 return; // NPAL15983 (Bug when displaying empty groups)
767 // set interactive object
769 Handle( SALOME_InteractiveObject ) anIO;
771 if ( !myIO.IsNull() ) {
772 AISShape->setIO( myIO );
773 AISShape->SetOwner( myIO );
776 else if ( !myName.empty() ) {
777 // workaround to allow selection of temporary objects
778 static int tempId = 0;
779 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toUtf8().data(), "GEOM", myName.c_str() );
780 AISShape->setIO( anIO );
781 AISShape->SetOwner( anIO );
784 // flag: only vertex or compound of vertices is processed (specific handling)
785 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
786 // presentation study entry (empty for temporary objects like preview)
787 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
788 // flag: temporary object
789 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
790 // currently active view window's ID (-1 if no active view)
791 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
793 // get presentation properties
794 PropMap propMap = getObjectProperties( entry, myViewFrame );
796 // Temporary staff: vertex must be infinite for correct visualization
797 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
800 Material_Model material;
801 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
803 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
804 // - set front material properties
805 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
806 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
807 // - set back material properties
808 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
809 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
810 // - switch to default (both sides) facing mode
811 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
817 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
818 // we set it to the shape not taking into account material properties
819 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
821 else if ( !material.isPhysical() ) {
822 // shading color from properties is used only for non-physical materials
823 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
827 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
828 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
829 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
830 AISShape->Attributes()->SetLineAspect( anAspect );
832 // - unfree boundaries color
833 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
834 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
835 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
836 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
838 // - free boundaries color
839 Handle(Prs3d_LineAspect) aFreeBoundaryAspect =
840 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
841 *aFreeBoundaryAspect->Aspect() = *AISShape->Attributes()->FreeBoundaryAspect()->Aspect();
842 aFreeBoundaryAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
843 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
844 AISShape->Attributes()->SetFreeBoundaryAspect( aFreeBoundaryAspect );
846 // - standalone edges color
847 anAspect = AISShape->Attributes()->WireAspect();
848 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
849 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
850 AISShape->Attributes()->SetWireAspect( anAspect );
852 // - color for edges in shading+edges mode
853 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
855 // - color of labels (textual fields and shape name)
856 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
859 int displayMode = HasDisplayMode() ?
860 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
862 // display mode from properties
863 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
864 AISShape->SetDisplayMode( displayMode );
866 // - face boundaries color and line width
867 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
868 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
869 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
870 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
872 // set display vectors flag
873 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
875 // set display vertices flag
876 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
877 AISShape->SetDisplayVertices( isVerticesMode );
879 // set display name flag
880 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
881 AISShape->SetDisplayName( isNameMode );
884 if( HasTransparency() ) {
885 AISShape->SetTransparency( GetTransparency() );
887 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
890 // set iso properties
891 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
892 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
893 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
894 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
895 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
896 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
898 if ( HasIsosColor() ) {
899 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
900 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
903 uIsoAspect->SetColor( isosColor );
904 vIsoAspect->SetColor( isosColor );
907 if ( HasIsosWidth() ) {
908 uIsoAspect->SetWidth( GetIsosWidth() );
909 vIsoAspect->SetWidth( GetIsosWidth() );
912 uIsoAspect->SetWidth( isosWidth );
913 vIsoAspect->SetWidth( isosWidth );
917 uIsoAspect->SetNumber( GetNbIsos() );
918 vIsoAspect->SetNumber( GetNbIsos() );
921 uIsoAspect->SetNumber( uIsos );
922 vIsoAspect->SetNumber( vIsos );
925 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
926 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
928 // set deflection coefficient
929 // ... to avoid to small values of the coefficient, its lower value is limited
930 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
934 if ( HasTexture() ) {
935 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
936 aImagePath = GetTexture().c_str();
937 if ( ! entry.isEmpty() ) {
938 // check that study is active
939 SalomeApp_Study* study = getStudy();
941 // Store the texture in object properties for next displays
942 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
943 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
945 // Update properties map
946 propMap = getObjectProperties( entry, myViewFrame );
951 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
954 Handle(Image_PixMap) aPixmap;
955 if ( !aImagePath.isEmpty() )
956 aPixmap = cacheTextureFor( aImagePath, AISShape );
958 aPixmap = getDefaultTexture();
960 // apply image to shape
961 if ( !aPixmap.IsNull() ) {
962 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) );
964 if ( displayMode == GEOM_AISShape::TexturedShape )
965 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
967 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
970 AISShape->SetWidth( HasWidth() ?
971 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
973 // libe width from properties
974 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
976 // set top-level flag
977 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
979 // set point marker (for vertex / compound of vertices only)
980 if ( onlyVertex || isVerticesMode ) {
981 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
982 if ( aList.size() == 2 ) {
983 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
984 int aTypeOfMarker = aList[0].toInt();
985 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
986 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
987 anAspect->SetScale( aScaleOfMarker );
988 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
989 anAspect->SetColor( HasColor() ?
990 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
991 (Quantity_NameOfColor)GetColor() :
992 // color from properties
993 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
994 AISShape->Attributes()->SetPointAspect( anAspect );
996 else if ( aList.size() == 1 ) {
997 // custom marker string contains "IdOfTexture"
998 int textureId = aList[0].toInt();
999 Standard_Integer aWidth, aHeight;
1000 Handle(TColStd_HArray1OfByte) aTexture =
1001 GeometryGUI::getTexture( textureId, aWidth, aHeight );
1002 if ( !aTexture.IsNull() ) {
1003 Handle(Prs3d_PointAspect) aTextureAspect =
1004 new Prs3d_PointAspect( HasColor() ?
1005 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1006 (Quantity_NameOfColor)GetColor() :
1007 // color from properties
1008 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1011 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1016 // set field step data
1017 AISShape->setFieldStepInfo( myFieldDataType,
1021 myFieldStepRangeMin,
1022 myFieldStepRangeMax );
1024 if ( create && !isTemporary && aMgrId != -1 ) {
1025 // set properties to the study
1026 study->setObjectProperties( aMgrId, entry, propMap );
1029 // AISShape->SetName(???); ??? necessary to set name ???
1032 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1034 // check that actor is not null
1035 if ( !actor ) return;
1037 // check that study is active
1038 SalomeApp_Study* study = getStudy();
1039 if ( !study ) return;
1041 // set interactive object
1043 Handle( SALOME_InteractiveObject ) anIO;
1045 if ( !myIO.IsNull() ) {
1046 actor->setIO( myIO );
1049 else if ( !myName.empty() ) {
1050 // workaround to allow selection of temporary objects
1051 static int tempId = 0;
1052 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toUtf8().data(), "GEOM", myName.c_str() );
1053 actor->setIO( anIO );
1056 // presentation study entry (empty for temporary objects like preview)
1057 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1058 // flag: temporary object
1059 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1060 // currently active view window's ID (-1 if no active view)
1061 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1063 // get presentation properties
1064 PropMap propMap = getObjectProperties( entry, myViewFrame );
1067 /////////////////////////////////////////////////////////////////////////
1068 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1069 // due to performance problem
1070 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1071 /////////////////////////////////////////////////////////////////////////
1072 if ( !actor->getTopo().IsSame( myShape ) )
1073 #ifdef LIMIT_DEFLECTION_FOR_VTK
1074 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1076 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1080 Material_Model material;
1081 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1082 std::vector<vtkProperty*> mprops;
1083 mprops.push_back( material.getMaterialVTKProperty( true ) );
1084 mprops.push_back( material.getMaterialVTKProperty( false) );
1085 actor->SetMaterial( mprops );
1087 // set iso-lines properties
1089 // - set number of iso-lines
1090 int nbIsos[2]= { 1, 1 };
1091 if ( HasNbIsos() ) {
1092 nbIsos[0] = GetNbIsos();
1093 nbIsos[1] = GetNbIsos();
1096 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1097 nbIsos[0] = isos[0].toInt();
1098 nbIsos[1] = isos[1].toInt();
1100 actor->SetNbIsos( nbIsos );
1102 // - set iso-lines width
1103 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1105 // - set iso-lines color
1106 if ( HasIsosColor() )
1107 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1109 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1110 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1115 // - same color for all sub-actors
1116 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1117 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1120 // shading color (for non-physical materials)
1121 if ( !material.isPhysical() ) {
1122 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1123 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1124 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1127 // - standalone edge color
1128 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1129 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1131 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1132 // - shared edges color ???
1133 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1135 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1136 // - free edges color ???
1137 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1140 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1141 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1144 // - color for edges in shading+edges mode
1145 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1146 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1148 // - color of labels (shape name)
1149 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1150 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1153 if( HasTransparency() ) {
1154 actor->SetOpacity( 1.0 - GetTransparency() );
1156 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1160 actor->SetWidth( HasWidth() ?
1161 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1163 // libe width from properties
1164 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1166 // set display vectors flag
1167 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1169 // set display vertices flag
1170 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1172 // set display name flag
1173 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1176 int displayMode = HasDisplayMode() ?
1177 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1179 // display mode from properties
1180 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1182 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1183 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1184 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1185 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1187 if ( displayMode == 2 )
1188 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1189 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1191 actor->setDisplayMode( displayMode );
1194 actor->PickableOn();
1196 actor->PickableOff();
1198 if ( create && !isTemporary && aMgrId != -1 ) {
1199 // set properties to the study
1200 study->setObjectProperties( aMgrId, entry, propMap );
1204 //=================================================================
1206 * GEOM_Displayer::updateDimensions
1207 * Creates or renews dimension presentation for the IO.
1209 //=================================================================
1210 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1211 SALOME_OCCPrs* thePrs,
1212 const gp_Ax3& theShapeLCS )
1214 SalomeApp_Study* aStudy = getStudy();
1220 if ( theIO.IsNull() )
1225 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1227 AIS_ListOfInteractive aListOfIO;
1229 anOccPrs->GetObjects( aListOfIO );
1231 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1233 // remove outdated presentations of dimensions
1234 for ( ; aIterateIO.More(); aIterateIO.Next() )
1236 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1237 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1242 aListOfIO.Remove( aIterateIO );
1244 if ( !aIterateIO.More() )
1250 // prepare dimension styling
1251 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1253 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1254 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1255 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1256 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1257 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1258 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1259 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1260 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1262 // restore dimension presentation from saved attribute or property data
1263 AIS_ListOfInteractive aRestoredDimensions;
1265 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1267 GEOM::propertyName( GEOM::Dimensions ),
1270 GEOMGUI_DimensionProperty aRecords;
1272 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1274 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1278 aRecords.LoadFromAttribute( theIO->getEntry() );
1281 // create up-to-date dimension presentations
1282 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1284 if ( !aRecords.IsVisible( aPrsIt ) )
1289 // init dimension by type
1290 Handle(AIS_Dimension) aPrs;
1291 switch( aRecords.GetType( aPrsIt ) )
1293 case GEOMGUI_DimensionProperty::DimensionType_Length :
1295 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1296 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1301 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1303 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1304 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1309 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1311 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1312 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1318 aPrs->SetOwner( theIO );
1320 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1322 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1324 aStyle->SetCommonColor( aColor );
1325 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1326 aStyle->MakeText3d( aUseText3d );
1327 aStyle->MakeTextShaded( Standard_True );
1328 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1329 aStyle->SetExtensionSize( fsize * 0.5 );
1330 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1331 aStyle->TextAspect()->SetHeight( fsize );
1332 aStyle->ArrowAspect()->SetLength( anArrowLength );
1333 aStyle->LineAspect()->SetWidth( aLineWidth );
1334 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1335 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1336 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1337 aPrs->SetDimensionAspect( aStyle );
1338 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1339 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1340 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1342 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1344 // show degree symbol for dimension instead of label "deg"
1345 if ( aUnitsAngle == "deg" )
1347 aPrs->SetSpecialSymbol(0xB0);
1348 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1349 aStyle->MakeUnitsDisplayed(Standard_False);
1353 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1354 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1359 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1362 aListOfIO.Append( aPrs );
1365 // update presentation
1368 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1370 anOccPrs->AddObject( aIterateIO.Value() );
1374 //=================================================================
1376 * GEOM_Displayer::Erase
1377 * Calls Erase() method for each object in the given list
1379 //=================================================================
1380 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1382 const bool updateViewer )
1384 SALOME_ListIteratorOfListIO Iter( theIOList );
1385 for ( ; Iter.More(); Iter.Next() )
1386 Erase( Iter.Value(), forced, false );
1392 //=================================================================
1394 * GEOM_Displayer::Redisplay
1395 * Calls Redisplay() method for each object in the given list
1397 //=================================================================
1398 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1399 const bool updateViewer,
1400 const bool checkActiveViewer )
1402 SALOME_ListIteratorOfListIO Iter( theIOList );
1403 for ( ; Iter.More(); Iter.Next() )
1404 Redisplay( Iter.Value(), false, checkActiveViewer );
1410 //=================================================================
1412 * GEOM_Displayer::Redisplay
1413 * Calls Redisplay() method for each object in the given list
1415 //=================================================================
1416 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1417 const bool theUpdateViewer,
1418 SALOME_View* theViewFrame )
1420 SALOME_ListIteratorOfListIO anIter( theIOList );
1421 for ( ; anIter.More(); anIter.Next() )
1423 Redisplay( anIter.Value(), false, theViewFrame );
1426 if ( theUpdateViewer )
1432 //=================================================================
1434 * GEOM_Displayer::Update
1435 * Update OCC presentation
1436 * [ Reimplemented from SALOME_Displayer ]
1438 //=================================================================
1439 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1441 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1442 SalomeApp_Study* study = getStudy();
1444 if ( !occPrs || myShape.IsNull() || !study )
1447 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1450 // specific processing for local coordinate system presentation
1453 TopoDS_Face aFace = TopoDS::Face( myShape );
1454 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1455 if ( !aPlane.IsNull() )
1457 gp_Ax3 aPos = aPlane->Pln().Position();
1458 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1460 Handle(GEOM_AISTrihedron) aTrh;
1462 if ( occPrs->IsNull() )
1464 // new presentation is being created
1465 aTrh = new GEOM_AISTrihedron( aPlc );
1466 occPrs->AddObject( aTrh );
1470 // presentation is being updated
1471 AIS_ListOfInteractive aList;
1472 occPrs->GetObjects( aList );
1473 AIS_ListIteratorOfListOfInteractive anIter( aList );
1474 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1475 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1479 if ( !aTrh.IsNull() ) {
1480 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1482 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1483 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1485 aTrh->SetWidth( GetWidth() );
1487 if ( !myIO.IsNull() )
1489 aTrh->setIO( myIO );
1490 aTrh->SetOwner( myIO );
1492 aTrh->SetComponent( aPlc );
1493 aTrh->SetToUpdate();
1495 occPrs->SetToActivate( ToActivate() );
1501 // processing for usual geometry presentation
1504 // if presentation is empty we try to create new one
1505 if ( occPrs->IsNull() )
1507 // create presentation (specific for vectors)
1508 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1509 : new GEOM_AISShape ( myShape, "" );
1511 if( myType == GEOM_FIELD_STEP )
1512 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1513 // update shape properties
1514 updateShapeProperties( AISShape, true );
1516 // add shape to the presentation
1517 occPrs->AddObject( AISShape );
1519 // In accordance with ToActivate() value object will be activated/deactivated
1520 // when it will be displayed
1521 occPrs->SetToActivate( ToActivate() );
1523 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1524 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1526 // create additional wireframe shape
1527 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1528 aWirePrs->SetWidth(AISShape->Width());
1529 if ( !myIO.IsNull() ) {
1530 aWirePrs->setIO( myIO );
1531 aWirePrs->SetOwner( myIO );
1534 // add shape to the presentation
1535 occPrs->AddObject( aWirePrs );
1538 // if presentation is found -> set again shape for it
1541 AIS_ListOfInteractive IOList;
1542 occPrs->GetObjects( IOList );
1543 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1544 for ( ; Iter.More(); Iter.Next() )
1546 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1547 if ( AISShape.IsNull() )
1550 // re-set shape (it might be changed)
1551 if ( AISShape->Shape() != myShape )
1552 AISShape->Set( myShape );
1554 // update shape properties
1555 updateShapeProperties( AISShape, false );
1558 AISShape->UpdateSelection();
1559 AISShape->SetToUpdate();
1563 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1567 //=================================================================
1569 * GEOM_Displayer::Update
1570 * Update VTK presentation
1571 * [ Reimplemented from SALOME_Displayer ]
1573 //=================================================================
1574 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1576 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1577 SalomeApp_Study* study = getStudy();
1579 if ( !vtkPrs || myShape.IsNull() || !study )
1582 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1585 // specific processing for local coordinate system presentation
1588 TopoDS_Face aFace = TopoDS::Face( myShape );
1589 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1590 if ( !aPlane.IsNull() ) {
1591 gp_Ax3 aPos = aPlane->Pln().Position();
1592 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1594 GEOM_VTKTrihedron* aTrh = 0;
1596 if ( vtkPrs->IsNull() ) {
1597 // new presentation is being created
1598 aTrh = GEOM_VTKTrihedron::New();
1599 vtkPrs->AddObject( aTrh );
1602 // presentation is being updated
1603 vtkActorCollection* actors = vtkPrs->GetObjects();
1605 actors->InitTraversal();
1606 vtkActor* a = actors->GetNextActor();
1607 while ( a && !aTrh ) {
1608 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1609 a = actors->GetNextActor();
1615 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1617 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1618 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1620 #ifdef VTK_TRIHEDRON_WIDTH
1622 // VSR: currently isn't supported
1624 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1626 aTrh->SetWidth( GetWidth() );
1629 if ( !myIO.IsNull() )
1630 aTrh->setIO( myIO );
1632 aTrh->SetPlacement( aPlc );
1639 // processing for usual geometry presentation
1642 // if presentation is empty we try to create new one
1643 if ( vtkPrs->IsNull() )
1646 GEOM_Actor* actor = GEOM_Actor::New();
1647 // update actor properties
1648 updateActorProperties( actor, true );
1649 // add actor to the presentation
1650 vtkPrs->AddObject( actor );
1653 // presentation is being updated
1654 vtkActorCollection* actors = vtkPrs->GetObjects();
1656 actors->InitTraversal();
1657 vtkActor* a = actors->GetNextActor();
1659 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1661 // update actor properties
1662 updateActorProperties( actor, false );
1663 a = actors->GetNextActor();
1671 //=================================================================
1673 * GEOM_Displayer::BuildPrs
1674 * Build presentation according to the current viewer type
1676 //=================================================================
1677 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1679 if ( theObj->_is_nil() )
1682 myViewFrame = GetActiveView();
1683 if ( myViewFrame == 0 )
1686 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1691 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1692 myType = theObj->GetType();
1694 // Update presentation
1700 //=================================================================
1702 * GEOM_Displayer::BuildPrs
1703 * Build presentation according to the current viewer type
1705 //=================================================================
1706 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1708 myViewFrame = GetActiveView();
1709 if ( theShape.IsNull() || myViewFrame == 0 )
1712 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1717 setShape( theShape );
1725 //=================================================================
1727 * GEOM_Displayer::buildPresentation
1728 * Builds/finds object's presentation for the current viewer
1729 * Calls corresponding Update() method by means of double dispatch
1732 //=================================================================
1733 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1734 SALOME_View* theViewFrame )
1736 SALOME_Prs* prs = 0;
1739 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1743 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1746 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1747 theIO->setEntry( entry.toUtf8().constData() );
1748 if ( !theIO.IsNull() )
1750 // set interactive object
1752 // Find SOBject (because shape should be published previously)
1755 _PTR(SObject) SO ( getStudy()->studyDS()->FindObjectID( theIO->getEntry() ) );
1758 // get CORBA reference to data object
1759 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1760 if ( !CORBA::is_nil( object ) )
1762 // downcast to GEOM base object
1763 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1764 if ( !GeomBaseObject->_is_nil() )
1766 myType = GeomBaseObject->GetType();
1768 // downcast to GEOM object
1769 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1770 if ( myType == GEOM_FIELD_STEP )
1772 // get the GEOM object from the field's shape
1773 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1774 if ( !GeomFieldStep->_is_nil() )
1776 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1777 if ( !GeomField->_is_nil() )
1778 GeomObject = GeomField->GetShape();
1781 // read the field step information
1782 readFieldStepInfo( GeomFieldStep );
1785 if ( !GeomObject->_is_nil() )
1787 CORBA::String_var name = GeomObject->GetName();
1788 theIO->setName( name );
1789 // finally set shape
1790 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1797 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1803 //=================================================================
1805 * GEOM_Displayer::buildSubshapePresentation
1806 * Builds/finds object's presentation for the current viewer
1807 * Calls corresponding Update() method by means of double dispatch
1808 * For not published objects (for Mantis issue 0020435)
1810 //=================================================================
1811 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1812 const QString& entry,
1813 SALOME_View* theViewFrame)
1815 SALOME_Prs* prs = 0;
1818 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1822 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1825 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1826 theIO->setEntry(entry.toUtf8().constData());
1827 if (!theIO.IsNull())
1829 // set interactive object
1831 // finally set shape
1833 myType = GEOM_SUBSHAPE;
1835 UpdatePrs(prs); // Update presentation by using of the double dispatch
1841 //=================================================================
1843 * GEOM_Displayer::internalReset
1844 * Resets internal data
1847 //=================================================================
1848 void GEOM_Displayer::internalReset()
1853 myFieldDataType = GEOM::FDT_Double;
1854 myFieldDimension = 0;
1855 myFieldStepData.clear();
1856 myFieldStepName.Clear();
1857 myFieldStepRangeMin = 0;
1858 myFieldStepRangeMax = 0;
1861 //=================================================================
1863 * GEOM_Displayer::LocalSelection
1864 * Activate selection of CAD shapes with activisation of selection
1865 * of their sub-shapes (with opened local context for OCC viewer)
1867 //=================================================================
1868 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1870 SUIT_Session* session = SUIT_Session::session();
1871 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1875 LightApp_SelectionMgr* sm = app->selectionMgr();
1877 // remove all filters from selection
1880 SALOME_View* vf = GetActiveView();
1882 if (!theIO.IsNull() && !vf->isVisible(theIO))
1884 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1885 vf->LocalSelection( prs, modes );
1886 delete prs; // delete presentation because displayer is its owner
1890 //=================================================================
1892 * GEOM_Displayer::LocalSelection
1893 * Activate selection of CAD shapes with activisation of selection
1894 * of their sub-shapes (with opened local context for OCC viewer)
1896 //=================================================================
1897 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1899 std::list<int> modes;
1900 modes.push_back( theMode );
1901 LocalSelection( theIO, modes );
1904 //=================================================================
1906 * GEOM_Displayer::globalSelection
1907 * Activate selection of CAD shapes without activisation of selection
1908 * of their sub-shapes (without opened local context for OCC viewer)
1910 //=================================================================
1911 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1913 TColStd_MapOfInteger aModes;
1914 aModes.Add( theMode );
1915 GlobalSelection( aModes, update );
1918 //=================================================================
1920 * GEOM_Displayer::globalSelection
1921 * Activate selection of CAD shapes without activisation of selection
1922 * of their sub-shapes (without opened local context for OCC viewer)
1924 //=================================================================
1925 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1926 const bool update, const QList<int>* theSubShapes )
1928 SUIT_Session* session = SUIT_Session::session();
1929 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1933 SALOME_View* vf = GetActiveView();
1937 // Close local context
1938 vf->GlobalSelection( update );
1940 // Set selection filters in accordance with current mode
1941 LightApp_SelectionMgr* sm = app->selectionMgr();
1945 // Remove from selection temporary objects if necessary
1946 if ( !theModes.Contains( GEOM_PREVIEW ) )
1947 clearTemporary( sm );
1949 //@ aSel->ClearIndex();
1953 // Remove filters from AIS_InteractiveContext
1954 Handle(AIS_InteractiveContext) ic;
1955 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1958 ic = viewer->getAISContext();
1960 ic->RemoveFilters();
1963 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1966 SUIT_SelectionFilter* aFilter;
1967 if ( theModes.Extent() == 1 )
1969 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1971 if ( aMode == GEOM_COMPOUNDFILTER )
1972 aFilter = getComplexFilter( theSubShapes );
1974 aFilter = getFilter( aMode );
1976 else if ( theModes.Extent() > 1 )
1978 TColStd_MapOfInteger aTopAbsModes;
1979 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1980 QList<SUIT_SelectionFilter*> aListOfFilters;
1981 for ( ; anIter.More(); anIter.Next() )
1983 SUIT_SelectionFilter* aFilter;
1984 int aMode = anIter.Key();
1985 if ( aMode == GEOM_COMPOUNDFILTER )
1986 aFilter = getComplexFilter( theSubShapes );
1988 aFilter = getFilter( aMode );
1991 aListOfFilters.append( aFilter );
1994 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
2001 sm->installFilter( aFilter );
2004 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
2005 ic->AddFilter( anOCCFilter );
2010 //=================================================================
2012 * GEOM_Displayer::LocalSelection
2013 * Activate selection of CAD shapes with activisation of selection
2014 * of their sub-shapes (with opened local context for OCC viewer)
2016 //=================================================================
2017 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2019 SALOME_ListIteratorOfListIO Iter( theIOList );
2020 for ( ; Iter.More(); Iter.Next() )
2021 LocalSelection( Iter.Value(), modes );
2024 //=================================================================
2026 * GEOM_Displayer::LocalSelection
2027 * Activate selection of CAD shapes with activisation of selection
2028 * of their sub-shapes (with opened local context for OCC viewer)
2030 //=================================================================
2031 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2033 std::list<int> modes;
2034 modes.push_back( theMode );
2035 LocalSelection( theIOList, modes );
2038 //=================================================================
2040 * GEOM_Displayer::BeforeDisplay
2041 * Called before displaying of pars. Close local context
2042 * [ Reimplemented from SALOME_Displayer ]
2044 //=================================================================
2045 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2047 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2050 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2053 if ( ic->HasOpenedContext() )
2054 ic->CloseAllContexts(Standard_True);
2059 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2063 // visualize annotations for displayed presentation
2064 SUIT_Session* session = SUIT_Session::session();
2065 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2066 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2068 if ( !myIsRedisplayed ) {
2069 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2071 aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2076 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2078 LightApp_Displayer::BeforeErase( v, p );
2079 releaseTextures( p );
2082 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2084 LightApp_Displayer::AfterErase( v, p );
2087 if ( !myIsRedisplayed ) {
2088 // hide annotations for erased presentation
2089 SUIT_Session* session = SUIT_Session::session();
2090 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2091 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2093 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2097 //=================================================================
2099 * GEOM_Displayer::SetColor
2100 * Set color for shape displaying. If it is equal -1 then default color is used.
2101 * Available values are from Quantity_NameOfColor enumeration
2103 //=================================================================
2104 void GEOM_Displayer::SetColor( const int color )
2111 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2115 int GEOM_Displayer::GetColor() const
2120 bool GEOM_Displayer::HasColor() const
2122 return myColor != -1;
2125 void GEOM_Displayer::UnsetColor()
2129 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2130 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2131 myShadingColor = SalomeApp_Tools::color( col );
2134 //=================================================================
2136 * GEOM_Displayer::SetTransparency
2137 * Set transparency for shape displaying.
2139 //=================================================================
2140 double GEOM_Displayer::SetTransparency( const double transparency )
2142 double prevTransparency = myTransparency;
2143 myTransparency = transparency;
2144 return prevTransparency;
2147 //=================================================================
2149 * GEOM_Displayer::GetTransparency
2150 * Get transparency for shape displaying.
2152 //=================================================================
2153 double GEOM_Displayer::GetTransparency() const
2155 return myTransparency;
2158 //=================================================================
2160 * GEOM_Displayer::HasTransparency
2161 * Check if transparency for shape displaying is set.
2163 //=================================================================
2164 bool GEOM_Displayer::HasTransparency() const
2166 return myTransparency >= 0;
2169 //=================================================================
2171 * GEOM_Displayer::UnsetTransparency
2172 * Unset transparency for shape displaying.
2174 //=================================================================
2175 double GEOM_Displayer::UnsetTransparency()
2177 return SetTransparency( -1 );
2180 //=================================================================
2182 * GEOM_Displayer::SetTexture
2184 //=================================================================
2185 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2187 myTexture = texureFileName;
2190 bool GEOM_Displayer::HasTexture() const
2192 return myTexture != "";
2195 std::string GEOM_Displayer::GetTexture() const
2200 //=================================================================
2202 * GEOM_Displayer::SetWidth
2203 * Set width of shape displaying. If it is equal -1 then default width is used.
2205 //=================================================================
2206 void GEOM_Displayer::SetWidth( const double width )
2211 double GEOM_Displayer::GetWidth() const
2216 bool GEOM_Displayer::HasWidth() const
2218 return myWidth != -1;
2221 void GEOM_Displayer::UnsetWidth()
2226 int GEOM_Displayer::GetIsosWidth() const
2231 void GEOM_Displayer::SetIsosWidth(const int width)
2233 myIsosWidth = width;
2236 bool GEOM_Displayer::HasIsosWidth() const
2238 return myIsosWidth != -1;
2241 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2243 int prevNbIsos = myNbIsos;
2248 int GEOM_Displayer::UnsetNbIsos()
2250 return SetNbIsos( -1 );
2253 int GEOM_Displayer::GetNbIsos() const
2258 bool GEOM_Displayer::HasNbIsos() const
2260 return myNbIsos >= 0;
2263 int GEOM_Displayer::SetIsosColor( const int color )
2265 int prevColor = myIsosColor;
2266 myIsosColor = color;
2270 int GEOM_Displayer::GetIsosColor() const
2275 bool GEOM_Displayer::HasIsosColor() const
2277 return myIsosColor != -1;
2280 int GEOM_Displayer::UnsetIsosColor()
2282 return SetIsosColor( -1 );
2285 //=================================================================
2287 * GEOM_Displayer::SetToActivate
2288 * This method is used for activisation/deactivisation of objects to be displayed
2290 //=================================================================
2291 void GEOM_Displayer::SetToActivate( const bool toActivate )
2293 myToActivate = toActivate;
2295 bool GEOM_Displayer::ToActivate() const
2297 return myToActivate;
2300 //=================================================================
2302 * GEOM_Displayer::clearTemporary
2303 * Removes from selection temporary objects
2305 //=================================================================
2306 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2308 SALOME_ListIO selected, toSelect;
2309 theSelMgr->selectedObjects( selected );
2311 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2312 Handle(SALOME_InteractiveObject) io = it.Value();
2313 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2314 toSelect.Append( it.Value() );
2317 theSelMgr->setSelectedObjects( toSelect, true );
2320 void GEOM_Displayer::SetName( const char* theName )
2325 void GEOM_Displayer::UnsetName()
2330 SalomeApp_Study* GEOM_Displayer::getStudy() const
2332 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2335 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2340 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2345 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2346 const int theFieldDimension,
2347 const QList<QVariant>& theFieldStepData,
2348 const TCollection_AsciiString& theFieldStepName,
2349 const double theFieldStepRangeMin,
2350 const double theFieldStepRangeMax )
2352 myFieldDataType = theFieldDataType;
2353 myFieldDimension = theFieldDimension;
2354 myFieldStepData = theFieldStepData;
2355 myFieldStepName = theFieldStepName;
2356 myFieldStepRangeMin = theFieldStepRangeMin;
2357 myFieldStepRangeMax = theFieldStepRangeMax;
2360 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2362 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toUtf8() );
2363 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2364 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2365 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2366 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2367 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2370 int GEOM_Displayer::SetDisplayMode( const int theMode )
2372 int aPrevMode = myDisplayMode;
2373 if ( theMode != -1 ) {
2374 myDisplayMode = theMode;
2375 myHasDisplayMode = true;
2383 int GEOM_Displayer::GetDisplayMode() const
2385 return myDisplayMode;
2388 int GEOM_Displayer::UnsetDisplayMode()
2390 int aPrevMode = myDisplayMode;
2391 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2392 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2393 myHasDisplayMode = false;
2397 bool GEOM_Displayer::HasDisplayMode() const
2399 return myHasDisplayMode;
2402 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2404 static QList<QColor> colors;
2406 if ( colors.isEmpty() ) {
2408 for (int s = 0; s < 2 ; s++)
2410 for (int v = 100; v >= 40; v = v - 20)
2412 for (int h = 0; h < 359 ; h = h + 60)
2414 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2420 static int currentColor = randomize( colors.size() );
2422 SALOMEDS::Color color;
2423 color.R = (double)colors[currentColor].red() / 255.0;
2424 color.G = (double)colors[currentColor].green() / 255.0;
2425 color.B = (double)colors[currentColor].blue() / 255.0;
2427 currentColor = (currentColor+1) % colors.count();
2432 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2435 int aTolerance = 64;
2436 int anIterations = 0;
2442 if( anIterations % aPeriod == 0 )
2445 if( aTolerance < 1 )
2448 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2450 aHue = (int)( 360.0 * rand() / RAND_MAX );
2451 //std::cout << "Hue = " << aHue << std::endl;
2453 //std::cout << "Auto colors : ";
2455 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2456 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2457 for( ; it != itEnd; ++it )
2459 SALOMEDS::Color anAutoColor = *it;
2460 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2463 aQColor.getHsv( &h, &s, &v );
2464 //std::cout << h << " ";
2465 if( abs( h - aHue ) < aTolerance )
2468 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2472 //std::cout << std::endl;
2478 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2480 aColor.setHsv( aHue, 255, 255 );
2482 SALOMEDS::Color aSColor;
2483 aSColor.R = (double)aColor.red() / 255.0;
2484 aSColor.G = (double)aColor.green() / 255.0;
2485 aSColor.B = (double)aColor.blue() / 255.0;
2490 PropMap GEOM_Displayer::getObjectProperties( const QString& entry,
2493 // get default properties for the explicitly specified default view type
2494 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2496 if ( getStudy() && view ) {
2497 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2498 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2499 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2501 if ( viewModel && viewId != -1 ) {
2502 // get properties from the study
2503 PropMap storedMap = getStudy()->getObjectProperties( viewId, entry );
2504 // overwrite default properties from stored ones (that are specified)
2505 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2506 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2507 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2508 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2510 // ... specific processing for color
2511 // ... current implementation is to use same stored color for all aspects
2512 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2513 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2514 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2515 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2516 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2517 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2518 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2521 if ( !entry.isEmpty() ) {
2522 // get CORBA reference to geom object
2523 _PTR(SObject) SO( getStudy()->studyDS()->FindObjectID( entry.toStdString() ) );
2525 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2526 if ( !CORBA::is_nil( object ) ) {
2527 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2528 if ( !CORBA::is_nil( geomObject ) ) { // to check
2529 // check that geom object has color properly set
2530 bool hasColor = false;
2531 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2532 // set color from geometry object (only once, if it is not yet set in GUI)
2533 // current implementation is to use same color for all aspects
2534 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2535 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2536 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2537 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2538 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2539 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2540 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2541 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2543 // check that object has point marker properly set
2544 GEOM::marker_type mType = geomObject->GetMarkerType();
2545 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2546 int mTextureId = geomObject->GetMarkerTexture();
2547 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2548 ( mType == GEOM::MT_USER && mTextureId > 0 );
2549 // set point marker from geometry object (only once, if it is not yet set in GUI)
2550 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2551 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2553 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2554 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2556 else if ( mType == GEOM::MT_USER ) {
2558 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2570 PropMap GEOM_Displayer::getDefaultPropertyMap()
2574 // get resource manager
2575 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2577 // fill in the properties map with default values
2579 // - visibility (false by default)
2580 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2582 // - nb isos (take default value from preferences)
2583 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2584 QString( "%1%2%3" ).
2585 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2586 arg( GEOM::subSectionSeparator() ).
2587 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2589 // - transparency (opacity = 1-transparency)
2590 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2591 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2593 // - display mode (take default value from preferences)
2594 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2595 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2597 // - show edges direction flag (false by default)
2598 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2600 // - show vertices flag (false by default)
2601 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2603 // - show name flag (false by default)
2604 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2606 // - shading color (take default value from preferences)
2607 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2608 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2610 // - wireframe color (take default value from preferences)
2611 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2612 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2614 // - standalone edges color (take default value from preferences)
2615 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2616 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2618 // - free boundaries color (take default value from preferences)
2619 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2620 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2622 // - points color (take default value from preferences)
2623 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2624 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2626 // - isos color (take default value from preferences)
2627 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2628 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2630 // - outlines color (take default value from preferences)
2631 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2632 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2634 // - deflection coefficient (take default value from preferences)
2635 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2636 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2638 // - material (take default value from preferences)
2639 Material_Model material;
2640 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2641 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2643 // - edge width (take default value from preferences)
2644 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2645 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2647 // - isos width (take default value from preferences)
2648 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2649 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2651 // - point marker (take default value from preferences)
2652 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2653 QString( "%1%2%3" ).
2654 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2655 arg( GEOM::subSectionSeparator() ).
2656 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2658 // - top-level flag (false by default)
2659 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2664 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2665 SALOMEDS::Color aSColor;
2668 SUIT_Session* session = SUIT_Session::session();
2669 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2671 if ( app && !theGeomObject->_is_nil()) {
2672 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2675 _PTR(Study) aStudy = study->studyDS();
2676 aSColor = theGeomObject->GetColor();
2677 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2679 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2680 bool general_autocolor = true;
2681 #else // auto-color for groups only
2682 bool general_autocolor = false;
2683 #endif // GENERAL_AUTOCOLOR
2684 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2685 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2686 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2687 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2688 aSColor = getPredefinedUniqueColor();
2690 #else // old algorithm for auto-colors
2691 QList<SALOMEDS::Color> aReservedColors;
2692 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2693 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2694 if ( aMainSObject ) {
2695 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2696 for ( ; it->More(); it->Next() ) {
2697 _PTR(SObject) aChildSObject( it->Value() );
2698 GEOM::GEOM_Object_var aChildObject =
2699 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2700 if ( CORBA::is_nil( aChildObject ) )
2703 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2704 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2705 aReservedColors.append( aReservedColor );
2708 aSColor = getUniqueColor( aReservedColors );
2710 #endif // SIMPLE_AUTOCOLOR
2720 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2721 const bool eraseOnlyChildren)
2723 LightApp_DataObject* parent = getStudy()->findObjectByEntry(theIO->getEntry());
2728 // Erase from all views
2729 QList<SALOME_View*> views;
2731 ViewManagerList vmans = myApp->viewManagers();
2732 SUIT_ViewManager* vman;
2733 foreach ( vman, vmans ) {
2734 SUIT_ViewModel* vmod = vman->getViewModel();
2735 view = dynamic_cast<SALOME_View*> ( vmod );
2737 views.append( view );
2740 if( views.count() == 0 )
2743 //Erase childrens w/o update views
2744 DataObjectList listObj = parent->children( true );
2745 SUIT_DataObject* obj;
2746 foreach( obj, listObj ) {
2747 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2749 foreach ( view, views ) {
2750 Handle(SALOME_InteractiveObject) anIO =
2751 new SALOME_InteractiveObject(qUtf8Printable(l_obj->entry()), "GEOM", "");
2752 Erase(anIO, false, false, view);
2756 //Erase parent with view update or repaint views
2757 foreach ( view, views ) {
2758 if(!eraseOnlyChildren)
2759 Erase(theIO, false, true, view);
2765 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2767 if( theGeomFieldStep->_is_nil() )
2770 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2771 if( aGeomField->_is_nil() )
2774 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2775 if( aGeomFieldShape->_is_nil() )
2778 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2779 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2780 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2782 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2784 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2786 int aFieldDimension = aGeomField->GetDimension();
2788 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2789 int aFieldNbComponents = aFieldComponents->length();
2791 QList<QVariant> aFieldStepData;
2792 if( aFieldDataType == GEOM::FDT_Bool )
2794 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2795 if ( !aGeomBoolFieldStep->_is_nil() )
2797 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2798 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2799 aFieldStepData << (bool)aValues[i];
2802 else if( aFieldDataType == GEOM::FDT_Int )
2804 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2805 if ( !aGeomIntFieldStep->_is_nil() )
2807 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2808 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2809 aFieldStepData << (qlonglong)aValues[i];
2812 else if( aFieldDataType == GEOM::FDT_Double )
2814 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2815 if ( !aGeomDoubleFieldStep->_is_nil() )
2817 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2818 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2819 aFieldStepData << (double)aValues[i];
2822 else if( aFieldDataType == GEOM::FDT_String )
2824 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2825 if ( !aGeomStringFieldStep->_is_nil() )
2827 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2828 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2829 aFieldStepData << QString( aValues[i] );
2833 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2834 aFieldStepData = groupFieldData( aFieldStepData,
2836 aFieldDataType == GEOM::FDT_String,
2838 aFieldStepRangeMax );
2840 setFieldStepInfo( aFieldDataType,
2845 aFieldStepRangeMax );
2848 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2849 const int theFieldNbComponents,
2850 const bool theIsString,
2851 double& theFieldStepRangeMin,
2852 double& theFieldStepRangeMax )
2854 QList<QVariant> aResultList;
2855 theFieldStepRangeMin = 0;
2856 theFieldStepRangeMax = 0;
2858 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2861 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2863 QList<QVariant> aGroupedList;
2865 bool anIsBoolean = false;
2866 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2869 QStringList aStringList;
2871 int aBaseIndex = aSubShape * theFieldNbComponents;
2872 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2874 int anIndex = aComponent + aBaseIndex;
2876 const QVariant& aVariant = theFieldStepData[ anIndex ];
2879 if( aVariant.type() == QVariant::String )
2880 aStringList << aVariant.toString();
2885 if( aVariant.type() == QVariant::Bool )
2887 aValue = aVariant.toBool() ? 1.0 : 0.0;
2893 if( aVariant.type() == QVariant::LongLong )
2894 aValue = double( aVariant.toLongLong() );
2895 else if( aVariant.type() == QVariant::Double )
2896 aValue = aVariant.toDouble();
2897 aNorm += aValue * aValue;
2903 aGroupedList << aStringList.join( "\n" );
2907 aNorm /= theFieldNbComponents;
2909 aNorm = pow( aNorm, 0.5 );
2911 if( aGroupedList.isEmpty() )
2912 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2915 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2916 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2919 aGroupedList << aNorm;
2925 theFieldStepRangeMin = 0.0;
2926 theFieldStepRangeMax = 1.0;
2929 SUIT_Session* session = SUIT_Session::session();
2930 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2931 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2933 QListIterator<QVariant> anIter( aGroupedList );
2934 while( anIter.hasNext() )
2936 const QVariant& aVariant = anIter.next();
2938 aResultList << aVariant;
2942 Quantity_Color aColor;
2943 if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2944 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2945 aResultList << aQColor;
2951 void GEOM_Displayer::UpdateColorScale()
2953 if ( !myUpdateColorScale )
2956 SUIT_Session* session = SUIT_Session::session();
2957 SUIT_Application* app = session->activeApplication();
2960 Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject();
2962 QList<SUIT_ViewWindow*> windows = app->desktop()->windows();
2963 foreach( SUIT_ViewWindow* window, windows )
2965 OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>( window );
2966 if ( !occWindow ) continue;
2967 if ( !occWindow->getViewManager() ) continue;
2968 if ( !window->getViewManager() ) continue;
2969 if ( !window->getViewManager()->getViewModel() ) continue;
2970 SOCC_Viewer* view = dynamic_cast<SOCC_Viewer*>( window->getViewManager()->getViewModel() );
2971 if ( !view ) continue;
2972 Handle(V3d_Viewer) viewer = view->getViewer3d();
2973 if ( !io.IsNull() && view->isVisible( io ) )
2975 bool visible = false;
2976 SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( view->CreatePrs( io->getEntry() ) );
2979 AIS_ListOfInteractive presentations;
2980 prs->GetObjects( presentations );
2981 AIS_ListIteratorOfListOfInteractive iter( presentations );
2982 for ( ; iter.More(); iter.Next() )
2984 Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() );
2985 if ( shape.IsNull() ) continue;
2986 GEOM::field_data_type fieldDataType;
2988 QList<QVariant> fieldStepData;
2989 TCollection_AsciiString fieldStepName;
2990 Standard_Real fieldStepRangeMin, fieldStepRangeMax;
2991 shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData,
2992 fieldStepName, fieldStepRangeMin, fieldStepRangeMax );
2993 visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String;
2996 SUIT_Session* session = SUIT_Session::session();
2997 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2999 Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3000 Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3001 Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3002 Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3003 Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3004 Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3006 Standard_Integer viewWidth = 0, viewHeight = 0;
3007 occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight );
3009 Handle(AIS_ColorScale) colorScale = view->getColorScale();
3011 colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos );
3012 colorScale->SetBreadth( viewWidth * width );
3013 colorScale->SetHeight( viewHeight * height );
3014 colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax );
3015 colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals );
3016 colorScale->SetTextHeight( textHeight );
3017 colorScale->SetTitle( fieldStepName );
3021 view->setColorScaleShown( visible );
3022 } // if ( view->isVisible( io ) )
3025 view->setColorScaleShown( false );
3027 } // foreach( SUIT_ViewWindow* window, windows )
3030 bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049
3032 bool previous = myUpdateColorScale;
3033 myUpdateColorScale = toUpdate;
3034 if ( myUpdateColorScale && !previous )