1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
28 #include "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
59 #include <Basics_OCCTVersion.hxx>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
68 #include <SALOME_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_Drawer.hxx>
84 #include <AIS_Dimension.hxx>
85 #include <AIS_LengthDimension.hxx>
86 #include <AIS_DiameterDimension.hxx>
87 #include <AIS_AngleDimension.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <Aspect_PolygonOffsetMode.hxx>
90 #include <Aspect_ColorScale.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <StdSelect_TypeOfEdge.hxx>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <StdSelect_DisplayMode.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <BRep_Tool.hxx>
98 #include <Geom_Plane.hxx>
99 #include <Geom_Axis2Placement.hxx>
100 #include <Graphic3d_AspectFillArea3d.hxx>
101 #include <gp_Pln.hxx>
102 #include <TColStd_MapOfInteger.hxx>
103 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
104 #include <TopoDS_Iterator.hxx>
105 #include <Graphic3d_AspectMarker3d.hxx>
106 #include <TopTools_MapOfShape.hxx>
107 #include <TopTools_ListOfShape.hxx>
108 #include <TopTools_ListIteratorOfListOfShape.hxx>
109 #include <TopoDS.hxx>
110 #include <NCollection_DataMap.hxx>
111 #include <NCollection_Map.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #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 only for testing purpose
500 // and if the corresponding env variable is set to 1
501 char* parallel_visu = getenv("PARALLEL_VISU");
502 if (parallel_visu && atoi(parallel_visu))
504 MESSAGE("Parallel visualisation on");
505 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
510 myFieldDataType = GEOM::FDT_Double;
511 myFieldDimension = 0;
512 myFieldStepRangeMin = 0;
513 myFieldStepRangeMax = 0;
516 //=================================================================
518 * GEOM_Displayer::~GEOM_Displayer
521 //=================================================================
522 GEOM_Displayer::~GEOM_Displayer()
526 //=================================================================
528 * GEOM_Displayer::Display
529 * Display interactive object in the current viewer
531 //=================================================================
532 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
533 const bool updateViewer,
534 SALOME_View* theViewFrame )
536 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
539 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
543 vf->BeforeDisplay( this, prs );
544 vf->Display( this, prs );
545 vf->AfterDisplay( this, prs );
550 delete prs; // delete presentation because displayer is its owner
555 //=================================================================
557 * GEOM_Displayer::Display
558 * This overloaded Display() method can be useful for operations
559 * not using dialog boxes.
561 //=================================================================
562 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
564 if ( theObj->_is_nil() )
567 std::string entry = getEntry( theObj );
569 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
574 //=================================================================
576 * GEOM_Displayer::Erase
577 * Erase interactive object in the current viewer
579 //=================================================================
580 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
582 const bool updateViewer,
583 SALOME_View* theViewFrame )
585 if ( theIO.IsNull() )
588 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
591 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
593 vf->BeforeErase( this, prs );
594 vf->Erase( this, prs, forced );
595 vf->AfterErase( this, prs );
598 delete prs; // delete presentation because displayer is its owner
603 //=================================================================
605 * GEOM_Displayer::Erase
606 * Erase geometry object in the current viewer
608 //=================================================================
609 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
611 const bool updateViewer,
612 SALOME_View* theViewFrame)
614 std::string entry = getEntry( theObj );
617 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
618 forced, updateViewer, theViewFrame);
622 //=================================================================
624 * GEOM_Displayer::Redisplay
625 * Redisplay (erase and then display again) interactive object
626 * in the current viewer
628 //=================================================================
629 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
630 const bool updateViewer,
631 const bool checkActiveViewer )
633 // Remove the object permanently (<forced> == true)
634 SUIT_Session* ses = SUIT_Session::session();
635 SUIT_Application* app = ses->activeApplication();
638 SUIT_Desktop* desk = app->desktop();
639 QList<SUIT_ViewWindow*> wnds = desk->windows();
640 SUIT_ViewWindow* wnd;
641 QListIterator<SUIT_ViewWindow*> it( wnds );
642 while ( it.hasNext() && (wnd = it.next()) )
644 SUIT_ViewManager* vman = wnd->getViewManager();
647 SUIT_ViewModel* vmodel = vman->getViewModel();
650 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
653 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
655 Redisplay( theIO, updateViewer, view );
664 //=================================================================
666 * GEOM_Displayer::Redisplay
667 * Redisplay (erase and then display again) interactive object
668 * in the specified view
670 //=================================================================
671 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
672 const bool theUpdateViewer,
673 SALOME_View* theViewFrame )
675 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
681 Erase( theIO, true, false, theViewFrame );
682 Display( theIO, theUpdateViewer, theViewFrame );
685 //=================================================================
687 * GEOM_Displayer::Display
688 * Calls Display() method for each object in the given list
690 //=================================================================
691 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
693 SALOME_ListIteratorOfListIO Iter( theIOList );
694 for ( ; Iter.More(); Iter.Next() ) {
695 Display( Iter.Value(), false );
701 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
703 SalomeApp_Study* aStudy = getStudy();
705 if ( v ) vId = getViewManagerId( v );
708 QString entry = p->GetEntry();
709 if ( !entry.isEmpty() ) {
711 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
712 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
717 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
722 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
724 // VSR: this method can be improved in future:
725 // to improve performance, the default values from resource manager should be cached in the displayer
726 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
729 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
731 // VSR: this method can be improved in future:
732 // to improve performance, the default values from resource manager should be cached in the displayer
733 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
736 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
738 // check that shape is not null
739 if ( AISShape.IsNull() ) return;
741 // check that study is active
742 SalomeApp_Study* study = getStudy();
743 if ( !study ) return;
745 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
746 !TopoDS_Iterator(myShape).More() )
747 return; // NPAL15983 (Bug when displaying empty groups)
749 // set interactive object
751 Handle( SALOME_InteractiveObject ) anIO;
753 if ( !myIO.IsNull() ) {
754 AISShape->setIO( myIO );
755 AISShape->SetOwner( myIO );
758 else if ( !myName.empty() ) {
759 // workaround to allow selection of temporary objects
760 static int tempId = 0;
761 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
762 AISShape->setIO( anIO );
763 AISShape->SetOwner( anIO );
766 // flag: only vertex or compound of vertices is processed (specific handling)
767 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
768 // presentation study entry (empty for temporary objects like preview)
769 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
770 // flag: temporary object
771 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
772 // currently active view window's ID (-1 if no active view)
773 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
775 // get presentation properties
776 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
778 // Temporary staff: vertex must be infinite for correct visualization
779 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
782 Material_Model material;
783 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
785 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
786 // - set front material properties
787 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
788 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
789 // - set back material properties
790 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
791 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
792 // - switch to default (both sides) facing mode
793 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
799 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
800 // we set it to the shape not taking into account material properties
801 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
803 else if ( !material.isPhysical() ) {
804 // shading color from properties is used only for non-physical materials
805 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
809 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
810 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
811 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
812 AISShape->Attributes()->SetLineAspect( anAspect );
814 // - unfree boundaries color
815 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
816 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
817 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
818 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
820 // - free boundaries color
821 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
822 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
823 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
824 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
826 // - standalone edges color
827 anAspect = AISShape->Attributes()->WireAspect();
828 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
829 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
830 AISShape->Attributes()->SetWireAspect( anAspect );
832 // - color for edges in shading+edges mode
833 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
836 AISShape->SetDisplayMode( HasDisplayMode() ?
837 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
839 // display mode from properties
840 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
842 // - face boundaries color
843 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
844 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
845 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
846 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
847 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
849 // set display vectors flag
850 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
852 // set display vertices flag
853 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
854 AISShape->SetDisplayVertices( isVerticesMode );
857 if( HasTransparency() ) {
858 AISShape->SetTransparency( GetTransparency() );
860 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
863 // set iso properties
864 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
865 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
866 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
867 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
868 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
869 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
871 if ( HasIsosColor() ) {
872 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
873 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
876 uIsoAspect->SetColor( isosColor );
877 vIsoAspect->SetColor( isosColor );
880 if ( HasIsosWidth() ) {
881 uIsoAspect->SetWidth( GetIsosWidth() );
882 vIsoAspect->SetWidth( GetIsosWidth() );
885 uIsoAspect->SetWidth( isosWidth );
886 vIsoAspect->SetWidth( isosWidth );
890 uIsoAspect->SetNumber( GetNbIsos() );
891 vIsoAspect->SetNumber( GetNbIsos() );
894 uIsoAspect->SetNumber( uIsos );
895 vIsoAspect->SetNumber( vIsos );
898 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
899 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
901 // set deflection coefficient
902 // ... to avoid to small values of the coefficient, its lower value is limited
903 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
907 if ( HasTexture() ) {
908 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
909 aImagePath = GetTexture().c_str();
910 if ( ! entry.isEmpty() ) {
911 // check that study is active
912 SalomeApp_Study* study = getActiveStudy();
914 // Store the texture in object properties for next displays
915 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
916 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
918 // Update propeties map
919 propMap = getObjectProperties( study, entry, myViewFrame );
924 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
927 #ifdef USE_TEXTURED_SHAPE
928 Handle(Image_PixMap) aPixmap;
929 if ( !aImagePath.isEmpty() )
930 aPixmap = cacheTextureFor( aImagePath, AISShape );
932 aPixmap = getDefaultTexture();
934 // apply image to shape
935 if ( !aPixmap.IsNull() ) {
936 AISShape->SetTexturePixMap( aPixmap );
937 AISShape->SetTextureMapOn();
938 AISShape->DisableTextureModulate();
941 AISShape->SetTextureMapOff();
946 AISShape->SetWidth( HasWidth() ?
947 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
949 // libe width from properties
950 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
952 // set top-level flag
953 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
955 // set point marker (for vertex / compound of vertices only)
956 if ( onlyVertex || isVerticesMode ) {
957 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
958 if ( aList.size() == 2 ) {
959 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
960 int aTypeOfMarker = aList[0].toInt();
961 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
962 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
963 anAspect->SetScale( aScaleOfMarker );
964 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
965 anAspect->SetColor( HasColor() ?
966 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
967 (Quantity_NameOfColor)GetColor() :
968 // color from properties
969 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
970 AISShape->Attributes()->SetPointAspect( anAspect );
972 else if ( aList.size() == 1 ) {
973 // custom marker string contains "IdOfTexture"
974 int textureId = aList[0].toInt();
975 Standard_Integer aWidth, aHeight;
976 Handle(TColStd_HArray1OfByte) aTexture =
977 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
978 if ( !aTexture.IsNull() ) {
979 Handle(Prs3d_PointAspect) aTextureAspect =
980 new Prs3d_PointAspect( HasColor() ?
981 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
982 (Quantity_NameOfColor)GetColor() :
983 // color from properties
984 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
987 AISShape->Attributes()->SetPointAspect( aTextureAspect );
992 // set field step data
993 AISShape->setFieldStepInfo( myFieldDataType,
998 myFieldStepRangeMax );
1000 if ( create && !isTemporary && aMgrId != -1 ) {
1001 // set properties to the study
1002 study->setObjectProperties( aMgrId, entry, propMap );
1005 // AISShape->SetName(???); ??? necessary to set name ???
1008 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1010 // check that actor is not null
1011 if ( !actor ) return;
1013 // check that study is active
1014 SalomeApp_Study* study = getStudy();
1015 if ( !study ) return;
1017 // set interactive object
1019 Handle( SALOME_InteractiveObject ) anIO;
1021 if ( !myIO.IsNull() ) {
1022 actor->setIO( myIO );
1025 else if ( !myName.empty() ) {
1026 // workaround to allow selection of temporary objects
1027 static int tempId = 0;
1028 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1029 actor->setIO( anIO );
1032 // presentation study entry (empty for temporary objects like preview)
1033 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1034 // flag: temporary object
1035 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1036 // currently active view window's ID (-1 if no active view)
1037 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1039 // get presentation properties
1040 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1043 /////////////////////////////////////////////////////////////////////////
1044 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1045 // due to performance problem
1046 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1047 /////////////////////////////////////////////////////////////////////////
1048 if ( !actor->getTopo().IsSame( myShape ) )
1049 #ifdef LIMIT_DEFLECTION_FOR_VTK
1050 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1052 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1056 Material_Model material;
1057 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1058 std::vector<vtkProperty*> mprops;
1059 mprops.push_back( material.getMaterialVTKProperty( true ) );
1060 mprops.push_back( material.getMaterialVTKProperty( false) );
1061 actor->SetMaterial( mprops );
1063 // set iso-lines properties
1065 // - set number of iso-lines
1066 int nbIsos[2]= { 1, 1 };
1067 if ( HasNbIsos() ) {
1068 nbIsos[0] = GetNbIsos();
1069 nbIsos[1] = GetNbIsos();
1072 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1073 nbIsos[0] = isos[0].toInt();
1074 nbIsos[1] = isos[1].toInt();
1076 actor->SetNbIsos( nbIsos );
1078 // - set iso-lines width
1079 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1081 // - set iso-lines color
1082 if ( HasIsosColor() )
1083 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1085 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1086 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1091 // - same color for all sub-actors
1092 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1093 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1096 // shading color (for non-physical materials)
1097 if ( !material.isPhysical() ) {
1098 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1099 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1100 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1103 // - standalone edge color
1104 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1105 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1107 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1108 // - shared edges color ???
1109 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1111 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1112 // - free edges color ???
1113 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1116 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1117 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1120 // - color for edges in shading+edges mode
1121 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1122 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1125 if( HasTransparency() ) {
1126 actor->SetOpacity( 1.0 - GetTransparency() );
1128 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1132 actor->SetWidth( HasWidth() ?
1133 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1135 // libe width from properties
1136 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1138 // set display vectors flag
1139 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1141 // set display vertices flag
1142 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1145 int displayMode = HasDisplayMode() ?
1146 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1148 // display mode from properties
1149 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1151 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1152 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1153 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1154 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1156 if ( displayMode == 2 )
1157 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1158 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1160 actor->setDisplayMode( displayMode );
1163 actor->PickableOn();
1165 actor->PickableOff();
1167 if ( create && !isTemporary && aMgrId != -1 ) {
1168 // set properties to the study
1169 study->setObjectProperties( aMgrId, entry, propMap );
1173 //=================================================================
1175 * GEOM_Displayer::updateDimensions
1176 * Creates or renews dimension presentation for the IO.
1178 //=================================================================
1179 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1180 SALOME_OCCPrs* thePrs,
1181 const gp_Ax3& theShapeLCS )
1183 SalomeApp_Study* aStudy = getStudy();
1189 if ( theIO.IsNull() )
1194 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1196 AIS_ListOfInteractive aListOfIO;
1198 anOccPrs->GetObjects( aListOfIO );
1200 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1202 // remove outdated presentations of dimensions
1203 for ( ; aIterateIO.More(); aIterateIO.Next() )
1205 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1206 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1211 aListOfIO.Remove( aIterateIO );
1213 if ( !aIterateIO.More() )
1219 // prepare dimension styling
1220 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1222 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1223 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1224 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1225 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1226 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1227 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1228 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1230 // restore dimension presentation from saved attribute or property data
1231 AIS_ListOfInteractive aRestoredDimensions;
1233 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1235 GEOM::propertyName( GEOM::Dimensions ),
1238 GEOMGUI_DimensionProperty aRecords;
1240 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1242 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1246 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1249 // create up-to-date dimension presentations
1250 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1252 if ( !aRecords.IsVisible( aPrsIt ) )
1257 // init dimension by type
1258 Handle(AIS_Dimension) aPrs;
1259 switch( aRecords.GetType( aPrsIt ) )
1261 case GEOMGUI_DimensionProperty::DimensionType_Length :
1263 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1264 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1269 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1271 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1272 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1277 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1279 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1280 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1286 aPrs->SetOwner( theIO );
1288 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1290 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1292 aStyle->SetCommonColor( aColor );
1293 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1294 aStyle->MakeText3d( Standard_True );
1295 aStyle->MakeTextShaded( Standard_True );
1296 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1297 aStyle->TextAspect()->SetHeight( aFontHeight );
1298 aStyle->ArrowAspect()->SetLength( anArrowLength );
1299 aStyle->LineAspect()->SetWidth( aLineWidth );
1300 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1301 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1302 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1303 aPrs->SetDimensionAspect( aStyle );
1304 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1305 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1306 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1308 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1310 // show degree symbol for dimension instead of label "deg"
1311 if ( aUnitsAngle == "deg" )
1313 aPrs->SetSpecialSymbol(0xB0);
1314 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1315 aStyle->MakeUnitsDisplayed(Standard_False);
1319 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1320 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1325 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1328 aListOfIO.Append( aPrs );
1331 // update presentation
1334 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1336 anOccPrs->AddObject( aIterateIO.Value() );
1340 //=================================================================
1342 * GEOM_Displayer::Erase
1343 * Calls Erase() method for each object in the given list
1345 //=================================================================
1346 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1348 const bool updateViewer )
1350 SALOME_ListIteratorOfListIO Iter( theIOList );
1351 for ( ; Iter.More(); Iter.Next() )
1352 Erase( Iter.Value(), forced, false );
1358 //=================================================================
1360 * GEOM_Displayer::Redisplay
1361 * Calls Redisplay() method for each object in the given list
1363 //=================================================================
1364 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1365 const bool updateViewer,
1366 const bool checkActiveViewer )
1368 SALOME_ListIteratorOfListIO Iter( theIOList );
1369 for ( ; Iter.More(); Iter.Next() )
1370 Redisplay( Iter.Value(), false, checkActiveViewer );
1376 //=================================================================
1378 * GEOM_Displayer::Redisplay
1379 * Calls Redisplay() method for each object in the given list
1381 //=================================================================
1382 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1383 const bool theUpdateViewer,
1384 SALOME_View* theViewFrame )
1386 SALOME_ListIteratorOfListIO anIter( theIOList );
1387 for ( ; anIter.More(); anIter.Next() )
1389 Redisplay( anIter.Value(), false, theViewFrame );
1392 if ( theUpdateViewer )
1398 //=================================================================
1400 * GEOM_Displayer::Update
1401 * Update OCC presentaion
1402 * [ Reimplemented from SALOME_Displayer ]
1404 //=================================================================
1405 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1407 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1408 SalomeApp_Study* study = getStudy();
1410 if ( !occPrs || myShape.IsNull() || !study )
1413 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1416 // specific processing for local coordinate system presentation
1419 TopoDS_Face aFace = TopoDS::Face( myShape );
1420 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1421 if ( !aPlane.IsNull() )
1423 gp_Ax3 aPos = aPlane->Pln().Position();
1424 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1426 Handle(GEOM_AISTrihedron) aTrh;
1428 if ( occPrs->IsNull() )
1430 // new presentation is being created
1431 aTrh = new GEOM_AISTrihedron( aPlc );
1432 occPrs->AddObject( aTrh );
1436 // presentation is being updated
1437 AIS_ListOfInteractive aList;
1438 occPrs->GetObjects( aList );
1439 AIS_ListIteratorOfListOfInteractive anIter( aList );
1440 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1441 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1445 if ( !aTrh.IsNull() ) {
1446 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1448 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1449 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1451 aTrh->SetWidth( GetWidth() );
1453 if ( !myIO.IsNull() )
1455 aTrh->setIO( myIO );
1456 aTrh->SetOwner( myIO );
1458 aTrh->SetComponent( aPlc );
1459 aTrh->SetToUpdate();
1461 occPrs->SetToActivate( ToActivate() );
1467 // processing for usual geometry presentation
1470 // if presentation is empty we try to create new one
1471 if ( occPrs->IsNull() )
1473 // create presentation (specific for vectors)
1474 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1475 : new GEOM_AISShape ( myShape, "" );
1477 if( myType == GEOM_FIELD_STEP )
1478 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1479 // update shape properties
1480 updateShapeProperties( AISShape, true );
1482 // add shape to the presentation
1483 occPrs->AddObject( AISShape );
1485 // In accordance with ToActivate() value object will be activated/deactivated
1486 // when it will be displayed
1487 occPrs->SetToActivate( ToActivate() );
1489 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1490 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1492 // create additional wireframe shape
1493 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1494 aWirePrs->SetWidth(AISShape->Width());
1495 if ( !myIO.IsNull() ) {
1496 aWirePrs->setIO( myIO );
1497 aWirePrs->SetOwner( myIO );
1500 // add shape to the presentation
1501 occPrs->AddObject( aWirePrs );
1504 // if presentation is found -> set again shape for it
1507 AIS_ListOfInteractive IOList;
1508 occPrs->GetObjects( IOList );
1509 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1510 for ( ; Iter.More(); Iter.Next() )
1512 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1513 if ( AISShape.IsNull() )
1516 // re-set shape (it might be changed)
1517 if ( AISShape->Shape() != myShape )
1518 AISShape->Set( myShape );
1520 // update shape properties
1521 updateShapeProperties( AISShape, false );
1524 AISShape->UpdateSelection();
1525 AISShape->SetToUpdate();
1529 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1533 //=================================================================
1535 * GEOM_Displayer::Update
1536 * Update VTK presentaion
1537 * [ Reimplemented from SALOME_Displayer ]
1539 //=================================================================
1540 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1542 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1543 SalomeApp_Study* study = getStudy();
1545 if ( !vtkPrs || myShape.IsNull() || !study )
1548 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1551 // specific processing for local coordinate system presentation
1554 TopoDS_Face aFace = TopoDS::Face( myShape );
1555 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1556 if ( !aPlane.IsNull() ) {
1557 gp_Ax3 aPos = aPlane->Pln().Position();
1558 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1560 GEOM_VTKTrihedron* aTrh = 0;
1562 if ( vtkPrs->IsNull() ) {
1563 // new presentation is being created
1564 aTrh = GEOM_VTKTrihedron::New();
1565 vtkPrs->AddObject( aTrh );
1568 // presentation is being updated
1569 vtkActorCollection* actors = vtkPrs->GetObjects();
1571 actors->InitTraversal();
1572 vtkActor* a = actors->GetNextActor();
1573 while ( a && !aTrh ) {
1574 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1575 a = actors->GetNextActor();
1581 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1583 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1584 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1586 #ifdef VTK_TRIHEDRON_WIDTH
1588 // VSR: currently isn't supported
1590 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1592 aTrh->SetWidth( GetWidth() );
1595 if ( !myIO.IsNull() )
1596 aTrh->setIO( myIO );
1598 aTrh->SetPlacement( aPlc );
1605 // processing for usual geometry presentation
1608 // if presentation is empty we try to create new one
1609 if ( vtkPrs->IsNull() )
1612 GEOM_Actor* actor = GEOM_Actor::New();
1613 // update actor properties
1614 updateActorProperties( actor, true );
1615 // add actor to the presentation
1616 vtkPrs->AddObject( actor );
1619 // presentation is being updated
1620 vtkActorCollection* actors = vtkPrs->GetObjects();
1622 actors->InitTraversal();
1623 vtkActor* a = actors->GetNextActor();
1625 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1627 // update actor properties
1628 updateActorProperties( actor, false );
1629 a = actors->GetNextActor();
1637 //=================================================================
1639 * GEOM_Displayer::BuildPrs
1640 * Build presentation accordint to the current viewer type
1642 //=================================================================
1643 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1645 if ( theObj->_is_nil() )
1648 myViewFrame = GetActiveView();
1649 if ( myViewFrame == 0 )
1652 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1657 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1658 myType = theObj->GetType();
1660 // Update presentation
1666 //=================================================================
1668 * GEOM_Displayer::BuildPrs
1669 * Build presentation accordint to the current viewer type
1671 //=================================================================
1672 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1674 myViewFrame = GetActiveView();
1675 if ( theShape.IsNull() || myViewFrame == 0 )
1678 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1683 setShape( theShape );
1691 //=================================================================
1693 * GEOM_Displayer::buildPresentation
1694 * Builds/finds object's presentation for the current viewer
1695 * Calls corresponding Update() method by means of double dispatch
1698 //=================================================================
1699 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1700 SALOME_View* theViewFrame )
1702 SALOME_Prs* prs = 0;
1705 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1709 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1712 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1713 theIO->setEntry( entry.toLatin1().constData() );
1714 if ( !theIO.IsNull() )
1716 // set interactive object
1718 // Find SOBject (because shape should be published previously)
1719 SUIT_Session* session = SUIT_Session::session();
1720 SUIT_Application* app = session->activeApplication();
1723 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1726 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1729 // get CORBA reference to data object
1730 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1731 if ( !CORBA::is_nil( object ) )
1733 // downcast to GEOM base object
1734 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1735 if ( !GeomBaseObject->_is_nil() )
1737 myType = GeomBaseObject->GetType();
1739 // downcast to GEOM object
1740 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1741 if ( myType == GEOM_FIELD_STEP )
1743 // get the GEOM object from the field's shape
1744 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1745 if ( !GeomFieldStep->_is_nil() )
1747 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1748 if ( !GeomField->_is_nil() )
1749 GeomObject = GeomField->GetShape();
1752 // read the field step information
1753 readFieldStepInfo( GeomFieldStep );
1756 if ( !GeomObject->_is_nil() )
1758 // finally set shape
1759 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1767 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1773 //=================================================================
1775 * GEOM_Displayer::buildSubshapePresentation
1776 * Builds/finds object's presentation for the current viewer
1777 * Calls corresponding Update() method by means of double dispatch
1778 * For not published objects (for Mantis issue 0020435)
1780 //=================================================================
1781 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1782 const QString& entry,
1783 SALOME_View* theViewFrame)
1785 SALOME_Prs* prs = 0;
1788 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1792 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1795 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1796 theIO->setEntry(entry.toLatin1().constData());
1797 if (!theIO.IsNull())
1799 // set interactive object
1801 // finally set shape
1803 myType = GEOM_SUBSHAPE;
1805 UpdatePrs(prs); // Update presentation by using of the double dispatch
1811 //=================================================================
1813 * GEOM_Displayer::internalReset
1814 * Resets internal data
1817 //=================================================================
1818 void GEOM_Displayer::internalReset()
1823 myFieldDataType = GEOM::FDT_Double;
1824 myFieldDimension = 0;
1825 myFieldStepData.clear();
1826 myFieldStepName.Clear();
1827 myFieldStepRangeMin = 0;
1828 myFieldStepRangeMax = 0;
1831 //=================================================================
1833 * GEOM_Displayer::LocalSelection
1834 * Activate selection of CAD shapes with activisation of selection
1835 * of their sub-shapes (with opened local context for OCC viewer)
1837 //=================================================================
1838 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1840 SUIT_Session* session = SUIT_Session::session();
1841 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1845 LightApp_SelectionMgr* sm = app->selectionMgr();
1847 // remove all filters from selection
1850 SALOME_View* vf = GetActiveView();
1852 if (!theIO.IsNull() && !vf->isVisible(theIO))
1854 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1855 vf->LocalSelection( prs, modes );
1856 delete prs; // delete presentation because displayer is its owner
1860 //=================================================================
1862 * GEOM_Displayer::LocalSelection
1863 * Activate selection of CAD shapes with activisation of selection
1864 * of their sub-shapes (with opened local context for OCC viewer)
1866 //=================================================================
1867 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1869 std::list<int> modes;
1870 modes.push_back( theMode );
1871 LocalSelection( theIO, modes );
1874 //=================================================================
1876 * GEOM_Displayer::globalSelection
1877 * Activate selection of CAD shapes without activisation of selection
1878 * of their sub-shapes (without opened local context for OCC viewer)
1880 //=================================================================
1881 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1883 TColStd_MapOfInteger aModes;
1884 aModes.Add( theMode );
1885 GlobalSelection( aModes, update );
1888 //=================================================================
1890 * GEOM_Displayer::globalSelection
1891 * Activate selection of CAD shapes without activisation of selection
1892 * of their sub-shapes (without opened local context for OCC viewer)
1894 //=================================================================
1895 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1896 const bool update, const QList<int>* theSubShapes )
1898 SUIT_Session* session = SUIT_Session::session();
1899 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1903 SALOME_View* vf = GetActiveView();
1907 // Close local context
1908 vf->GlobalSelection( update );
1910 // Set selection filters in accordance with current mode
1911 LightApp_SelectionMgr* sm = app->selectionMgr();
1915 // Remove from selection temporary objects if necessary
1916 if ( !theModes.Contains( GEOM_PREVIEW ) )
1917 clearTemporary( sm );
1919 //@ aSel->ClearIndex();
1923 // Remove filters from AIS_InteractiveContext
1924 Handle(AIS_InteractiveContext) ic;
1925 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1928 ic = viewer->getAISContext();
1930 ic->RemoveFilters();
1933 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1936 SUIT_SelectionFilter* aFilter;
1937 if ( theModes.Extent() == 1 )
1939 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1941 if ( aMode == GEOM_COMPOUNDFILTER )
1942 aFilter = getComplexFilter( theSubShapes );
1944 aFilter = getFilter( aMode );
1946 else if ( theModes.Extent() > 1 )
1948 TColStd_MapOfInteger aTopAbsModes;
1949 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1950 QList<SUIT_SelectionFilter*> aListOfFilters;
1951 for ( ; anIter.More(); anIter.Next() )
1953 SUIT_SelectionFilter* aFilter;
1954 int aMode = anIter.Key();
1955 if ( aMode == GEOM_COMPOUNDFILTER )
1956 aFilter = getComplexFilter( theSubShapes );
1958 aFilter = getFilter( aMode );
1961 aListOfFilters.append( aFilter );
1964 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1971 sm->installFilter( aFilter );
1974 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1975 ic->AddFilter( anOCCFilter );
1980 //=================================================================
1982 * GEOM_Displayer::LocalSelection
1983 * Activate selection of CAD shapes with activisation of selection
1984 * of their sub-shapes (with opened local context for OCC viewer)
1986 //=================================================================
1987 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
1989 SALOME_ListIteratorOfListIO Iter( theIOList );
1990 for ( ; Iter.More(); Iter.Next() )
1991 LocalSelection( Iter.Value(), modes );
1994 //=================================================================
1996 * GEOM_Displayer::LocalSelection
1997 * Activate selection of CAD shapes with activisation of selection
1998 * of their sub-shapes (with opened local context for OCC viewer)
2000 //=================================================================
2001 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2003 std::list<int> modes;
2004 modes.push_back( theMode );
2005 LocalSelection( theIOList, modes );
2008 //=================================================================
2010 * GEOM_Displayer::BeforeDisplay
2011 * Called before displaying of pars. Close local context
2012 * [ Reimplemented from SALOME_Displayer ]
2014 //=================================================================
2015 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2017 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2020 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2023 if ( ic->HasOpenedContext() )
2024 ic->CloseAllContexts();
2029 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2031 UpdateColorScale(false,false);
2034 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2036 LightApp_Displayer::BeforeErase( v, p );
2037 releaseTextures( p );
2040 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2042 LightApp_Displayer::AfterErase( v, p );
2043 UpdateColorScale(false,false);
2046 //=================================================================
2048 * GEOM_Displayer::SetColor
2049 * Set color for shape displaying. If it is equal -1 then default color is used.
2050 * Available values are from Quantity_NameOfColor enumeration
2052 //=================================================================
2053 void GEOM_Displayer::SetColor( const int color )
2060 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2064 int GEOM_Displayer::GetColor() const
2069 bool GEOM_Displayer::HasColor() const
2071 return myColor != -1;
2074 void GEOM_Displayer::UnsetColor()
2078 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2079 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2080 myShadingColor = SalomeApp_Tools::color( col );
2083 //=================================================================
2085 * GEOM_Displayer::SetTransparency
2086 * Set transparency for shape displaying.
2088 //=================================================================
2089 double GEOM_Displayer::SetTransparency( const double transparency )
2091 double prevTransparency = myTransparency;
2092 myTransparency = transparency;
2093 return prevTransparency;
2096 //=================================================================
2098 * GEOM_Displayer::GetTransparency
2099 * Get transparency for shape displaying.
2101 //=================================================================
2102 double GEOM_Displayer::GetTransparency() const
2104 return myTransparency;
2107 //=================================================================
2109 * GEOM_Displayer::HasTransparency
2110 * Check if transparency for shape displaying is set.
2112 //=================================================================
2113 bool GEOM_Displayer::HasTransparency() const
2115 return myTransparency >= 0;
2118 //=================================================================
2120 * GEOM_Displayer::UnsetTransparency
2121 * Unset transparency for shape displaying.
2123 //=================================================================
2124 double GEOM_Displayer::UnsetTransparency()
2126 return SetTransparency( -1 );
2129 //=================================================================
2131 * GEOM_Displayer::SetTexture
2133 //=================================================================
2134 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2136 myTexture = texureFileName;
2139 bool GEOM_Displayer::HasTexture() const
2141 return myTexture != "";
2144 std::string GEOM_Displayer::GetTexture() const
2149 //=================================================================
2151 * GEOM_Displayer::SetWidth
2152 * Set width of shape displaying. If it is equal -1 then default width is used.
2154 //=================================================================
2155 void GEOM_Displayer::SetWidth( const double width )
2160 double GEOM_Displayer::GetWidth() const
2165 bool GEOM_Displayer::HasWidth() const
2167 return myWidth != -1;
2170 void GEOM_Displayer::UnsetWidth()
2175 int GEOM_Displayer::GetIsosWidth() const
2180 void GEOM_Displayer::SetIsosWidth(const int width)
2182 myIsosWidth = width;
2185 bool GEOM_Displayer::HasIsosWidth() const
2187 return myIsosWidth != -1;
2190 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2192 int prevNbIsos = myNbIsos;
2197 int GEOM_Displayer::UnsetNbIsos()
2199 return SetNbIsos( -1 );
2202 int GEOM_Displayer::GetNbIsos() const
2207 bool GEOM_Displayer::HasNbIsos() const
2209 return myNbIsos >= 0;
2212 int GEOM_Displayer::SetIsosColor( const int color )
2214 int prevColor = myIsosColor;
2215 myIsosColor = color;
2219 int GEOM_Displayer::GetIsosColor() const
2224 bool GEOM_Displayer::HasIsosColor() const
2226 return myIsosColor != -1;
2229 int GEOM_Displayer::UnsetIsosColor()
2231 return SetIsosColor( -1 );
2234 //=================================================================
2236 * GEOM_Displayer::SetToActivate
2237 * This method is used for activisation/deactivisation of objects to be displayed
2239 //=================================================================
2240 void GEOM_Displayer::SetToActivate( const bool toActivate )
2242 myToActivate = toActivate;
2244 bool GEOM_Displayer::ToActivate() const
2246 return myToActivate;
2249 //=================================================================
2251 * GEOM_Displayer::clearTemporary
2252 * Removes from selection temporary objects
2254 //=================================================================
2255 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2257 SALOME_ListIO selected, toSelect;
2258 theSelMgr->selectedObjects( selected );
2260 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2261 Handle(SALOME_InteractiveObject) io = it.Value();
2262 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2263 toSelect.Append( it.Value() );
2266 theSelMgr->setSelectedObjects( toSelect, true );
2269 void GEOM_Displayer::SetName( const char* theName )
2274 void GEOM_Displayer::UnsetName()
2279 SalomeApp_Study* GEOM_Displayer::getStudy() const
2281 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2284 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2289 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2294 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2295 const int theFieldDimension,
2296 const QList<QVariant>& theFieldStepData,
2297 const TCollection_AsciiString& theFieldStepName,
2298 const double theFieldStepRangeMin,
2299 const double theFieldStepRangeMax )
2301 myFieldDataType = theFieldDataType;
2302 myFieldDimension = theFieldDimension;
2303 myFieldStepData = theFieldStepData;
2304 myFieldStepName = theFieldStepName;
2305 myFieldStepRangeMin = theFieldStepRangeMin;
2306 myFieldStepRangeMax = theFieldStepRangeMax;
2309 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2311 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2312 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2313 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2314 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2315 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2316 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2319 int GEOM_Displayer::SetDisplayMode( const int theMode )
2321 int aPrevMode = myDisplayMode;
2322 if ( theMode != -1 ) {
2323 myDisplayMode = theMode;
2324 myHasDisplayMode = true;
2332 int GEOM_Displayer::GetDisplayMode() const
2334 return myDisplayMode;
2337 int GEOM_Displayer::UnsetDisplayMode()
2339 int aPrevMode = myDisplayMode;
2340 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2341 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2342 myHasDisplayMode = false;
2346 bool GEOM_Displayer::HasDisplayMode() const
2348 return myHasDisplayMode;
2351 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2353 static QList<QColor> colors;
2355 if ( colors.isEmpty() ) {
2357 for (int s = 0; s < 2 ; s++)
2359 for (int v = 100; v >= 40; v = v - 20)
2361 for (int h = 0; h < 359 ; h = h + 60)
2363 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2369 static int currentColor = randomize( colors.size() );
2371 SALOMEDS::Color color;
2372 color.R = (double)colors[currentColor].red() / 255.0;
2373 color.G = (double)colors[currentColor].green() / 255.0;
2374 color.B = (double)colors[currentColor].blue() / 255.0;
2376 currentColor = (currentColor+1) % colors.count();
2381 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2384 int aTolerance = 64;
2385 int anIterations = 0;
2391 if( anIterations % aPeriod == 0 )
2394 if( aTolerance < 1 )
2397 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2399 aHue = (int)( 360.0 * rand() / RAND_MAX );
2400 //std::cout << "Hue = " << aHue << std::endl;
2402 //std::cout << "Auto colors : ";
2404 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2405 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2406 for( ; it != itEnd; ++it )
2408 SALOMEDS::Color anAutoColor = *it;
2409 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2412 aQColor.getHsv( &h, &s, &v );
2413 //std::cout << h << " ";
2414 if( abs( h - aHue ) < aTolerance )
2417 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2421 //std::cout << std::endl;
2427 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2429 aColor.setHsv( aHue, 255, 255 );
2431 SALOMEDS::Color aSColor;
2432 aSColor.R = (double)aColor.red() / 255.0;
2433 aSColor.G = (double)aColor.green() / 255.0;
2434 aSColor.B = (double)aColor.blue() / 255.0;
2439 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2440 const QString& entry,
2443 // get default properties for the explicitly specified default view type
2444 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2446 if ( study && view ) {
2447 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2448 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2449 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2451 if ( viewModel && viewId != -1 ) {
2452 // get properties from the study
2453 PropMap storedMap = study->getObjectProperties( viewId, entry );
2454 // overwrite default properties from stored ones (that are specified)
2455 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2456 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2457 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2458 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2460 // ... specific processing for color
2461 // ... current implementation is to use same stored color for all aspects
2462 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2463 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2464 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2465 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2466 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2467 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2468 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2471 if ( !entry.isEmpty() ) {
2472 // get CORBA reference to geom object
2473 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2475 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2476 if ( !CORBA::is_nil( object ) ) {
2477 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2478 if ( !CORBA::is_nil( geomObject ) ) { // to check
2479 // check that geom object has color properly set
2480 bool hasColor = false;
2481 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2482 // set color from geometry object (only once, if it is not yet set in GUI)
2483 // current implementation is to use same color for all aspects
2484 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2485 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2486 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2487 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2488 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2489 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2490 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2491 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2493 // check that object has point marker properly set
2494 GEOM::marker_type mType = geomObject->GetMarkerType();
2495 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2496 int mTextureId = geomObject->GetMarkerTexture();
2497 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2498 ( mType == GEOM::MT_USER && mTextureId > 0 );
2499 // set point marker from geometry object (only once, if it is not yet set in GUI)
2500 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2501 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2503 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2504 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2506 else if ( mType == GEOM::MT_USER ) {
2508 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2520 PropMap GEOM_Displayer::getDefaultPropertyMap()
2524 // get resource manager
2525 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2527 // fill in the properties map with default values
2529 // - visibility (false by default)
2530 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2532 // - nb isos (take default value from preferences)
2533 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2534 QString( "%1%2%3" ).
2535 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2536 arg( GEOM::subSectionSeparator() ).
2537 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2539 // - transparency (opacity = 1-transparency)
2540 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2541 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2543 // - display mode (take default value from preferences)
2544 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2545 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2547 // - show edges direction flag (false by default)
2548 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2550 // - show vertices flag (false by default)
2551 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2553 // - shading color (take default value from preferences)
2554 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2555 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2557 // - wireframe color (take default value from preferences)
2558 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2559 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2561 // - standalone edges color (take default value from preferences)
2562 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2563 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2565 // - free boundaries color (take default value from preferences)
2566 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2567 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2569 // - points color (take default value from preferences)
2570 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2571 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2573 // - isos color (take default value from preferences)
2574 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2575 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2577 // - outlines color (take default value from preferences)
2578 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2579 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2581 // - deflection coefficient (take default value from preferences)
2582 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2583 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2585 // - material (take default value from preferences)
2586 Material_Model material;
2587 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2588 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2590 // - edge width (take default value from preferences)
2591 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2592 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2594 // - isos width (take default value from preferences)
2595 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2596 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2598 // - point marker (take default value from preferences)
2599 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2600 QString( "%1%2%3" ).
2601 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2602 arg( GEOM::subSectionSeparator() ).
2603 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2605 // - top-level flag (false by default)
2606 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2611 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2612 SALOMEDS::Color aSColor;
2615 SUIT_Session* session = SUIT_Session::session();
2616 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2618 if ( app && !theGeomObject->_is_nil()) {
2619 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2622 _PTR(Study) aStudy = study->studyDS();
2623 aSColor = theGeomObject->GetColor();
2624 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2626 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2627 bool general_autocolor = true;
2628 #else // auto-color for groups only
2629 bool general_autocolor = false;
2630 #endif // GENERAL_AUTOCOLOR
2631 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2632 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2633 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2634 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2635 aSColor = getPredefinedUniqueColor();
2637 #else // old algorithm for auto-colors
2638 QList<SALOMEDS::Color> aReservedColors;
2639 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2640 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2641 if ( aMainSObject ) {
2642 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2643 for ( ; it->More(); it->Next() ) {
2644 _PTR(SObject) aChildSObject( it->Value() );
2645 GEOM::GEOM_Object_var aChildObject =
2646 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2647 if ( CORBA::is_nil( aChildObject ) )
2650 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2651 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2652 aReservedColors.append( aReservedColor );
2655 aSColor = getUniqueColor( aReservedColors );
2657 #endif // SIMPLE_AUTOCOLOR
2667 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2668 const bool eraseOnlyChildren) {
2669 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2673 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2677 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2682 // Erase from all views
2683 QList<SALOME_View*> views;
2685 ViewManagerList vmans = app->viewManagers();
2686 SUIT_ViewManager* vman;
2687 foreach ( vman, vmans ) {
2688 SUIT_ViewModel* vmod = vman->getViewModel();
2689 view = dynamic_cast<SALOME_View*> ( vmod );
2691 views.append( view );
2694 if( views.count() == 0 )
2697 //Erase childrens w/o update views
2698 DataObjectList listObj = parent->children( true );
2699 SUIT_DataObject* obj;
2700 foreach( obj, listObj ) {
2701 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2703 foreach ( view, views ) {
2704 Handle(SALOME_InteractiveObject) anIO =
2705 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2706 Erase(anIO, false, false, view);
2710 //Erase parent with view update or repaint views
2711 foreach ( view, views ) {
2712 if(!eraseOnlyChildren)
2713 Erase(theIO, false, true, view);
2719 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2721 if( theGeomFieldStep->_is_nil() )
2724 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2725 if( aGeomField->_is_nil() )
2728 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2729 if( aGeomFieldShape->_is_nil() )
2732 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2733 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2734 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2736 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2738 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2740 int aFieldDimension = aGeomField->GetDimension();
2742 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2743 int aFieldNbComponents = aFieldComponents->length();
2745 QList<QVariant> aFieldStepData;
2746 if( aFieldDataType == GEOM::FDT_Bool )
2748 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2749 if ( !aGeomBoolFieldStep->_is_nil() )
2751 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2752 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2753 aFieldStepData << (bool)aValues[i];
2756 else if( aFieldDataType == GEOM::FDT_Int )
2758 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2759 if ( !aGeomIntFieldStep->_is_nil() )
2761 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2762 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2763 aFieldStepData << (qlonglong)aValues[i];
2766 else if( aFieldDataType == GEOM::FDT_Double )
2768 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2769 if ( !aGeomDoubleFieldStep->_is_nil() )
2771 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2772 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2773 aFieldStepData << (double)aValues[i];
2776 else if( aFieldDataType == GEOM::FDT_String )
2778 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2779 if ( !aGeomStringFieldStep->_is_nil() )
2781 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2782 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2783 aFieldStepData << QString( aValues[i] );
2787 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2788 aFieldStepData = groupFieldData( aFieldStepData,
2790 aFieldDataType == GEOM::FDT_String,
2792 aFieldStepRangeMax );
2794 setFieldStepInfo( aFieldDataType,
2799 aFieldStepRangeMax );
2802 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2803 const int theFieldNbComponents,
2804 const bool theIsString,
2805 double& theFieldStepRangeMin,
2806 double& theFieldStepRangeMax )
2808 QList<QVariant> aResultList;
2809 theFieldStepRangeMin = 0;
2810 theFieldStepRangeMax = 0;
2812 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2815 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2817 QList<QVariant> aGroupedList;
2819 bool anIsBoolean = false;
2820 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2823 QStringList aStringList;
2825 int aBaseIndex = aSubShape * theFieldNbComponents;
2826 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2828 int anIndex = aComponent + aBaseIndex;
2830 const QVariant& aVariant = theFieldStepData[ anIndex ];
2833 if( aVariant.type() == QVariant::String )
2834 aStringList << aVariant.toString();
2839 if( aVariant.type() == QVariant::Bool )
2841 aValue = aVariant.toBool() ? 1.0 : 0.0;
2847 if( aVariant.type() == QVariant::LongLong )
2848 aValue = double( aVariant.toLongLong() );
2849 else if( aVariant.type() == QVariant::Double )
2850 aValue = aVariant.toDouble();
2851 aNorm += aValue * aValue;
2857 aGroupedList << aStringList.join( "\n" );
2861 aNorm /= theFieldNbComponents;
2863 aNorm = pow( aNorm, 0.5 );
2865 if( aGroupedList.isEmpty() )
2866 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2869 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2870 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2873 aGroupedList << aNorm;
2879 theFieldStepRangeMin = 0.0;
2880 theFieldStepRangeMax = 1.0;
2883 SUIT_Session* session = SUIT_Session::session();
2884 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2885 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2887 QListIterator<QVariant> anIter( aGroupedList );
2888 while( anIter.hasNext() )
2890 const QVariant& aVariant = anIter.next();
2892 aResultList << aVariant;
2896 Quantity_Color aColor;
2897 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2898 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2899 aResultList << aQColor;
2905 // Note: the method is copied from Aspect_ColorScale class
2906 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2907 const Standard_Integer aMin,
2908 const Standard_Integer aMax )
2910 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2912 Standard_Integer aHue = maxLimit;
2914 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2916 aHue = Min( Max( minLimit, aHue ), maxLimit );
2921 // Note: the method is copied from Aspect_ColorScale class
2922 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2923 const Standard_Real aMin,
2924 const Standard_Real aMax,
2925 const Standard_Integer ColorsCount,
2926 Quantity_Color& aColor )
2928 if( aValue<aMin || aValue>aMax || aMax<aMin )
2929 return Standard_False;
2933 Standard_Real IntervNumber = 0;
2936 else if( aValue>aMax )
2937 IntervNumber = ColorsCount-1;
2938 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2939 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2941 Standard_Integer Interv = Standard_Integer( IntervNumber );
2943 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2945 return Standard_True;
2949 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2951 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2955 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2959 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2960 if( aViewer.IsNull() )
2963 aViewer->InitActiveViews();
2964 if( !aViewer->MoreActiveViews() )
2967 Handle(V3d_View) aView = aViewer->ActiveView();
2968 if( aView.IsNull() )
2971 Standard_Boolean anIsDisplayColorScale = Standard_False;
2972 TCollection_AsciiString aColorScaleTitle;
2973 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2974 Standard_Boolean anIsBoolean = Standard_False;
2976 SALOME_ListIO aSelectedObjects;
2977 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2978 if( aSelectedObjects.Extent() == 1 )
2980 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2981 if( !anIO.IsNull() )
2983 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2986 AIS_ListOfInteractive aList;
2987 aPrs->GetObjects( aList );
2988 AIS_ListIteratorOfListOfInteractive anIter( aList );
2989 for( ; anIter.More(); anIter.Next() )
2991 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2992 if( !aShape.IsNull() )
2994 GEOM::field_data_type aFieldDataType;
2995 int aFieldDimension;
2996 QList<QVariant> aFieldStepData;
2997 TCollection_AsciiString aFieldStepName;
2998 double aFieldStepRangeMin, aFieldStepRangeMax;
2999 aShape->getFieldStepInfo( aFieldDataType,
3004 aFieldStepRangeMax );
3005 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3007 anIsDisplayColorScale = Standard_True;
3008 aColorScaleTitle = aFieldStepName;
3009 aColorScaleMin = aFieldStepRangeMin;
3010 aColorScaleMax = aFieldStepRangeMax;
3011 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3019 if( anIsDisplayColorScale )
3021 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
3022 if( !aColorScale.IsNull() )
3024 SUIT_Session* session = SUIT_Session::session();
3025 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3027 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3028 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3029 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3030 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3031 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3032 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3034 aColorScale->SetXPosition( anXPos );
3035 aColorScale->SetYPosition( anYPos );
3036 aColorScale->SetWidth( aWidth );
3037 aColorScale->SetHeight( aHeight );
3039 aColorScale->SetTextHeight( aTextHeight );
3040 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3042 aColorScale->SetTitle( aColorScaleTitle );
3043 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3045 if( !aView->ColorScaleIsDisplayed() )
3046 aView->ColorScaleDisplay();
3050 if( aView->ColorScaleIsDisplayed() )
3051 aView->ColorScaleErase();
3054 if( theIsRedisplayFieldSteps )
3056 _PTR(Study) aStudyDS = aStudy->studyDS();
3057 QList<SUIT_ViewManager*> vmList;
3058 myApp->viewManagers( vmList );
3059 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3061 if( SUIT_ViewManager* aViewManager = *vmIt )
3063 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3064 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3066 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3069 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3070 if( !CORBA::is_nil( anObject ) )
3072 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3073 if( !aFieldStep->_is_nil() )
3075 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3076 Handle(SALOME_InteractiveObject) aStepIO =
3077 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3078 Redisplay( aStepIO, false, false );