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 "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISDimension.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 <GEOMUtils.hxx>
50 #include <Material_Model.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ViewWindow.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_ViewManager.h>
56 #include <SUIT_ResourceMgr.h>
58 #include <Basics_OCCTVersion.hxx>
60 #include <SalomeApp_Study.h>
61 #include <SalomeApp_Application.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_DataObject.h>
64 #include <SalomeApp_TypeFilter.h>
65 #include <SalomeApp_Tools.h>
66 #include "utilities.h"
68 #include <SALOME_ListIO.hxx>
69 #include <SALOME_Prs.h>
70 #include "utilities.h"
73 #include <SOCC_ViewModel.h>
76 #include <SVTK_ViewModel.h>
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
80 #include <OCCViewer_Utilities.h>
83 #include <AIS_Dimension.hxx>
84 #include <AIS_LengthDimension.hxx>
85 #include <AIS_DiameterDimension.hxx>
86 #include <AIS_AngleDimension.hxx>
87 #include <AIS_ListIteratorOfListOfInteractive.hxx>
88 #include <Aspect_PolygonOffsetMode.hxx>
89 #if OCC_VERSION_MAJOR < 7
90 #include <Aspect_ColorScale.hxx>
92 #include <Prs3d_IsoAspect.hxx>
93 #include <Prs3d_PointAspect.hxx>
94 #include <StdSelect_TypeOfEdge.hxx>
95 #include <StdSelect_TypeOfFace.hxx>
96 #include <StdSelect_DisplayMode.hxx>
97 #include <TopoDS_Face.hxx>
98 #include <BRep_Tool.hxx>
99 #include <Geom_Plane.hxx>
100 #include <Geom_Axis2Placement.hxx>
101 #include <Graphic3d_AspectFillArea3d.hxx>
102 #include <gp_Pln.hxx>
103 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
104 #include <TopoDS_Iterator.hxx>
105 #include <Graphic3d_AspectMarker3d.hxx>
106 #include <TopTools_MapOfShape.hxx>
107 #include <TopTools_ListOfShape.hxx>
108 #include <TopTools_ListIteratorOfListOfShape.hxx>
109 #include <TopoDS.hxx>
110 #include <NCollection_DataMap.hxx>
111 #include <NCollection_Map.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #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 #ifdef USE_TEXTURED_SHAPE
242 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
243 if ( aPixmap.IsNull() )
246 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
249 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
251 aUsersShapes.Remove( aAISShape );
253 if ( aUsersShapes.IsEmpty() ) {
254 aPixmapUsersMap.UnBind( aPixmap );
255 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
261 uint randomize( uint size )
263 static bool initialized = false;
264 if ( !initialized ) {
265 qsrand( QDateTime::currentDateTime().toTime_t() );
269 v = uint( (double)( v ) / RAND_MAX * size );
270 v = qMax( uint(0), qMin ( v, size-1 ) );
275 //================================================================
276 // Function : getActiveStudy
277 // Purpose : Get active study, returns 0 if no open study frame
278 //================================================================
279 static inline SalomeApp_Study* getActiveStudy()
281 SUIT_Session* session = SUIT_Session::session();
282 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
284 return ( SalomeApp_Study* )app->activeStudy();
288 static inline int getViewManagerId( SALOME_View* theViewFrame) {
289 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
290 SUIT_ViewManager* aViewMgr = 0;
292 aViewMgr = aModel->getViewManager();
293 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
296 //================================================================
297 // Function : getTopAbsMode
298 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
299 // one from GEOMImpl_Types.h
300 //================================================================
301 static inline int getTopAbsMode( const int implType )
305 case GEOM_COMPOUND : return TopAbs_COMPOUND;
306 case GEOM_SOLID : return TopAbs_SOLID;
307 case GEOM_SHELL : return TopAbs_SHELL;
308 case GEOM_FACE : return TopAbs_FACE;
309 case GEOM_WIRE : return TopAbs_WIRE;
310 case GEOM_EDGE : return TopAbs_EDGE;
311 case GEOM_POINT : return TopAbs_VERTEX;
316 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
318 if ( shape.IsNull() )
321 int ret = shape.ShapeType();
323 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
324 TopoDS_Iterator it(shape, Standard_True, Standard_False);
325 for (; it.More(); it.Next()) {
326 TopoDS_Shape sub_shape = it.Value();
327 if ( sub_shape.IsNull() ) continue;
328 int stype = getMinMaxShapeType( sub_shape, ismin );
329 if ( stype == TopAbs_SHAPE ) continue;
330 if ( ismin && stype > ret )
332 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
340 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
342 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
345 //================================================================
346 // Function : getFilter
347 // Purpose : Get filter corresponding to the type of object
348 // from GEOMImpl_Types.h
349 //================================================================
350 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
352 SUIT_SelectionFilter* aFilter;
354 int aTopAbsMode = getTopAbsMode( theMode );
355 if ( aTopAbsMode != -1 )
356 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
360 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
361 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
363 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
364 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
365 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
366 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
367 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
368 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
370 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
372 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
373 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
375 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
381 //================================================================
382 // Function : getComplexFilter
383 // Purpose : Get compound filter corresponding to the type of
384 // object from GEOMImpl_Types.h
385 //================================================================
386 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
388 GEOM_CompoundFilter* aFilter;
390 if(aSubShapes != NULL ) {
391 aFilter = new GEOM_CompoundFilter(getStudy());
392 QList<int> aTopAbsTypes;
393 QList<int>::const_iterator it;
394 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
395 int topAbsMode = getTopAbsMode(*it);
396 if(topAbsMode != -1 )
397 aTopAbsTypes.append(topAbsMode);
399 aFilter->addSubTypes(aTopAbsTypes);
405 //================================================================
406 // Function : getEntry
408 //================================================================
409 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
411 SUIT_Session* session = SUIT_Session::session();
412 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
415 CORBA::String_var IOR = app->orb()->object_to_string( object );
416 if ( strcmp(IOR.in(), "") != 0 )
418 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
419 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
427 //================================================================
428 // Function : getName
430 //================================================================
431 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
433 SUIT_Session* session = SUIT_Session::session();
434 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
437 CORBA::String_var IOR = app->orb()->object_to_string( object );
438 if ( strcmp(IOR.in(), "") != 0 )
440 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
441 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
443 _PTR(GenericAttribute) anAttr;
445 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
447 _PTR(AttributeName) aNameAttr( anAttr );
448 return aNameAttr->Value();
456 //=================================================================
458 * GEOM_Displayer::GEOM_Displayer
461 //=================================================================
462 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
465 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
470 SUIT_Session* session = SUIT_Session::session();
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 #if OCC_VERSION_MAJOR >= 7
511 myColorScale = new AIS_ColorScale;
512 myColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
513 myColorScale->SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt (-1,-1,0));
516 myFieldDataType = GEOM::FDT_Double;
517 myFieldDimension = 0;
518 myFieldStepRangeMin = 0;
519 myFieldStepRangeMax = 0;
522 //=================================================================
524 * GEOM_Displayer::~GEOM_Displayer
527 //=================================================================
528 GEOM_Displayer::~GEOM_Displayer()
532 //=================================================================
534 * GEOM_Displayer::Display
535 * Display interactive object in the current viewer
537 //=================================================================
538 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
539 const bool updateViewer,
540 SALOME_View* theViewFrame )
542 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
545 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
549 vf->BeforeDisplay( this, prs );
550 vf->Display( this, prs );
551 vf->AfterDisplay( this, prs );
556 delete prs; // delete presentation because displayer is its owner
561 //=================================================================
563 * GEOM_Displayer::Display
564 * This overloaded Display() method can be useful for operations
565 * not using dialog boxes.
567 //=================================================================
568 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
570 if ( theObj->_is_nil() )
573 std::string entry = getEntry( theObj );
575 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
580 //=================================================================
582 * GEOM_Displayer::Erase
583 * Erase interactive object in the current viewer
585 //=================================================================
586 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
588 const bool updateViewer,
589 SALOME_View* theViewFrame )
591 if ( theIO.IsNull() )
594 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
597 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
599 vf->BeforeErase( this, prs );
600 vf->Erase( this, prs, forced );
601 vf->AfterErase( this, prs );
604 delete prs; // delete presentation because displayer is its owner
609 //=================================================================
611 * GEOM_Displayer::Erase
612 * Erase geometry object in the current viewer
614 //=================================================================
615 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
617 const bool updateViewer,
618 SALOME_View* theViewFrame)
620 std::string entry = getEntry( theObj );
623 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
624 forced, updateViewer, theViewFrame);
628 //=================================================================
630 * GEOM_Displayer::Redisplay
631 * Redisplay (erase and then display again) interactive object
632 * in the current viewer
634 //=================================================================
635 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
636 const bool updateViewer,
637 const bool checkActiveViewer )
639 // Remove the object permanently (<forced> == true)
640 SUIT_Session* ses = SUIT_Session::session();
641 SUIT_Application* app = ses->activeApplication();
644 SUIT_Desktop* desk = app->desktop();
645 QList<SUIT_ViewWindow*> wnds = desk->windows();
646 SUIT_ViewWindow* wnd;
647 QListIterator<SUIT_ViewWindow*> it( wnds );
648 while ( it.hasNext() && (wnd = it.next()) )
650 SUIT_ViewManager* vman = wnd->getViewManager();
653 SUIT_ViewModel* vmodel = vman->getViewModel();
656 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
659 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
661 Redisplay( theIO, updateViewer, view );
670 //=================================================================
672 * GEOM_Displayer::Redisplay
673 * Redisplay (erase and then display again) interactive object
674 * in the specified view
676 //=================================================================
677 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
678 const bool theUpdateViewer,
679 SALOME_View* theViewFrame )
681 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
687 Erase( theIO, true, false, theViewFrame );
688 Display( theIO, theUpdateViewer, theViewFrame );
691 //=================================================================
693 * GEOM_Displayer::Display
694 * Calls Display() method for each object in the given list
696 //=================================================================
697 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
699 SALOME_ListIteratorOfListIO Iter( theIOList );
700 for ( ; Iter.More(); Iter.Next() ) {
701 Display( Iter.Value(), false );
707 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
709 SalomeApp_Study* aStudy = getStudy();
711 if ( v ) vId = getViewManagerId( v );
714 QString entry = p->GetEntry();
715 if ( !entry.isEmpty() ) {
717 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
718 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
723 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
728 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
730 // VSR: this method can be improved in future:
731 // to improve performance, the default values from resource manager should be cached in the displayer
732 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
735 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
737 // VSR: this method can be improved in future:
738 // to improve performance, the default values from resource manager should be cached in the displayer
739 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
742 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
744 // check that shape is not null
745 if ( AISShape.IsNull() ) return;
747 // check that study is active
748 SalomeApp_Study* study = getStudy();
749 if ( !study ) return;
751 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
752 !TopoDS_Iterator(myShape).More() )
753 return; // NPAL15983 (Bug when displaying empty groups)
755 // set interactive object
757 Handle( SALOME_InteractiveObject ) anIO;
759 if ( !myIO.IsNull() ) {
760 AISShape->setIO( myIO );
761 AISShape->SetOwner( myIO );
764 else if ( !myName.empty() ) {
765 // workaround to allow selection of temporary objects
766 static int tempId = 0;
767 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
768 AISShape->setIO( anIO );
769 AISShape->SetOwner( anIO );
772 // flag: only vertex or compound of vertices is processed (specific handling)
773 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
774 // presentation study entry (empty for temporary objects like preview)
775 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
776 // flag: temporary object
777 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
778 // currently active view window's ID (-1 if no active view)
779 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
781 // get presentation properties
782 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
784 // Temporary staff: vertex must be infinite for correct visualization
785 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
788 Material_Model material;
789 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
791 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
792 // - set front material properties
793 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
794 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
795 // - set back material properties
796 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
797 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
798 // - switch to default (both sides) facing mode
799 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
805 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
806 // we set it to the shape not taking into account material properties
807 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
809 else if ( !material.isPhysical() ) {
810 // shading color from properties is used only for non-physical materials
811 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
815 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
816 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
817 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
818 AISShape->Attributes()->SetLineAspect( anAspect );
820 // - unfree boundaries color
821 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
822 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
823 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
824 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
826 // - free boundaries color
827 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
828 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
829 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
830 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
832 // - standalone edges color
833 anAspect = AISShape->Attributes()->WireAspect();
834 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
835 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
836 AISShape->Attributes()->SetWireAspect( anAspect );
838 // - color for edges in shading+edges mode
839 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
841 // - color of labels (textual fields and shape name)
842 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
845 AISShape->SetDisplayMode( HasDisplayMode() ?
846 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
848 // display mode from properties
849 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
851 // - face boundaries color and line width
852 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
853 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
854 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
855 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
857 // set display vectors flag
858 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
860 // set display vertices flag
861 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
862 AISShape->SetDisplayVertices( isVerticesMode );
864 // set display name flag
865 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
866 AISShape->SetDisplayName( isNameMode );
869 if( HasTransparency() ) {
870 AISShape->SetTransparency( GetTransparency() );
872 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
875 // set iso properties
876 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
877 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
878 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
879 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
880 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
881 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
883 if ( HasIsosColor() ) {
884 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
885 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
888 uIsoAspect->SetColor( isosColor );
889 vIsoAspect->SetColor( isosColor );
892 if ( HasIsosWidth() ) {
893 uIsoAspect->SetWidth( GetIsosWidth() );
894 vIsoAspect->SetWidth( GetIsosWidth() );
897 uIsoAspect->SetWidth( isosWidth );
898 vIsoAspect->SetWidth( isosWidth );
902 uIsoAspect->SetNumber( GetNbIsos() );
903 vIsoAspect->SetNumber( GetNbIsos() );
906 uIsoAspect->SetNumber( uIsos );
907 vIsoAspect->SetNumber( vIsos );
910 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
911 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
913 // set deflection coefficient
914 // ... to avoid to small values of the coefficient, its lower value is limited
915 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
919 if ( HasTexture() ) {
920 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
921 aImagePath = GetTexture().c_str();
922 if ( ! entry.isEmpty() ) {
923 // check that study is active
924 SalomeApp_Study* study = getActiveStudy();
926 // Store the texture in object properties for next displays
927 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
928 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
930 // Update propeties map
931 propMap = getObjectProperties( study, entry, myViewFrame );
936 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
939 #ifdef USE_TEXTURED_SHAPE
940 Handle(Image_PixMap) aPixmap;
941 if ( !aImagePath.isEmpty() )
942 aPixmap = cacheTextureFor( aImagePath, AISShape );
944 aPixmap = getDefaultTexture();
946 // apply image to shape
947 if ( !aPixmap.IsNull() ) {
948 AISShape->SetTexturePixMap( aPixmap );
949 AISShape->SetTextureMapOn();
950 AISShape->DisableTextureModulate();
953 AISShape->SetTextureMapOff();
958 AISShape->SetWidth( HasWidth() ?
959 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
961 // libe width from properties
962 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
964 // set top-level flag
965 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
967 // set point marker (for vertex / compound of vertices only)
968 if ( onlyVertex || isVerticesMode ) {
969 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
970 if ( aList.size() == 2 ) {
971 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
972 int aTypeOfMarker = aList[0].toInt();
973 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
974 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
975 anAspect->SetScale( aScaleOfMarker );
976 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
977 anAspect->SetColor( HasColor() ?
978 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
979 (Quantity_NameOfColor)GetColor() :
980 // color from properties
981 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
982 AISShape->Attributes()->SetPointAspect( anAspect );
984 else if ( aList.size() == 1 ) {
985 // custom marker string contains "IdOfTexture"
986 int textureId = aList[0].toInt();
987 Standard_Integer aWidth, aHeight;
988 Handle(TColStd_HArray1OfByte) aTexture =
989 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
990 if ( !aTexture.IsNull() ) {
991 Handle(Prs3d_PointAspect) aTextureAspect =
992 new Prs3d_PointAspect( HasColor() ?
993 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
994 (Quantity_NameOfColor)GetColor() :
995 // color from properties
996 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
999 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1004 // set field step data
1005 AISShape->setFieldStepInfo( myFieldDataType,
1009 myFieldStepRangeMin,
1010 myFieldStepRangeMax );
1012 if ( create && !isTemporary && aMgrId != -1 ) {
1013 // set properties to the study
1014 study->setObjectProperties( aMgrId, entry, propMap );
1017 // AISShape->SetName(???); ??? necessary to set name ???
1020 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1022 // check that actor is not null
1023 if ( !actor ) return;
1025 // check that study is active
1026 SalomeApp_Study* study = getStudy();
1027 if ( !study ) return;
1029 // set interactive object
1031 Handle( SALOME_InteractiveObject ) anIO;
1033 if ( !myIO.IsNull() ) {
1034 actor->setIO( myIO );
1037 else if ( !myName.empty() ) {
1038 // workaround to allow selection of temporary objects
1039 static int tempId = 0;
1040 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1041 actor->setIO( anIO );
1044 // presentation study entry (empty for temporary objects like preview)
1045 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1046 // flag: temporary object
1047 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1048 // currently active view window's ID (-1 if no active view)
1049 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1051 // get presentation properties
1052 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1055 /////////////////////////////////////////////////////////////////////////
1056 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1057 // due to performance problem
1058 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1059 /////////////////////////////////////////////////////////////////////////
1060 if ( !actor->getTopo().IsSame( myShape ) )
1061 #ifdef LIMIT_DEFLECTION_FOR_VTK
1062 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1064 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1068 Material_Model material;
1069 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1070 std::vector<vtkProperty*> mprops;
1071 mprops.push_back( material.getMaterialVTKProperty( true ) );
1072 mprops.push_back( material.getMaterialVTKProperty( false) );
1073 actor->SetMaterial( mprops );
1075 // set iso-lines properties
1077 // - set number of iso-lines
1078 int nbIsos[2]= { 1, 1 };
1079 if ( HasNbIsos() ) {
1080 nbIsos[0] = GetNbIsos();
1081 nbIsos[1] = GetNbIsos();
1084 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1085 nbIsos[0] = isos[0].toInt();
1086 nbIsos[1] = isos[1].toInt();
1088 actor->SetNbIsos( nbIsos );
1090 // - set iso-lines width
1091 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1093 // - set iso-lines color
1094 if ( HasIsosColor() )
1095 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1097 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1098 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1103 // - same color for all sub-actors
1104 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1105 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1108 // shading color (for non-physical materials)
1109 if ( !material.isPhysical() ) {
1110 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1111 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1112 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1115 // - standalone edge color
1116 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1117 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1119 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1120 // - shared edges color ???
1121 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1123 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1124 // - free edges color ???
1125 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1128 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1129 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1132 // - color for edges in shading+edges mode
1133 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1134 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1136 // - color of labels (shape name)
1137 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1138 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1141 if( HasTransparency() ) {
1142 actor->SetOpacity( 1.0 - GetTransparency() );
1144 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1148 actor->SetWidth( HasWidth() ?
1149 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1151 // libe width from properties
1152 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1154 // set display vectors flag
1155 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1157 // set display vertices flag
1158 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1160 // set display name flag
1161 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1164 int displayMode = HasDisplayMode() ?
1165 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1167 // display mode from properties
1168 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1170 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1171 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1172 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1173 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1175 if ( displayMode == 2 )
1176 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1177 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1179 actor->setDisplayMode( displayMode );
1182 actor->PickableOn();
1184 actor->PickableOff();
1186 if ( create && !isTemporary && aMgrId != -1 ) {
1187 // set properties to the study
1188 study->setObjectProperties( aMgrId, entry, propMap );
1192 //=================================================================
1194 * GEOM_Displayer::updateDimensions
1195 * Creates or renews dimension presentation for the IO.
1197 //=================================================================
1198 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1199 SALOME_OCCPrs* thePrs,
1200 const gp_Ax3& theShapeLCS )
1202 SalomeApp_Study* aStudy = getStudy();
1208 if ( theIO.IsNull() )
1213 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1215 AIS_ListOfInteractive aListOfIO;
1217 anOccPrs->GetObjects( aListOfIO );
1219 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1221 // remove outdated presentations of dimensions
1222 for ( ; aIterateIO.More(); aIterateIO.Next() )
1224 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1225 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1230 aListOfIO.Remove( aIterateIO );
1232 if ( !aIterateIO.More() )
1238 // prepare dimension styling
1239 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1241 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1242 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1243 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1244 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1245 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1246 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1247 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1248 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1250 // restore dimension presentation from saved attribute or property data
1251 AIS_ListOfInteractive aRestoredDimensions;
1253 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1255 GEOM::propertyName( GEOM::Dimensions ),
1258 GEOMGUI_DimensionProperty aRecords;
1260 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1262 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1266 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1269 // create up-to-date dimension presentations
1270 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1272 if ( !aRecords.IsVisible( aPrsIt ) )
1277 // init dimension by type
1278 Handle(AIS_Dimension) aPrs;
1279 switch( aRecords.GetType( aPrsIt ) )
1281 case GEOMGUI_DimensionProperty::DimensionType_Length :
1283 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1284 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1289 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1291 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1292 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1297 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1299 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1300 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1306 aPrs->SetOwner( theIO );
1308 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1310 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1312 aStyle->SetCommonColor( aColor );
1313 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1314 aStyle->MakeText3d( aUseText3d );
1315 aStyle->MakeTextShaded( Standard_True );
1316 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1317 aStyle->SetExtensionSize( fsize * 0.5 );
1318 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1319 aStyle->TextAspect()->SetHeight( fsize );
1320 aStyle->ArrowAspect()->SetLength( anArrowLength );
1321 aStyle->LineAspect()->SetWidth( aLineWidth );
1322 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1323 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1324 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1325 aPrs->SetDimensionAspect( aStyle );
1326 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1327 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1328 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1330 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1332 // show degree symbol for dimension instead of label "deg"
1333 if ( aUnitsAngle == "deg" )
1335 aPrs->SetSpecialSymbol(0xB0);
1336 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1337 aStyle->MakeUnitsDisplayed(Standard_False);
1341 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1342 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1347 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1350 aListOfIO.Append( aPrs );
1353 // update presentation
1356 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1358 anOccPrs->AddObject( aIterateIO.Value() );
1362 //=================================================================
1364 * GEOM_Displayer::Erase
1365 * Calls Erase() method for each object in the given list
1367 //=================================================================
1368 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1370 const bool updateViewer )
1372 SALOME_ListIteratorOfListIO Iter( theIOList );
1373 for ( ; Iter.More(); Iter.Next() )
1374 Erase( Iter.Value(), forced, false );
1380 //=================================================================
1382 * GEOM_Displayer::Redisplay
1383 * Calls Redisplay() method for each object in the given list
1385 //=================================================================
1386 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1387 const bool updateViewer,
1388 const bool checkActiveViewer )
1390 SALOME_ListIteratorOfListIO Iter( theIOList );
1391 for ( ; Iter.More(); Iter.Next() )
1392 Redisplay( Iter.Value(), false, checkActiveViewer );
1398 //=================================================================
1400 * GEOM_Displayer::Redisplay
1401 * Calls Redisplay() method for each object in the given list
1403 //=================================================================
1404 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1405 const bool theUpdateViewer,
1406 SALOME_View* theViewFrame )
1408 SALOME_ListIteratorOfListIO anIter( theIOList );
1409 for ( ; anIter.More(); anIter.Next() )
1411 Redisplay( anIter.Value(), false, theViewFrame );
1414 if ( theUpdateViewer )
1420 //=================================================================
1422 * GEOM_Displayer::Update
1423 * Update OCC presentaion
1424 * [ Reimplemented from SALOME_Displayer ]
1426 //=================================================================
1427 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1429 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1430 SalomeApp_Study* study = getStudy();
1432 if ( !occPrs || myShape.IsNull() || !study )
1435 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1438 // specific processing for local coordinate system presentation
1441 TopoDS_Face aFace = TopoDS::Face( myShape );
1442 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1443 if ( !aPlane.IsNull() )
1445 gp_Ax3 aPos = aPlane->Pln().Position();
1446 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1448 Handle(GEOM_AISTrihedron) aTrh;
1450 if ( occPrs->IsNull() )
1452 // new presentation is being created
1453 aTrh = new GEOM_AISTrihedron( aPlc );
1454 occPrs->AddObject( aTrh );
1458 // presentation is being updated
1459 AIS_ListOfInteractive aList;
1460 occPrs->GetObjects( aList );
1461 AIS_ListIteratorOfListOfInteractive anIter( aList );
1462 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1463 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1467 if ( !aTrh.IsNull() ) {
1468 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1470 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1471 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1473 aTrh->SetWidth( GetWidth() );
1475 if ( !myIO.IsNull() )
1477 aTrh->setIO( myIO );
1478 aTrh->SetOwner( myIO );
1480 aTrh->SetComponent( aPlc );
1481 aTrh->SetToUpdate();
1483 occPrs->SetToActivate( ToActivate() );
1489 // processing for usual geometry presentation
1492 // if presentation is empty we try to create new one
1493 if ( occPrs->IsNull() )
1495 // create presentation (specific for vectors)
1496 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1497 : new GEOM_AISShape ( myShape, "" );
1499 if( myType == GEOM_FIELD_STEP )
1500 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1501 // update shape properties
1502 updateShapeProperties( AISShape, true );
1504 // add shape to the presentation
1505 occPrs->AddObject( AISShape );
1507 // In accordance with ToActivate() value object will be activated/deactivated
1508 // when it will be displayed
1509 occPrs->SetToActivate( ToActivate() );
1511 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1512 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1514 // create additional wireframe shape
1515 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1516 aWirePrs->SetWidth(AISShape->Width());
1517 if ( !myIO.IsNull() ) {
1518 aWirePrs->setIO( myIO );
1519 aWirePrs->SetOwner( myIO );
1522 // add shape to the presentation
1523 occPrs->AddObject( aWirePrs );
1526 // if presentation is found -> set again shape for it
1529 AIS_ListOfInteractive IOList;
1530 occPrs->GetObjects( IOList );
1531 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1532 for ( ; Iter.More(); Iter.Next() )
1534 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1535 if ( AISShape.IsNull() )
1538 // re-set shape (it might be changed)
1539 if ( AISShape->Shape() != myShape )
1540 AISShape->Set( myShape );
1542 // update shape properties
1543 updateShapeProperties( AISShape, false );
1546 AISShape->UpdateSelection();
1547 AISShape->SetToUpdate();
1551 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1555 //=================================================================
1557 * GEOM_Displayer::Update
1558 * Update VTK presentaion
1559 * [ Reimplemented from SALOME_Displayer ]
1561 //=================================================================
1562 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1564 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1565 SalomeApp_Study* study = getStudy();
1567 if ( !vtkPrs || myShape.IsNull() || !study )
1570 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1573 // specific processing for local coordinate system presentation
1576 TopoDS_Face aFace = TopoDS::Face( myShape );
1577 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1578 if ( !aPlane.IsNull() ) {
1579 gp_Ax3 aPos = aPlane->Pln().Position();
1580 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1582 GEOM_VTKTrihedron* aTrh = 0;
1584 if ( vtkPrs->IsNull() ) {
1585 // new presentation is being created
1586 aTrh = GEOM_VTKTrihedron::New();
1587 vtkPrs->AddObject( aTrh );
1590 // presentation is being updated
1591 vtkActorCollection* actors = vtkPrs->GetObjects();
1593 actors->InitTraversal();
1594 vtkActor* a = actors->GetNextActor();
1595 while ( a && !aTrh ) {
1596 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1597 a = actors->GetNextActor();
1603 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1605 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1606 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1608 #ifdef VTK_TRIHEDRON_WIDTH
1610 // VSR: currently isn't supported
1612 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1614 aTrh->SetWidth( GetWidth() );
1617 if ( !myIO.IsNull() )
1618 aTrh->setIO( myIO );
1620 aTrh->SetPlacement( aPlc );
1627 // processing for usual geometry presentation
1630 // if presentation is empty we try to create new one
1631 if ( vtkPrs->IsNull() )
1634 GEOM_Actor* actor = GEOM_Actor::New();
1635 // update actor properties
1636 updateActorProperties( actor, true );
1637 // add actor to the presentation
1638 vtkPrs->AddObject( actor );
1641 // presentation is being updated
1642 vtkActorCollection* actors = vtkPrs->GetObjects();
1644 actors->InitTraversal();
1645 vtkActor* a = actors->GetNextActor();
1647 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1649 // update actor properties
1650 updateActorProperties( actor, false );
1651 a = actors->GetNextActor();
1659 //=================================================================
1661 * GEOM_Displayer::BuildPrs
1662 * Build presentation accordint to the current viewer type
1664 //=================================================================
1665 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1667 if ( theObj->_is_nil() )
1670 myViewFrame = GetActiveView();
1671 if ( myViewFrame == 0 )
1674 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1679 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1680 myType = theObj->GetType();
1682 // Update presentation
1688 //=================================================================
1690 * GEOM_Displayer::BuildPrs
1691 * Build presentation accordint to the current viewer type
1693 //=================================================================
1694 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1696 myViewFrame = GetActiveView();
1697 if ( theShape.IsNull() || myViewFrame == 0 )
1700 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1705 setShape( theShape );
1713 //=================================================================
1715 * GEOM_Displayer::buildPresentation
1716 * Builds/finds object's presentation for the current viewer
1717 * Calls corresponding Update() method by means of double dispatch
1720 //=================================================================
1721 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1722 SALOME_View* theViewFrame )
1724 SALOME_Prs* prs = 0;
1727 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1731 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1734 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1735 theIO->setEntry( entry.toLatin1().constData() );
1736 if ( !theIO.IsNull() )
1738 // set interactive object
1740 // Find SOBject (because shape should be published previously)
1741 SUIT_Session* session = SUIT_Session::session();
1742 SUIT_Application* app = session->activeApplication();
1745 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1748 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1751 // get CORBA reference to data object
1752 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1753 if ( !CORBA::is_nil( object ) )
1755 // downcast to GEOM base object
1756 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1757 if ( !GeomBaseObject->_is_nil() )
1759 myType = GeomBaseObject->GetType();
1761 // downcast to GEOM object
1762 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1763 if ( myType == GEOM_FIELD_STEP )
1765 // get the GEOM object from the field's shape
1766 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1767 if ( !GeomFieldStep->_is_nil() )
1769 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1770 if ( !GeomField->_is_nil() )
1771 GeomObject = GeomField->GetShape();
1774 // read the field step information
1775 readFieldStepInfo( GeomFieldStep );
1778 if ( !GeomObject->_is_nil() )
1780 theIO->setName( GeomObject->GetName() );
1781 // finally set shape
1782 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1790 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1796 //=================================================================
1798 * GEOM_Displayer::buildSubshapePresentation
1799 * Builds/finds object's presentation for the current viewer
1800 * Calls corresponding Update() method by means of double dispatch
1801 * For not published objects (for Mantis issue 0020435)
1803 //=================================================================
1804 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1805 const QString& entry,
1806 SALOME_View* theViewFrame)
1808 SALOME_Prs* prs = 0;
1811 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1815 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1818 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1819 theIO->setEntry(entry.toLatin1().constData());
1820 if (!theIO.IsNull())
1822 // set interactive object
1824 // finally set shape
1826 myType = GEOM_SUBSHAPE;
1828 UpdatePrs(prs); // Update presentation by using of the double dispatch
1834 //=================================================================
1836 * GEOM_Displayer::internalReset
1837 * Resets internal data
1840 //=================================================================
1841 void GEOM_Displayer::internalReset()
1846 myFieldDataType = GEOM::FDT_Double;
1847 myFieldDimension = 0;
1848 myFieldStepData.clear();
1849 myFieldStepName.Clear();
1850 myFieldStepRangeMin = 0;
1851 myFieldStepRangeMax = 0;
1854 //=================================================================
1856 * GEOM_Displayer::LocalSelection
1857 * Activate selection of CAD shapes with activisation of selection
1858 * of their sub-shapes (with opened local context for OCC viewer)
1860 //=================================================================
1861 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1863 SUIT_Session* session = SUIT_Session::session();
1864 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1868 LightApp_SelectionMgr* sm = app->selectionMgr();
1870 // remove all filters from selection
1873 SALOME_View* vf = GetActiveView();
1875 if (!theIO.IsNull() && !vf->isVisible(theIO))
1877 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1878 vf->LocalSelection( prs, modes );
1879 delete prs; // delete presentation because displayer is its owner
1883 //=================================================================
1885 * GEOM_Displayer::LocalSelection
1886 * Activate selection of CAD shapes with activisation of selection
1887 * of their sub-shapes (with opened local context for OCC viewer)
1889 //=================================================================
1890 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1892 std::list<int> modes;
1893 modes.push_back( theMode );
1894 LocalSelection( theIO, modes );
1897 //=================================================================
1899 * GEOM_Displayer::globalSelection
1900 * Activate selection of CAD shapes without activisation of selection
1901 * of their sub-shapes (without opened local context for OCC viewer)
1903 //=================================================================
1904 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1906 TColStd_MapOfInteger aModes;
1907 aModes.Add( theMode );
1908 GlobalSelection( aModes, update );
1911 //=================================================================
1913 * GEOM_Displayer::globalSelection
1914 * Activate selection of CAD shapes without activisation of selection
1915 * of their sub-shapes (without opened local context for OCC viewer)
1917 //=================================================================
1918 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1919 const bool update, const QList<int>* theSubShapes )
1921 SUIT_Session* session = SUIT_Session::session();
1922 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1926 SALOME_View* vf = GetActiveView();
1930 // Close local context
1931 vf->GlobalSelection( update );
1933 // Set selection filters in accordance with current mode
1934 LightApp_SelectionMgr* sm = app->selectionMgr();
1938 // Remove from selection temporary objects if necessary
1939 if ( !theModes.Contains( GEOM_PREVIEW ) )
1940 clearTemporary( sm );
1942 //@ aSel->ClearIndex();
1946 // Remove filters from AIS_InteractiveContext
1947 Handle(AIS_InteractiveContext) ic;
1948 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1951 ic = viewer->getAISContext();
1953 ic->RemoveFilters();
1956 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1959 SUIT_SelectionFilter* aFilter;
1960 if ( theModes.Extent() == 1 )
1962 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1964 if ( aMode == GEOM_COMPOUNDFILTER )
1965 aFilter = getComplexFilter( theSubShapes );
1967 aFilter = getFilter( aMode );
1969 else if ( theModes.Extent() > 1 )
1971 TColStd_MapOfInteger aTopAbsModes;
1972 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1973 QList<SUIT_SelectionFilter*> aListOfFilters;
1974 for ( ; anIter.More(); anIter.Next() )
1976 SUIT_SelectionFilter* aFilter;
1977 int aMode = anIter.Key();
1978 if ( aMode == GEOM_COMPOUNDFILTER )
1979 aFilter = getComplexFilter( theSubShapes );
1981 aFilter = getFilter( aMode );
1984 aListOfFilters.append( aFilter );
1987 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1994 sm->installFilter( aFilter );
1997 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1998 ic->AddFilter( anOCCFilter );
2003 //=================================================================
2005 * GEOM_Displayer::LocalSelection
2006 * Activate selection of CAD shapes with activisation of selection
2007 * of their sub-shapes (with opened local context for OCC viewer)
2009 //=================================================================
2010 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2012 SALOME_ListIteratorOfListIO Iter( theIOList );
2013 for ( ; Iter.More(); Iter.Next() )
2014 LocalSelection( Iter.Value(), modes );
2017 //=================================================================
2019 * GEOM_Displayer::LocalSelection
2020 * Activate selection of CAD shapes with activisation of selection
2021 * of their sub-shapes (with opened local context for OCC viewer)
2023 //=================================================================
2024 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2026 std::list<int> modes;
2027 modes.push_back( theMode );
2028 LocalSelection( theIOList, modes );
2031 //=================================================================
2033 * GEOM_Displayer::BeforeDisplay
2034 * Called before displaying of pars. Close local context
2035 * [ Reimplemented from SALOME_Displayer ]
2037 //=================================================================
2038 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2040 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2043 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2046 if ( ic->HasOpenedContext() )
2047 ic->CloseAllContexts();
2052 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2054 UpdateColorScale(false,false);
2057 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2059 LightApp_Displayer::BeforeErase( v, p );
2060 releaseTextures( p );
2063 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2065 LightApp_Displayer::AfterErase( v, p );
2066 UpdateColorScale(false,false);
2069 //=================================================================
2071 * GEOM_Displayer::SetColor
2072 * Set color for shape displaying. If it is equal -1 then default color is used.
2073 * Available values are from Quantity_NameOfColor enumeration
2075 //=================================================================
2076 void GEOM_Displayer::SetColor( const int color )
2083 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2087 int GEOM_Displayer::GetColor() const
2092 bool GEOM_Displayer::HasColor() const
2094 return myColor != -1;
2097 void GEOM_Displayer::UnsetColor()
2101 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2102 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2103 myShadingColor = SalomeApp_Tools::color( col );
2106 //=================================================================
2108 * GEOM_Displayer::SetTransparency
2109 * Set transparency for shape displaying.
2111 //=================================================================
2112 double GEOM_Displayer::SetTransparency( const double transparency )
2114 double prevTransparency = myTransparency;
2115 myTransparency = transparency;
2116 return prevTransparency;
2119 //=================================================================
2121 * GEOM_Displayer::GetTransparency
2122 * Get transparency for shape displaying.
2124 //=================================================================
2125 double GEOM_Displayer::GetTransparency() const
2127 return myTransparency;
2130 //=================================================================
2132 * GEOM_Displayer::HasTransparency
2133 * Check if transparency for shape displaying is set.
2135 //=================================================================
2136 bool GEOM_Displayer::HasTransparency() const
2138 return myTransparency >= 0;
2141 //=================================================================
2143 * GEOM_Displayer::UnsetTransparency
2144 * Unset transparency for shape displaying.
2146 //=================================================================
2147 double GEOM_Displayer::UnsetTransparency()
2149 return SetTransparency( -1 );
2152 //=================================================================
2154 * GEOM_Displayer::SetTexture
2156 //=================================================================
2157 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2159 myTexture = texureFileName;
2162 bool GEOM_Displayer::HasTexture() const
2164 return myTexture != "";
2167 std::string GEOM_Displayer::GetTexture() const
2172 //=================================================================
2174 * GEOM_Displayer::SetWidth
2175 * Set width of shape displaying. If it is equal -1 then default width is used.
2177 //=================================================================
2178 void GEOM_Displayer::SetWidth( const double width )
2183 double GEOM_Displayer::GetWidth() const
2188 bool GEOM_Displayer::HasWidth() const
2190 return myWidth != -1;
2193 void GEOM_Displayer::UnsetWidth()
2198 int GEOM_Displayer::GetIsosWidth() const
2203 void GEOM_Displayer::SetIsosWidth(const int width)
2205 myIsosWidth = width;
2208 bool GEOM_Displayer::HasIsosWidth() const
2210 return myIsosWidth != -1;
2213 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2215 int prevNbIsos = myNbIsos;
2220 int GEOM_Displayer::UnsetNbIsos()
2222 return SetNbIsos( -1 );
2225 int GEOM_Displayer::GetNbIsos() const
2230 bool GEOM_Displayer::HasNbIsos() const
2232 return myNbIsos >= 0;
2235 int GEOM_Displayer::SetIsosColor( const int color )
2237 int prevColor = myIsosColor;
2238 myIsosColor = color;
2242 int GEOM_Displayer::GetIsosColor() const
2247 bool GEOM_Displayer::HasIsosColor() const
2249 return myIsosColor != -1;
2252 int GEOM_Displayer::UnsetIsosColor()
2254 return SetIsosColor( -1 );
2257 //=================================================================
2259 * GEOM_Displayer::SetToActivate
2260 * This method is used for activisation/deactivisation of objects to be displayed
2262 //=================================================================
2263 void GEOM_Displayer::SetToActivate( const bool toActivate )
2265 myToActivate = toActivate;
2267 bool GEOM_Displayer::ToActivate() const
2269 return myToActivate;
2272 //=================================================================
2274 * GEOM_Displayer::clearTemporary
2275 * Removes from selection temporary objects
2277 //=================================================================
2278 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2280 SALOME_ListIO selected, toSelect;
2281 theSelMgr->selectedObjects( selected );
2283 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2284 Handle(SALOME_InteractiveObject) io = it.Value();
2285 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2286 toSelect.Append( it.Value() );
2289 theSelMgr->setSelectedObjects( toSelect, true );
2292 void GEOM_Displayer::SetName( const char* theName )
2297 void GEOM_Displayer::UnsetName()
2302 SalomeApp_Study* GEOM_Displayer::getStudy() const
2304 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2307 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2312 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2317 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2318 const int theFieldDimension,
2319 const QList<QVariant>& theFieldStepData,
2320 const TCollection_AsciiString& theFieldStepName,
2321 const double theFieldStepRangeMin,
2322 const double theFieldStepRangeMax )
2324 myFieldDataType = theFieldDataType;
2325 myFieldDimension = theFieldDimension;
2326 myFieldStepData = theFieldStepData;
2327 myFieldStepName = theFieldStepName;
2328 myFieldStepRangeMin = theFieldStepRangeMin;
2329 myFieldStepRangeMax = theFieldStepRangeMax;
2332 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2334 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2335 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2336 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2337 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2338 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2339 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2342 int GEOM_Displayer::SetDisplayMode( const int theMode )
2344 int aPrevMode = myDisplayMode;
2345 if ( theMode != -1 ) {
2346 myDisplayMode = theMode;
2347 myHasDisplayMode = true;
2355 int GEOM_Displayer::GetDisplayMode() const
2357 return myDisplayMode;
2360 int GEOM_Displayer::UnsetDisplayMode()
2362 int aPrevMode = myDisplayMode;
2363 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2364 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2365 myHasDisplayMode = false;
2369 bool GEOM_Displayer::HasDisplayMode() const
2371 return myHasDisplayMode;
2374 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2376 static QList<QColor> colors;
2378 if ( colors.isEmpty() ) {
2380 for (int s = 0; s < 2 ; s++)
2382 for (int v = 100; v >= 40; v = v - 20)
2384 for (int h = 0; h < 359 ; h = h + 60)
2386 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2392 static int currentColor = randomize( colors.size() );
2394 SALOMEDS::Color color;
2395 color.R = (double)colors[currentColor].red() / 255.0;
2396 color.G = (double)colors[currentColor].green() / 255.0;
2397 color.B = (double)colors[currentColor].blue() / 255.0;
2399 currentColor = (currentColor+1) % colors.count();
2404 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2407 int aTolerance = 64;
2408 int anIterations = 0;
2414 if( anIterations % aPeriod == 0 )
2417 if( aTolerance < 1 )
2420 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2422 aHue = (int)( 360.0 * rand() / RAND_MAX );
2423 //std::cout << "Hue = " << aHue << std::endl;
2425 //std::cout << "Auto colors : ";
2427 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2428 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2429 for( ; it != itEnd; ++it )
2431 SALOMEDS::Color anAutoColor = *it;
2432 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2435 aQColor.getHsv( &h, &s, &v );
2436 //std::cout << h << " ";
2437 if( abs( h - aHue ) < aTolerance )
2440 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2444 //std::cout << std::endl;
2450 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2452 aColor.setHsv( aHue, 255, 255 );
2454 SALOMEDS::Color aSColor;
2455 aSColor.R = (double)aColor.red() / 255.0;
2456 aSColor.G = (double)aColor.green() / 255.0;
2457 aSColor.B = (double)aColor.blue() / 255.0;
2462 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2463 const QString& entry,
2466 // get default properties for the explicitly specified default view type
2467 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2469 if ( study && view ) {
2470 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2471 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2472 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2474 if ( viewModel && viewId != -1 ) {
2475 // get properties from the study
2476 PropMap storedMap = study->getObjectProperties( viewId, entry );
2477 // overwrite default properties from stored ones (that are specified)
2478 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2479 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2480 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2481 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2483 // ... specific processing for color
2484 // ... current implementation is to use same stored color for all aspects
2485 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2486 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2487 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2488 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2489 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2490 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2491 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2494 if ( !entry.isEmpty() ) {
2495 // get CORBA reference to geom object
2496 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2498 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2499 if ( !CORBA::is_nil( object ) ) {
2500 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2501 if ( !CORBA::is_nil( geomObject ) ) { // to check
2502 // check that geom object has color properly set
2503 bool hasColor = false;
2504 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2505 // set color from geometry object (only once, if it is not yet set in GUI)
2506 // current implementation is to use same color for all aspects
2507 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2508 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2509 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2510 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2511 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2512 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2513 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2514 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2516 // check that object has point marker properly set
2517 GEOM::marker_type mType = geomObject->GetMarkerType();
2518 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2519 int mTextureId = geomObject->GetMarkerTexture();
2520 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2521 ( mType == GEOM::MT_USER && mTextureId > 0 );
2522 // set point marker from geometry object (only once, if it is not yet set in GUI)
2523 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2524 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2526 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2527 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2529 else if ( mType == GEOM::MT_USER ) {
2531 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2543 PropMap GEOM_Displayer::getDefaultPropertyMap()
2547 // get resource manager
2548 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2550 // fill in the properties map with default values
2552 // - visibility (false by default)
2553 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2555 // - nb isos (take default value from preferences)
2556 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2557 QString( "%1%2%3" ).
2558 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2559 arg( GEOM::subSectionSeparator() ).
2560 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2562 // - transparency (opacity = 1-transparency)
2563 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2564 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2566 // - display mode (take default value from preferences)
2567 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2568 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2570 // - show edges direction flag (false by default)
2571 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2573 // - show vertices flag (false by default)
2574 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2576 // - show name flag (false by default)
2577 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2579 // - shading color (take default value from preferences)
2580 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2581 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2583 // - wireframe color (take default value from preferences)
2584 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2585 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2587 // - standalone edges color (take default value from preferences)
2588 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2589 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2591 // - free boundaries color (take default value from preferences)
2592 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2593 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2595 // - points color (take default value from preferences)
2596 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2597 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2599 // - isos color (take default value from preferences)
2600 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2601 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2603 // - outlines color (take default value from preferences)
2604 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2605 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2607 // - deflection coefficient (take default value from preferences)
2608 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2609 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2611 // - material (take default value from preferences)
2612 Material_Model material;
2613 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2614 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2616 // - edge width (take default value from preferences)
2617 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2618 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2620 // - isos width (take default value from preferences)
2621 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2622 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2624 // - point marker (take default value from preferences)
2625 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2626 QString( "%1%2%3" ).
2627 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2628 arg( GEOM::subSectionSeparator() ).
2629 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2631 // - top-level flag (false by default)
2632 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2637 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2638 SALOMEDS::Color aSColor;
2641 SUIT_Session* session = SUIT_Session::session();
2642 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2644 if ( app && !theGeomObject->_is_nil()) {
2645 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2648 _PTR(Study) aStudy = study->studyDS();
2649 aSColor = theGeomObject->GetColor();
2650 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2652 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2653 bool general_autocolor = true;
2654 #else // auto-color for groups only
2655 bool general_autocolor = false;
2656 #endif // GENERAL_AUTOCOLOR
2657 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2658 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2659 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2660 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2661 aSColor = getPredefinedUniqueColor();
2663 #else // old algorithm for auto-colors
2664 QList<SALOMEDS::Color> aReservedColors;
2665 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2666 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2667 if ( aMainSObject ) {
2668 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2669 for ( ; it->More(); it->Next() ) {
2670 _PTR(SObject) aChildSObject( it->Value() );
2671 GEOM::GEOM_Object_var aChildObject =
2672 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2673 if ( CORBA::is_nil( aChildObject ) )
2676 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2677 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2678 aReservedColors.append( aReservedColor );
2681 aSColor = getUniqueColor( aReservedColors );
2683 #endif // SIMPLE_AUTOCOLOR
2693 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2694 const bool eraseOnlyChildren) {
2695 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2699 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2703 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2708 // Erase from all views
2709 QList<SALOME_View*> views;
2711 ViewManagerList vmans = app->viewManagers();
2712 SUIT_ViewManager* vman;
2713 foreach ( vman, vmans ) {
2714 SUIT_ViewModel* vmod = vman->getViewModel();
2715 view = dynamic_cast<SALOME_View*> ( vmod );
2717 views.append( view );
2720 if( views.count() == 0 )
2723 //Erase childrens w/o update views
2724 DataObjectList listObj = parent->children( true );
2725 SUIT_DataObject* obj;
2726 foreach( obj, listObj ) {
2727 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2729 foreach ( view, views ) {
2730 Handle(SALOME_InteractiveObject) anIO =
2731 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2732 Erase(anIO, false, false, view);
2736 //Erase parent with view update or repaint views
2737 foreach ( view, views ) {
2738 if(!eraseOnlyChildren)
2739 Erase(theIO, false, true, view);
2745 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2747 if( theGeomFieldStep->_is_nil() )
2750 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2751 if( aGeomField->_is_nil() )
2754 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2755 if( aGeomFieldShape->_is_nil() )
2758 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2759 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2760 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2762 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2764 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2766 int aFieldDimension = aGeomField->GetDimension();
2768 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2769 int aFieldNbComponents = aFieldComponents->length();
2771 QList<QVariant> aFieldStepData;
2772 if( aFieldDataType == GEOM::FDT_Bool )
2774 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2775 if ( !aGeomBoolFieldStep->_is_nil() )
2777 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2778 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2779 aFieldStepData << (bool)aValues[i];
2782 else if( aFieldDataType == GEOM::FDT_Int )
2784 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2785 if ( !aGeomIntFieldStep->_is_nil() )
2787 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2788 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2789 aFieldStepData << (qlonglong)aValues[i];
2792 else if( aFieldDataType == GEOM::FDT_Double )
2794 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2795 if ( !aGeomDoubleFieldStep->_is_nil() )
2797 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2798 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2799 aFieldStepData << (double)aValues[i];
2802 else if( aFieldDataType == GEOM::FDT_String )
2804 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2805 if ( !aGeomStringFieldStep->_is_nil() )
2807 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2808 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2809 aFieldStepData << QString( aValues[i] );
2813 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2814 aFieldStepData = groupFieldData( aFieldStepData,
2816 aFieldDataType == GEOM::FDT_String,
2818 aFieldStepRangeMax );
2820 setFieldStepInfo( aFieldDataType,
2825 aFieldStepRangeMax );
2828 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2829 const int theFieldNbComponents,
2830 const bool theIsString,
2831 double& theFieldStepRangeMin,
2832 double& theFieldStepRangeMax )
2834 QList<QVariant> aResultList;
2835 theFieldStepRangeMin = 0;
2836 theFieldStepRangeMax = 0;
2838 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2841 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2843 QList<QVariant> aGroupedList;
2845 bool anIsBoolean = false;
2846 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2849 QStringList aStringList;
2851 int aBaseIndex = aSubShape * theFieldNbComponents;
2852 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2854 int anIndex = aComponent + aBaseIndex;
2856 const QVariant& aVariant = theFieldStepData[ anIndex ];
2859 if( aVariant.type() == QVariant::String )
2860 aStringList << aVariant.toString();
2865 if( aVariant.type() == QVariant::Bool )
2867 aValue = aVariant.toBool() ? 1.0 : 0.0;
2873 if( aVariant.type() == QVariant::LongLong )
2874 aValue = double( aVariant.toLongLong() );
2875 else if( aVariant.type() == QVariant::Double )
2876 aValue = aVariant.toDouble();
2877 aNorm += aValue * aValue;
2883 aGroupedList << aStringList.join( "\n" );
2887 aNorm /= theFieldNbComponents;
2889 aNorm = pow( aNorm, 0.5 );
2891 if( aGroupedList.isEmpty() )
2892 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2895 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2896 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2899 aGroupedList << aNorm;
2905 theFieldStepRangeMin = 0.0;
2906 theFieldStepRangeMax = 1.0;
2909 SUIT_Session* session = SUIT_Session::session();
2910 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2911 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2913 QListIterator<QVariant> anIter( aGroupedList );
2914 while( anIter.hasNext() )
2916 const QVariant& aVariant = anIter.next();
2918 aResultList << aVariant;
2922 Quantity_Color aColor;
2923 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2924 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2925 aResultList << aQColor;
2931 // Note: the method is copied from AIS_ColorScale class
2932 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2933 const Standard_Integer aMin,
2934 const Standard_Integer aMax )
2936 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2938 Standard_Integer aHue = maxLimit;
2940 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2942 aHue = Min( Max( minLimit, aHue ), maxLimit );
2947 // Note: the method is copied from AIS_ColorScale class
2948 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2949 const Standard_Real aMin,
2950 const Standard_Real aMax,
2951 const Standard_Integer ColorsCount,
2952 Quantity_Color& aColor )
2954 if( aValue<aMin || aValue>aMax || aMax<aMin )
2955 return Standard_False;
2959 Standard_Real IntervNumber = 0;
2962 else if( aValue>aMax )
2963 IntervNumber = ColorsCount-1;
2964 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2965 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2967 Standard_Integer Interv = Standard_Integer( IntervNumber );
2969 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2971 return Standard_True;
2975 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2977 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2981 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2985 #if OCC_VERSION_MAJOR < 7
2986 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2987 if( aViewer.IsNull() )
2990 aViewer->InitActiveViews();
2991 if( !aViewer->MoreActiveViews() )
2994 Handle(V3d_View) aView = aViewer->ActiveView();
2995 if( aView.IsNull() )
2999 Standard_Boolean anIsDisplayColorScale = Standard_False;
3000 TCollection_AsciiString aColorScaleTitle;
3001 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
3002 Standard_Boolean anIsBoolean = Standard_False;
3004 SALOME_ListIO aSelectedObjects;
3005 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
3006 if( aSelectedObjects.Extent() == 1 )
3008 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
3009 if( !anIO.IsNull() )
3011 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
3014 AIS_ListOfInteractive aList;
3015 aPrs->GetObjects( aList );
3016 AIS_ListIteratorOfListOfInteractive anIter( aList );
3017 for( ; anIter.More(); anIter.Next() )
3019 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
3020 if( !aShape.IsNull() )
3022 GEOM::field_data_type aFieldDataType;
3023 int aFieldDimension;
3024 QList<QVariant> aFieldStepData;
3025 TCollection_AsciiString aFieldStepName;
3026 double aFieldStepRangeMin, aFieldStepRangeMax;
3027 aShape->getFieldStepInfo( aFieldDataType,
3032 aFieldStepRangeMax );
3033 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3035 anIsDisplayColorScale = Standard_True;
3036 aColorScaleTitle = aFieldStepName;
3037 aColorScaleMin = aFieldStepRangeMin;
3038 aColorScaleMax = aFieldStepRangeMax;
3039 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3047 if( anIsDisplayColorScale )
3049 SUIT_Session* session = SUIT_Session::session();
3050 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3052 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3053 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3054 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3055 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3056 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3057 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3059 #if OCC_VERSION_MAJOR < 7
3060 Handle(Aspect_ColorScale) myColorScale = aView->ColorScale();
3061 if( !myColorScale.IsNull() )
3065 myColorScale->SetXPosition( anXPos );
3066 myColorScale->SetYPosition( anYPos );
3067 myColorScale->SetWidth( aWidth );
3068 myColorScale->SetHeight( aHeight );
3070 myColorScale->SetTextHeight( aTextHeight );
3071 myColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3073 myColorScale->SetTitle( aColorScaleTitle );
3074 myColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3076 #if OCC_VERSION_MAJOR < 7
3078 if( !aView->ColorScaleIsDisplayed() )
3079 aView->ColorScaleDisplay();
3082 if( aView->ColorScaleIsDisplayed() )
3083 aView->ColorScaleErase();
3085 if( !aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3086 aViewModel->getAISContext()->Display( myColorScale );
3089 if( aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3090 aViewModel->getAISContext()->Erase( myColorScale );
3093 if( theIsRedisplayFieldSteps )
3095 _PTR(Study) aStudyDS = aStudy->studyDS();
3096 QList<SUIT_ViewManager*> vmList;
3097 myApp->viewManagers( vmList );
3098 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3100 if( SUIT_ViewManager* aViewManager = *vmIt )
3102 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3103 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3105 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3108 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3109 if( !CORBA::is_nil( anObject ) )
3111 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3112 if( !aFieldStep->_is_nil() )
3114 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3115 Handle(SALOME_InteractiveObject) aStepIO =
3116 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3117 Redisplay( aStepIO, false, false );