1 // Copyright (C) 2007-2016 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++ ).toLatin1().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 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
840 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
841 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
842 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
844 // - standalone edges color
845 anAspect = AISShape->Attributes()->WireAspect();
846 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
847 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
848 AISShape->Attributes()->SetWireAspect( anAspect );
850 // - color for edges in shading+edges mode
851 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
853 // - color of labels (textual fields and shape name)
854 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
857 int displayMode = HasDisplayMode() ?
858 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
860 // display mode from properties
861 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
862 AISShape->SetDisplayMode( displayMode );
864 // - face boundaries color and line width
865 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
866 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
867 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
868 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
870 // set display vectors flag
871 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
873 // set display vertices flag
874 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
875 AISShape->SetDisplayVertices( isVerticesMode );
877 // set display name flag
878 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
879 AISShape->SetDisplayName( isNameMode );
882 if( HasTransparency() ) {
883 AISShape->SetTransparency( GetTransparency() );
885 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
888 // set iso properties
889 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
890 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
891 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
892 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
893 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
894 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
896 if ( HasIsosColor() ) {
897 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
898 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
901 uIsoAspect->SetColor( isosColor );
902 vIsoAspect->SetColor( isosColor );
905 if ( HasIsosWidth() ) {
906 uIsoAspect->SetWidth( GetIsosWidth() );
907 vIsoAspect->SetWidth( GetIsosWidth() );
910 uIsoAspect->SetWidth( isosWidth );
911 vIsoAspect->SetWidth( isosWidth );
915 uIsoAspect->SetNumber( GetNbIsos() );
916 vIsoAspect->SetNumber( GetNbIsos() );
919 uIsoAspect->SetNumber( uIsos );
920 vIsoAspect->SetNumber( vIsos );
923 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
924 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
926 // set deflection coefficient
927 // ... to avoid to small values of the coefficient, its lower value is limited
928 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
932 if ( HasTexture() ) {
933 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
934 aImagePath = GetTexture().c_str();
935 if ( ! entry.isEmpty() ) {
936 // check that study is active
937 SalomeApp_Study* study = getStudy();
939 // Store the texture in object properties for next displays
940 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
941 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
943 // Update properties map
944 propMap = getObjectProperties( entry, myViewFrame );
949 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
952 Handle(Image_PixMap) aPixmap;
953 if ( !aImagePath.isEmpty() )
954 aPixmap = cacheTextureFor( aImagePath, AISShape );
956 aPixmap = getDefaultTexture();
958 // apply image to shape
959 if ( !aPixmap.IsNull() ) {
960 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) );
962 if ( displayMode == GEOM_AISShape::TexturedShape )
963 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
965 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
968 AISShape->SetWidth( HasWidth() ?
969 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
971 // libe width from properties
972 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
974 // set top-level flag
975 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
977 // set point marker (for vertex / compound of vertices only)
978 if ( onlyVertex || isVerticesMode ) {
979 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
980 if ( aList.size() == 2 ) {
981 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
982 int aTypeOfMarker = aList[0].toInt();
983 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
984 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
985 anAspect->SetScale( aScaleOfMarker );
986 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
987 anAspect->SetColor( HasColor() ?
988 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
989 (Quantity_NameOfColor)GetColor() :
990 // color from properties
991 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
992 AISShape->Attributes()->SetPointAspect( anAspect );
994 else if ( aList.size() == 1 ) {
995 // custom marker string contains "IdOfTexture"
996 int textureId = aList[0].toInt();
997 Standard_Integer aWidth, aHeight;
998 Handle(TColStd_HArray1OfByte) aTexture =
999 GeometryGUI::getTexture( textureId, aWidth, aHeight );
1000 if ( !aTexture.IsNull() ) {
1001 Handle(Prs3d_PointAspect) aTextureAspect =
1002 new Prs3d_PointAspect( HasColor() ?
1003 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1004 (Quantity_NameOfColor)GetColor() :
1005 // color from properties
1006 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1009 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1014 // set field step data
1015 AISShape->setFieldStepInfo( myFieldDataType,
1019 myFieldStepRangeMin,
1020 myFieldStepRangeMax );
1022 if ( create && !isTemporary && aMgrId != -1 ) {
1023 // set properties to the study
1024 study->setObjectProperties( aMgrId, entry, propMap );
1027 // AISShape->SetName(???); ??? necessary to set name ???
1030 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1032 // check that actor is not null
1033 if ( !actor ) return;
1035 // check that study is active
1036 SalomeApp_Study* study = getStudy();
1037 if ( !study ) return;
1039 // set interactive object
1041 Handle( SALOME_InteractiveObject ) anIO;
1043 if ( !myIO.IsNull() ) {
1044 actor->setIO( myIO );
1047 else if ( !myName.empty() ) {
1048 // workaround to allow selection of temporary objects
1049 static int tempId = 0;
1050 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1051 actor->setIO( anIO );
1054 // presentation study entry (empty for temporary objects like preview)
1055 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1056 // flag: temporary object
1057 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1058 // currently active view window's ID (-1 if no active view)
1059 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1061 // get presentation properties
1062 PropMap propMap = getObjectProperties( entry, myViewFrame );
1065 /////////////////////////////////////////////////////////////////////////
1066 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1067 // due to performance problem
1068 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1069 /////////////////////////////////////////////////////////////////////////
1070 if ( !actor->getTopo().IsSame( myShape ) )
1071 #ifdef LIMIT_DEFLECTION_FOR_VTK
1072 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1074 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1078 Material_Model material;
1079 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1080 std::vector<vtkProperty*> mprops;
1081 mprops.push_back( material.getMaterialVTKProperty( true ) );
1082 mprops.push_back( material.getMaterialVTKProperty( false) );
1083 actor->SetMaterial( mprops );
1085 // set iso-lines properties
1087 // - set number of iso-lines
1088 int nbIsos[2]= { 1, 1 };
1089 if ( HasNbIsos() ) {
1090 nbIsos[0] = GetNbIsos();
1091 nbIsos[1] = GetNbIsos();
1094 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1095 nbIsos[0] = isos[0].toInt();
1096 nbIsos[1] = isos[1].toInt();
1098 actor->SetNbIsos( nbIsos );
1100 // - set iso-lines width
1101 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1103 // - set iso-lines color
1104 if ( HasIsosColor() )
1105 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1107 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1108 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1113 // - same color for all sub-actors
1114 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1115 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1118 // shading color (for non-physical materials)
1119 if ( !material.isPhysical() ) {
1120 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1121 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1122 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1125 // - standalone edge color
1126 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1127 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1129 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1130 // - shared edges color ???
1131 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1133 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1134 // - free edges color ???
1135 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1138 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1139 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1142 // - color for edges in shading+edges mode
1143 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1144 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1146 // - color of labels (shape name)
1147 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1148 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1151 if( HasTransparency() ) {
1152 actor->SetOpacity( 1.0 - GetTransparency() );
1154 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1158 actor->SetWidth( HasWidth() ?
1159 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1161 // libe width from properties
1162 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1164 // set display vectors flag
1165 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1167 // set display vertices flag
1168 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1170 // set display name flag
1171 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1174 int displayMode = HasDisplayMode() ?
1175 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1177 // display mode from properties
1178 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1180 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1181 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1182 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1183 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1185 if ( displayMode == 2 )
1186 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1187 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1189 actor->setDisplayMode( displayMode );
1192 actor->PickableOn();
1194 actor->PickableOff();
1196 if ( create && !isTemporary && aMgrId != -1 ) {
1197 // set properties to the study
1198 study->setObjectProperties( aMgrId, entry, propMap );
1202 //=================================================================
1204 * GEOM_Displayer::updateDimensions
1205 * Creates or renews dimension presentation for the IO.
1207 //=================================================================
1208 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1209 SALOME_OCCPrs* thePrs,
1210 const gp_Ax3& theShapeLCS )
1212 SalomeApp_Study* aStudy = getStudy();
1218 if ( theIO.IsNull() )
1223 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1225 AIS_ListOfInteractive aListOfIO;
1227 anOccPrs->GetObjects( aListOfIO );
1229 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1231 // remove outdated presentations of dimensions
1232 for ( ; aIterateIO.More(); aIterateIO.Next() )
1234 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1235 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1240 aListOfIO.Remove( aIterateIO );
1242 if ( !aIterateIO.More() )
1248 // prepare dimension styling
1249 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1251 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1252 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1253 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1254 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1255 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1256 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1257 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1258 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1260 // restore dimension presentation from saved attribute or property data
1261 AIS_ListOfInteractive aRestoredDimensions;
1263 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1265 GEOM::propertyName( GEOM::Dimensions ),
1268 GEOMGUI_DimensionProperty aRecords;
1270 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1272 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1276 aRecords.LoadFromAttribute( theIO->getEntry() );
1279 // create up-to-date dimension presentations
1280 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1282 if ( !aRecords.IsVisible( aPrsIt ) )
1287 // init dimension by type
1288 Handle(AIS_Dimension) aPrs;
1289 switch( aRecords.GetType( aPrsIt ) )
1291 case GEOMGUI_DimensionProperty::DimensionType_Length :
1293 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1294 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1299 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1301 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1302 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1307 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1309 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1310 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1316 aPrs->SetOwner( theIO );
1318 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1320 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1322 aStyle->SetCommonColor( aColor );
1323 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1324 aStyle->MakeText3d( aUseText3d );
1325 aStyle->MakeTextShaded( Standard_True );
1326 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1327 aStyle->SetExtensionSize( fsize * 0.5 );
1328 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1329 aStyle->TextAspect()->SetHeight( fsize );
1330 aStyle->ArrowAspect()->SetLength( anArrowLength );
1331 aStyle->LineAspect()->SetWidth( aLineWidth );
1332 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1333 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1334 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1335 aPrs->SetDimensionAspect( aStyle );
1336 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1337 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1338 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1340 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1342 // show degree symbol for dimension instead of label "deg"
1343 if ( aUnitsAngle == "deg" )
1345 aPrs->SetSpecialSymbol(0xB0);
1346 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1347 aStyle->MakeUnitsDisplayed(Standard_False);
1351 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1352 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1357 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1360 aListOfIO.Append( aPrs );
1363 // update presentation
1366 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1368 anOccPrs->AddObject( aIterateIO.Value() );
1372 //=================================================================
1374 * GEOM_Displayer::Erase
1375 * Calls Erase() method for each object in the given list
1377 //=================================================================
1378 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1380 const bool updateViewer )
1382 SALOME_ListIteratorOfListIO Iter( theIOList );
1383 for ( ; Iter.More(); Iter.Next() )
1384 Erase( Iter.Value(), forced, false );
1390 //=================================================================
1392 * GEOM_Displayer::Redisplay
1393 * Calls Redisplay() method for each object in the given list
1395 //=================================================================
1396 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1397 const bool updateViewer,
1398 const bool checkActiveViewer )
1400 SALOME_ListIteratorOfListIO Iter( theIOList );
1401 for ( ; Iter.More(); Iter.Next() )
1402 Redisplay( Iter.Value(), false, checkActiveViewer );
1408 //=================================================================
1410 * GEOM_Displayer::Redisplay
1411 * Calls Redisplay() method for each object in the given list
1413 //=================================================================
1414 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1415 const bool theUpdateViewer,
1416 SALOME_View* theViewFrame )
1418 SALOME_ListIteratorOfListIO anIter( theIOList );
1419 for ( ; anIter.More(); anIter.Next() )
1421 Redisplay( anIter.Value(), false, theViewFrame );
1424 if ( theUpdateViewer )
1430 //=================================================================
1432 * GEOM_Displayer::Update
1433 * Update OCC presentaion
1434 * [ Reimplemented from SALOME_Displayer ]
1436 //=================================================================
1437 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1439 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1440 SalomeApp_Study* study = getStudy();
1442 if ( !occPrs || myShape.IsNull() || !study )
1445 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1448 // specific processing for local coordinate system presentation
1451 TopoDS_Face aFace = TopoDS::Face( myShape );
1452 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1453 if ( !aPlane.IsNull() )
1455 gp_Ax3 aPos = aPlane->Pln().Position();
1456 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1458 Handle(GEOM_AISTrihedron) aTrh;
1460 if ( occPrs->IsNull() )
1462 // new presentation is being created
1463 aTrh = new GEOM_AISTrihedron( aPlc );
1464 occPrs->AddObject( aTrh );
1468 // presentation is being updated
1469 AIS_ListOfInteractive aList;
1470 occPrs->GetObjects( aList );
1471 AIS_ListIteratorOfListOfInteractive anIter( aList );
1472 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1473 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1477 if ( !aTrh.IsNull() ) {
1478 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1480 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1481 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1483 aTrh->SetWidth( GetWidth() );
1485 if ( !myIO.IsNull() )
1487 aTrh->setIO( myIO );
1488 aTrh->SetOwner( myIO );
1490 aTrh->SetComponent( aPlc );
1491 aTrh->SetToUpdate();
1493 occPrs->SetToActivate( ToActivate() );
1499 // processing for usual geometry presentation
1502 // if presentation is empty we try to create new one
1503 if ( occPrs->IsNull() )
1505 // create presentation (specific for vectors)
1506 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1507 : new GEOM_AISShape ( myShape, "" );
1509 if( myType == GEOM_FIELD_STEP )
1510 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1511 // update shape properties
1512 updateShapeProperties( AISShape, true );
1514 // add shape to the presentation
1515 occPrs->AddObject( AISShape );
1517 // In accordance with ToActivate() value object will be activated/deactivated
1518 // when it will be displayed
1519 occPrs->SetToActivate( ToActivate() );
1521 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1522 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1524 // create additional wireframe shape
1525 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1526 aWirePrs->SetWidth(AISShape->Width());
1527 if ( !myIO.IsNull() ) {
1528 aWirePrs->setIO( myIO );
1529 aWirePrs->SetOwner( myIO );
1532 // add shape to the presentation
1533 occPrs->AddObject( aWirePrs );
1536 // if presentation is found -> set again shape for it
1539 AIS_ListOfInteractive IOList;
1540 occPrs->GetObjects( IOList );
1541 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1542 for ( ; Iter.More(); Iter.Next() )
1544 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1545 if ( AISShape.IsNull() )
1548 // re-set shape (it might be changed)
1549 if ( AISShape->Shape() != myShape )
1550 AISShape->Set( myShape );
1552 // update shape properties
1553 updateShapeProperties( AISShape, false );
1556 AISShape->UpdateSelection();
1557 AISShape->SetToUpdate();
1561 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1565 //=================================================================
1567 * GEOM_Displayer::Update
1568 * Update VTK presentaion
1569 * [ Reimplemented from SALOME_Displayer ]
1571 //=================================================================
1572 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1574 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1575 SalomeApp_Study* study = getStudy();
1577 if ( !vtkPrs || myShape.IsNull() || !study )
1580 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1583 // specific processing for local coordinate system presentation
1586 TopoDS_Face aFace = TopoDS::Face( myShape );
1587 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1588 if ( !aPlane.IsNull() ) {
1589 gp_Ax3 aPos = aPlane->Pln().Position();
1590 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1592 GEOM_VTKTrihedron* aTrh = 0;
1594 if ( vtkPrs->IsNull() ) {
1595 // new presentation is being created
1596 aTrh = GEOM_VTKTrihedron::New();
1597 vtkPrs->AddObject( aTrh );
1600 // presentation is being updated
1601 vtkActorCollection* actors = vtkPrs->GetObjects();
1603 actors->InitTraversal();
1604 vtkActor* a = actors->GetNextActor();
1605 while ( a && !aTrh ) {
1606 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1607 a = actors->GetNextActor();
1613 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1615 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1616 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1618 #ifdef VTK_TRIHEDRON_WIDTH
1620 // VSR: currently isn't supported
1622 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1624 aTrh->SetWidth( GetWidth() );
1627 if ( !myIO.IsNull() )
1628 aTrh->setIO( myIO );
1630 aTrh->SetPlacement( aPlc );
1637 // processing for usual geometry presentation
1640 // if presentation is empty we try to create new one
1641 if ( vtkPrs->IsNull() )
1644 GEOM_Actor* actor = GEOM_Actor::New();
1645 // update actor properties
1646 updateActorProperties( actor, true );
1647 // add actor to the presentation
1648 vtkPrs->AddObject( actor );
1651 // presentation is being updated
1652 vtkActorCollection* actors = vtkPrs->GetObjects();
1654 actors->InitTraversal();
1655 vtkActor* a = actors->GetNextActor();
1657 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1659 // update actor properties
1660 updateActorProperties( actor, false );
1661 a = actors->GetNextActor();
1669 //=================================================================
1671 * GEOM_Displayer::BuildPrs
1672 * Build presentation according to the current viewer type
1674 //=================================================================
1675 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1677 if ( theObj->_is_nil() )
1680 myViewFrame = GetActiveView();
1681 if ( myViewFrame == 0 )
1684 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1689 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1690 myType = theObj->GetType();
1692 // Update presentation
1698 //=================================================================
1700 * GEOM_Displayer::BuildPrs
1701 * Build presentation according to the current viewer type
1703 //=================================================================
1704 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1706 myViewFrame = GetActiveView();
1707 if ( theShape.IsNull() || myViewFrame == 0 )
1710 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1715 setShape( theShape );
1723 //=================================================================
1725 * GEOM_Displayer::buildPresentation
1726 * Builds/finds object's presentation for the current viewer
1727 * Calls corresponding Update() method by means of double dispatch
1730 //=================================================================
1731 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1732 SALOME_View* theViewFrame )
1734 SALOME_Prs* prs = 0;
1737 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1741 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1744 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1745 theIO->setEntry( entry.toLatin1().constData() );
1746 if ( !theIO.IsNull() )
1748 // set interactive object
1750 // Find SOBject (because shape should be published previously)
1753 _PTR(SObject) SO ( getStudy()->studyDS()->FindObjectID( theIO->getEntry() ) );
1756 // get CORBA reference to data object
1757 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1758 if ( !CORBA::is_nil( object ) )
1760 // downcast to GEOM base object
1761 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1762 if ( !GeomBaseObject->_is_nil() )
1764 myType = GeomBaseObject->GetType();
1766 // downcast to GEOM object
1767 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1768 if ( myType == GEOM_FIELD_STEP )
1770 // get the GEOM object from the field's shape
1771 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1772 if ( !GeomFieldStep->_is_nil() )
1774 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1775 if ( !GeomField->_is_nil() )
1776 GeomObject = GeomField->GetShape();
1779 // read the field step information
1780 readFieldStepInfo( GeomFieldStep );
1783 if ( !GeomObject->_is_nil() )
1785 CORBA::String_var name = GeomObject->GetName();
1786 theIO->setName( name );
1787 // finally set shape
1788 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1795 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1801 //=================================================================
1803 * GEOM_Displayer::buildSubshapePresentation
1804 * Builds/finds object's presentation for the current viewer
1805 * Calls corresponding Update() method by means of double dispatch
1806 * For not published objects (for Mantis issue 0020435)
1808 //=================================================================
1809 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1810 const QString& entry,
1811 SALOME_View* theViewFrame)
1813 SALOME_Prs* prs = 0;
1816 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1820 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1823 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1824 theIO->setEntry(entry.toLatin1().constData());
1825 if (!theIO.IsNull())
1827 // set interactive object
1829 // finally set shape
1831 myType = GEOM_SUBSHAPE;
1833 UpdatePrs(prs); // Update presentation by using of the double dispatch
1839 //=================================================================
1841 * GEOM_Displayer::internalReset
1842 * Resets internal data
1845 //=================================================================
1846 void GEOM_Displayer::internalReset()
1851 myFieldDataType = GEOM::FDT_Double;
1852 myFieldDimension = 0;
1853 myFieldStepData.clear();
1854 myFieldStepName.Clear();
1855 myFieldStepRangeMin = 0;
1856 myFieldStepRangeMax = 0;
1859 //=================================================================
1861 * GEOM_Displayer::LocalSelection
1862 * Activate selection of CAD shapes with activisation of selection
1863 * of their sub-shapes (with opened local context for OCC viewer)
1865 //=================================================================
1866 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1868 SUIT_Session* session = SUIT_Session::session();
1869 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1873 LightApp_SelectionMgr* sm = app->selectionMgr();
1875 // remove all filters from selection
1878 SALOME_View* vf = GetActiveView();
1880 if (!theIO.IsNull() && !vf->isVisible(theIO))
1882 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1883 vf->LocalSelection( prs, modes );
1884 delete prs; // delete presentation because displayer is its owner
1888 //=================================================================
1890 * GEOM_Displayer::LocalSelection
1891 * Activate selection of CAD shapes with activisation of selection
1892 * of their sub-shapes (with opened local context for OCC viewer)
1894 //=================================================================
1895 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1897 std::list<int> modes;
1898 modes.push_back( theMode );
1899 LocalSelection( theIO, modes );
1902 //=================================================================
1904 * GEOM_Displayer::globalSelection
1905 * Activate selection of CAD shapes without activisation of selection
1906 * of their sub-shapes (without opened local context for OCC viewer)
1908 //=================================================================
1909 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1911 TColStd_MapOfInteger aModes;
1912 aModes.Add( theMode );
1913 GlobalSelection( aModes, update );
1916 //=================================================================
1918 * GEOM_Displayer::globalSelection
1919 * Activate selection of CAD shapes without activisation of selection
1920 * of their sub-shapes (without opened local context for OCC viewer)
1922 //=================================================================
1923 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1924 const bool update, const QList<int>* theSubShapes )
1926 SUIT_Session* session = SUIT_Session::session();
1927 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1931 SALOME_View* vf = GetActiveView();
1935 // Close local context
1936 vf->GlobalSelection( update );
1938 // Set selection filters in accordance with current mode
1939 LightApp_SelectionMgr* sm = app->selectionMgr();
1943 // Remove from selection temporary objects if necessary
1944 if ( !theModes.Contains( GEOM_PREVIEW ) )
1945 clearTemporary( sm );
1947 //@ aSel->ClearIndex();
1951 // Remove filters from AIS_InteractiveContext
1952 Handle(AIS_InteractiveContext) ic;
1953 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1956 ic = viewer->getAISContext();
1958 ic->RemoveFilters();
1961 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1964 SUIT_SelectionFilter* aFilter;
1965 if ( theModes.Extent() == 1 )
1967 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1969 if ( aMode == GEOM_COMPOUNDFILTER )
1970 aFilter = getComplexFilter( theSubShapes );
1972 aFilter = getFilter( aMode );
1974 else if ( theModes.Extent() > 1 )
1976 TColStd_MapOfInteger aTopAbsModes;
1977 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1978 QList<SUIT_SelectionFilter*> aListOfFilters;
1979 for ( ; anIter.More(); anIter.Next() )
1981 SUIT_SelectionFilter* aFilter;
1982 int aMode = anIter.Key();
1983 if ( aMode == GEOM_COMPOUNDFILTER )
1984 aFilter = getComplexFilter( theSubShapes );
1986 aFilter = getFilter( aMode );
1989 aListOfFilters.append( aFilter );
1992 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1999 sm->installFilter( aFilter );
2002 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
2003 ic->AddFilter( anOCCFilter );
2008 //=================================================================
2010 * GEOM_Displayer::LocalSelection
2011 * Activate selection of CAD shapes with activisation of selection
2012 * of their sub-shapes (with opened local context for OCC viewer)
2014 //=================================================================
2015 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2017 SALOME_ListIteratorOfListIO Iter( theIOList );
2018 for ( ; Iter.More(); Iter.Next() )
2019 LocalSelection( Iter.Value(), modes );
2022 //=================================================================
2024 * GEOM_Displayer::LocalSelection
2025 * Activate selection of CAD shapes with activisation of selection
2026 * of their sub-shapes (with opened local context for OCC viewer)
2028 //=================================================================
2029 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2031 std::list<int> modes;
2032 modes.push_back( theMode );
2033 LocalSelection( theIOList, modes );
2036 //=================================================================
2038 * GEOM_Displayer::BeforeDisplay
2039 * Called before displaying of pars. Close local context
2040 * [ Reimplemented from SALOME_Displayer ]
2042 //=================================================================
2043 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2045 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2048 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2051 if ( ic->HasOpenedContext() )
2052 ic->CloseAllContexts(Standard_True);
2057 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2061 // visualize annotations for displayed presentation
2062 SUIT_Session* session = SUIT_Session::session();
2063 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2064 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2066 if ( !myIsRedisplayed ) {
2067 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2069 aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2074 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2076 LightApp_Displayer::BeforeErase( v, p );
2077 releaseTextures( p );
2080 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2082 LightApp_Displayer::AfterErase( v, p );
2085 if ( !myIsRedisplayed ) {
2086 // hide annotations for erased presentation
2087 SUIT_Session* session = SUIT_Session::session();
2088 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2089 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2091 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2095 //=================================================================
2097 * GEOM_Displayer::SetColor
2098 * Set color for shape displaying. If it is equal -1 then default color is used.
2099 * Available values are from Quantity_NameOfColor enumeration
2101 //=================================================================
2102 void GEOM_Displayer::SetColor( const int color )
2109 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2113 int GEOM_Displayer::GetColor() const
2118 bool GEOM_Displayer::HasColor() const
2120 return myColor != -1;
2123 void GEOM_Displayer::UnsetColor()
2127 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2128 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2129 myShadingColor = SalomeApp_Tools::color( col );
2132 //=================================================================
2134 * GEOM_Displayer::SetTransparency
2135 * Set transparency for shape displaying.
2137 //=================================================================
2138 double GEOM_Displayer::SetTransparency( const double transparency )
2140 double prevTransparency = myTransparency;
2141 myTransparency = transparency;
2142 return prevTransparency;
2145 //=================================================================
2147 * GEOM_Displayer::GetTransparency
2148 * Get transparency for shape displaying.
2150 //=================================================================
2151 double GEOM_Displayer::GetTransparency() const
2153 return myTransparency;
2156 //=================================================================
2158 * GEOM_Displayer::HasTransparency
2159 * Check if transparency for shape displaying is set.
2161 //=================================================================
2162 bool GEOM_Displayer::HasTransparency() const
2164 return myTransparency >= 0;
2167 //=================================================================
2169 * GEOM_Displayer::UnsetTransparency
2170 * Unset transparency for shape displaying.
2172 //=================================================================
2173 double GEOM_Displayer::UnsetTransparency()
2175 return SetTransparency( -1 );
2178 //=================================================================
2180 * GEOM_Displayer::SetTexture
2182 //=================================================================
2183 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2185 myTexture = texureFileName;
2188 bool GEOM_Displayer::HasTexture() const
2190 return myTexture != "";
2193 std::string GEOM_Displayer::GetTexture() const
2198 //=================================================================
2200 * GEOM_Displayer::SetWidth
2201 * Set width of shape displaying. If it is equal -1 then default width is used.
2203 //=================================================================
2204 void GEOM_Displayer::SetWidth( const double width )
2209 double GEOM_Displayer::GetWidth() const
2214 bool GEOM_Displayer::HasWidth() const
2216 return myWidth != -1;
2219 void GEOM_Displayer::UnsetWidth()
2224 int GEOM_Displayer::GetIsosWidth() const
2229 void GEOM_Displayer::SetIsosWidth(const int width)
2231 myIsosWidth = width;
2234 bool GEOM_Displayer::HasIsosWidth() const
2236 return myIsosWidth != -1;
2239 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2241 int prevNbIsos = myNbIsos;
2246 int GEOM_Displayer::UnsetNbIsos()
2248 return SetNbIsos( -1 );
2251 int GEOM_Displayer::GetNbIsos() const
2256 bool GEOM_Displayer::HasNbIsos() const
2258 return myNbIsos >= 0;
2261 int GEOM_Displayer::SetIsosColor( const int color )
2263 int prevColor = myIsosColor;
2264 myIsosColor = color;
2268 int GEOM_Displayer::GetIsosColor() const
2273 bool GEOM_Displayer::HasIsosColor() const
2275 return myIsosColor != -1;
2278 int GEOM_Displayer::UnsetIsosColor()
2280 return SetIsosColor( -1 );
2283 //=================================================================
2285 * GEOM_Displayer::SetToActivate
2286 * This method is used for activisation/deactivisation of objects to be displayed
2288 //=================================================================
2289 void GEOM_Displayer::SetToActivate( const bool toActivate )
2291 myToActivate = toActivate;
2293 bool GEOM_Displayer::ToActivate() const
2295 return myToActivate;
2298 //=================================================================
2300 * GEOM_Displayer::clearTemporary
2301 * Removes from selection temporary objects
2303 //=================================================================
2304 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2306 SALOME_ListIO selected, toSelect;
2307 theSelMgr->selectedObjects( selected );
2309 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2310 Handle(SALOME_InteractiveObject) io = it.Value();
2311 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2312 toSelect.Append( it.Value() );
2315 theSelMgr->setSelectedObjects( toSelect, true );
2318 void GEOM_Displayer::SetName( const char* theName )
2323 void GEOM_Displayer::UnsetName()
2328 SalomeApp_Study* GEOM_Displayer::getStudy() const
2330 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2333 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2338 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2343 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2344 const int theFieldDimension,
2345 const QList<QVariant>& theFieldStepData,
2346 const TCollection_AsciiString& theFieldStepName,
2347 const double theFieldStepRangeMin,
2348 const double theFieldStepRangeMax )
2350 myFieldDataType = theFieldDataType;
2351 myFieldDimension = theFieldDimension;
2352 myFieldStepData = theFieldStepData;
2353 myFieldStepName = theFieldStepName;
2354 myFieldStepRangeMin = theFieldStepRangeMin;
2355 myFieldStepRangeMax = theFieldStepRangeMax;
2358 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2360 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2361 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2362 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2363 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2364 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2365 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2368 int GEOM_Displayer::SetDisplayMode( const int theMode )
2370 int aPrevMode = myDisplayMode;
2371 if ( theMode != -1 ) {
2372 myDisplayMode = theMode;
2373 myHasDisplayMode = true;
2381 int GEOM_Displayer::GetDisplayMode() const
2383 return myDisplayMode;
2386 int GEOM_Displayer::UnsetDisplayMode()
2388 int aPrevMode = myDisplayMode;
2389 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2390 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2391 myHasDisplayMode = false;
2395 bool GEOM_Displayer::HasDisplayMode() const
2397 return myHasDisplayMode;
2400 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2402 static QList<QColor> colors;
2404 if ( colors.isEmpty() ) {
2406 for (int s = 0; s < 2 ; s++)
2408 for (int v = 100; v >= 40; v = v - 20)
2410 for (int h = 0; h < 359 ; h = h + 60)
2412 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2418 static int currentColor = randomize( colors.size() );
2420 SALOMEDS::Color color;
2421 color.R = (double)colors[currentColor].red() / 255.0;
2422 color.G = (double)colors[currentColor].green() / 255.0;
2423 color.B = (double)colors[currentColor].blue() / 255.0;
2425 currentColor = (currentColor+1) % colors.count();
2430 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2433 int aTolerance = 64;
2434 int anIterations = 0;
2440 if( anIterations % aPeriod == 0 )
2443 if( aTolerance < 1 )
2446 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2448 aHue = (int)( 360.0 * rand() / RAND_MAX );
2449 //std::cout << "Hue = " << aHue << std::endl;
2451 //std::cout << "Auto colors : ";
2453 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2454 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2455 for( ; it != itEnd; ++it )
2457 SALOMEDS::Color anAutoColor = *it;
2458 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2461 aQColor.getHsv( &h, &s, &v );
2462 //std::cout << h << " ";
2463 if( abs( h - aHue ) < aTolerance )
2466 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2470 //std::cout << std::endl;
2476 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2478 aColor.setHsv( aHue, 255, 255 );
2480 SALOMEDS::Color aSColor;
2481 aSColor.R = (double)aColor.red() / 255.0;
2482 aSColor.G = (double)aColor.green() / 255.0;
2483 aSColor.B = (double)aColor.blue() / 255.0;
2488 PropMap GEOM_Displayer::getObjectProperties( const QString& entry,
2491 // get default properties for the explicitly specified default view type
2492 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2494 if ( getStudy() && view ) {
2495 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2496 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2497 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2499 if ( viewModel && viewId != -1 ) {
2500 // get properties from the study
2501 PropMap storedMap = getStudy()->getObjectProperties( viewId, entry );
2502 // overwrite default properties from stored ones (that are specified)
2503 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2504 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2505 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2506 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2508 // ... specific processing for color
2509 // ... current implementation is to use same stored color for all aspects
2510 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2511 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2512 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2513 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2514 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2515 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2516 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2519 if ( !entry.isEmpty() ) {
2520 // get CORBA reference to geom object
2521 _PTR(SObject) SO( getStudy()->studyDS()->FindObjectID( entry.toStdString() ) );
2523 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2524 if ( !CORBA::is_nil( object ) ) {
2525 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2526 if ( !CORBA::is_nil( geomObject ) ) { // to check
2527 // check that geom object has color properly set
2528 bool hasColor = false;
2529 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2530 // set color from geometry object (only once, if it is not yet set in GUI)
2531 // current implementation is to use same color for all aspects
2532 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2533 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2534 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2535 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2536 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2537 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2538 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2539 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2541 // check that object has point marker properly set
2542 GEOM::marker_type mType = geomObject->GetMarkerType();
2543 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2544 int mTextureId = geomObject->GetMarkerTexture();
2545 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2546 ( mType == GEOM::MT_USER && mTextureId > 0 );
2547 // set point marker from geometry object (only once, if it is not yet set in GUI)
2548 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2549 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2551 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2552 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2554 else if ( mType == GEOM::MT_USER ) {
2556 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2568 PropMap GEOM_Displayer::getDefaultPropertyMap()
2572 // get resource manager
2573 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2575 // fill in the properties map with default values
2577 // - visibility (false by default)
2578 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2580 // - nb isos (take default value from preferences)
2581 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2582 QString( "%1%2%3" ).
2583 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2584 arg( GEOM::subSectionSeparator() ).
2585 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2587 // - transparency (opacity = 1-transparency)
2588 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2589 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2591 // - display mode (take default value from preferences)
2592 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2593 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2595 // - show edges direction flag (false by default)
2596 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2598 // - show vertices flag (false by default)
2599 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2601 // - show name flag (false by default)
2602 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2604 // - shading color (take default value from preferences)
2605 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2606 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2608 // - wireframe color (take default value from preferences)
2609 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2610 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2612 // - standalone edges color (take default value from preferences)
2613 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2614 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2616 // - free boundaries color (take default value from preferences)
2617 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2618 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2620 // - points color (take default value from preferences)
2621 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2622 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2624 // - isos color (take default value from preferences)
2625 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2626 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2628 // - outlines color (take default value from preferences)
2629 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2630 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2632 // - deflection coefficient (take default value from preferences)
2633 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2634 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2636 // - material (take default value from preferences)
2637 Material_Model material;
2638 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2639 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2641 // - edge width (take default value from preferences)
2642 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2643 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2645 // - isos width (take default value from preferences)
2646 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2647 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2649 // - point marker (take default value from preferences)
2650 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2651 QString( "%1%2%3" ).
2652 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2653 arg( GEOM::subSectionSeparator() ).
2654 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2656 // - top-level flag (false by default)
2657 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2662 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2663 SALOMEDS::Color aSColor;
2666 SUIT_Session* session = SUIT_Session::session();
2667 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2669 if ( app && !theGeomObject->_is_nil()) {
2670 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2673 _PTR(Study) aStudy = study->studyDS();
2674 aSColor = theGeomObject->GetColor();
2675 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2677 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2678 bool general_autocolor = true;
2679 #else // auto-color for groups only
2680 bool general_autocolor = false;
2681 #endif // GENERAL_AUTOCOLOR
2682 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2683 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2684 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2685 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2686 aSColor = getPredefinedUniqueColor();
2688 #else // old algorithm for auto-colors
2689 QList<SALOMEDS::Color> aReservedColors;
2690 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2691 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2692 if ( aMainSObject ) {
2693 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2694 for ( ; it->More(); it->Next() ) {
2695 _PTR(SObject) aChildSObject( it->Value() );
2696 GEOM::GEOM_Object_var aChildObject =
2697 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2698 if ( CORBA::is_nil( aChildObject ) )
2701 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2702 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2703 aReservedColors.append( aReservedColor );
2706 aSColor = getUniqueColor( aReservedColors );
2708 #endif // SIMPLE_AUTOCOLOR
2718 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2719 const bool eraseOnlyChildren)
2721 LightApp_DataObject* parent = getStudy()->findObjectByEntry(theIO->getEntry());
2726 // Erase from all views
2727 QList<SALOME_View*> views;
2729 ViewManagerList vmans = myApp->viewManagers();
2730 SUIT_ViewManager* vman;
2731 foreach ( vman, vmans ) {
2732 SUIT_ViewModel* vmod = vman->getViewModel();
2733 view = dynamic_cast<SALOME_View*> ( vmod );
2735 views.append( view );
2738 if( views.count() == 0 )
2741 //Erase childrens w/o update views
2742 DataObjectList listObj = parent->children( true );
2743 SUIT_DataObject* obj;
2744 foreach( obj, listObj ) {
2745 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2747 foreach ( view, views ) {
2748 Handle(SALOME_InteractiveObject) anIO =
2749 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2750 Erase(anIO, false, false, view);
2754 //Erase parent with view update or repaint views
2755 foreach ( view, views ) {
2756 if(!eraseOnlyChildren)
2757 Erase(theIO, false, true, view);
2763 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2765 if( theGeomFieldStep->_is_nil() )
2768 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2769 if( aGeomField->_is_nil() )
2772 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2773 if( aGeomFieldShape->_is_nil() )
2776 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2777 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2778 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2780 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2782 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2784 int aFieldDimension = aGeomField->GetDimension();
2786 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2787 int aFieldNbComponents = aFieldComponents->length();
2789 QList<QVariant> aFieldStepData;
2790 if( aFieldDataType == GEOM::FDT_Bool )
2792 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2793 if ( !aGeomBoolFieldStep->_is_nil() )
2795 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2796 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2797 aFieldStepData << (bool)aValues[i];
2800 else if( aFieldDataType == GEOM::FDT_Int )
2802 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2803 if ( !aGeomIntFieldStep->_is_nil() )
2805 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2806 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2807 aFieldStepData << (qlonglong)aValues[i];
2810 else if( aFieldDataType == GEOM::FDT_Double )
2812 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2813 if ( !aGeomDoubleFieldStep->_is_nil() )
2815 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2816 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2817 aFieldStepData << (double)aValues[i];
2820 else if( aFieldDataType == GEOM::FDT_String )
2822 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2823 if ( !aGeomStringFieldStep->_is_nil() )
2825 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2826 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2827 aFieldStepData << QString( aValues[i] );
2831 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2832 aFieldStepData = groupFieldData( aFieldStepData,
2834 aFieldDataType == GEOM::FDT_String,
2836 aFieldStepRangeMax );
2838 setFieldStepInfo( aFieldDataType,
2843 aFieldStepRangeMax );
2846 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2847 const int theFieldNbComponents,
2848 const bool theIsString,
2849 double& theFieldStepRangeMin,
2850 double& theFieldStepRangeMax )
2852 QList<QVariant> aResultList;
2853 theFieldStepRangeMin = 0;
2854 theFieldStepRangeMax = 0;
2856 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2859 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2861 QList<QVariant> aGroupedList;
2863 bool anIsBoolean = false;
2864 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2867 QStringList aStringList;
2869 int aBaseIndex = aSubShape * theFieldNbComponents;
2870 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2872 int anIndex = aComponent + aBaseIndex;
2874 const QVariant& aVariant = theFieldStepData[ anIndex ];
2877 if( aVariant.type() == QVariant::String )
2878 aStringList << aVariant.toString();
2883 if( aVariant.type() == QVariant::Bool )
2885 aValue = aVariant.toBool() ? 1.0 : 0.0;
2891 if( aVariant.type() == QVariant::LongLong )
2892 aValue = double( aVariant.toLongLong() );
2893 else if( aVariant.type() == QVariant::Double )
2894 aValue = aVariant.toDouble();
2895 aNorm += aValue * aValue;
2901 aGroupedList << aStringList.join( "\n" );
2905 aNorm /= theFieldNbComponents;
2907 aNorm = pow( aNorm, 0.5 );
2909 if( aGroupedList.isEmpty() )
2910 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2913 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2914 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2917 aGroupedList << aNorm;
2923 theFieldStepRangeMin = 0.0;
2924 theFieldStepRangeMax = 1.0;
2927 SUIT_Session* session = SUIT_Session::session();
2928 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2929 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2931 QListIterator<QVariant> anIter( aGroupedList );
2932 while( anIter.hasNext() )
2934 const QVariant& aVariant = anIter.next();
2936 aResultList << aVariant;
2940 Quantity_Color aColor;
2941 if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2942 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2943 aResultList << aQColor;
2949 void GEOM_Displayer::UpdateColorScale()
2951 if ( !myUpdateColorScale )
2954 SUIT_Session* session = SUIT_Session::session();
2955 SUIT_Application* app = session->activeApplication();
2958 Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject();
2960 QList<SUIT_ViewWindow*> windows = app->desktop()->windows();
2961 foreach( SUIT_ViewWindow* window, windows )
2963 OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>( window );
2964 if ( !occWindow ) continue;
2965 if ( !occWindow->getViewManager() ) continue;
2966 if ( !window->getViewManager() ) continue;
2967 if ( !window->getViewManager()->getViewModel() ) continue;
2968 SOCC_Viewer* view = dynamic_cast<SOCC_Viewer*>( window->getViewManager()->getViewModel() );
2969 if ( !view ) continue;
2970 Handle(V3d_Viewer) viewer = view->getViewer3d();
2971 if ( !io.IsNull() && view->isVisible( io ) )
2973 bool visible = false;
2974 SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( view->CreatePrs( io->getEntry() ) );
2977 AIS_ListOfInteractive presentations;
2978 prs->GetObjects( presentations );
2979 AIS_ListIteratorOfListOfInteractive iter( presentations );
2980 for ( ; iter.More(); iter.Next() )
2982 Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() );
2983 if ( shape.IsNull() ) continue;
2984 GEOM::field_data_type fieldDataType;
2986 QList<QVariant> fieldStepData;
2987 TCollection_AsciiString fieldStepName;
2988 Standard_Real fieldStepRangeMin, fieldStepRangeMax;
2989 shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData,
2990 fieldStepName, fieldStepRangeMin, fieldStepRangeMax );
2991 visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String;
2994 SUIT_Session* session = SUIT_Session::session();
2995 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2997 Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2998 Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2999 Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3000 Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3001 Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3002 Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3004 Standard_Integer viewWidth = 0, viewHeight = 0;
3005 occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight );
3007 Handle(AIS_ColorScale) colorScale = view->getColorScale();
3009 colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos );
3010 colorScale->SetBreadth( viewWidth * width );
3011 colorScale->SetHeight( viewHeight * height );
3012 colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax );
3013 colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals );
3014 colorScale->SetTextHeight( textHeight );
3015 colorScale->SetTitle( fieldStepName );
3019 view->setColorScaleShown( visible );
3020 } // if ( view->isVisible( io ) )
3023 view->setColorScaleShown( false );
3025 } // foreach( SUIT_ViewWindow* window, windows )
3028 bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049
3030 bool previous = myUpdateColorScale;
3031 myUpdateColorScale = toUpdate;
3032 if ( myUpdateColorScale && !previous )