1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESHGUI_SelectionProxy.h"
26 #include "SMESHGUI_Utils.h"
27 #include "SMESHGUI_VTKUtils.h"
28 #include "SMDS_Mesh.hxx"
29 #include "SMESH_Actor.h"
30 #include "SMESH_ControlsDef.hxx"
32 #include <SALOMEconfig.h>
33 #include CORBA_SERVER_HEADER(SMESH_Filter)
34 #include CORBA_SERVER_HEADER(SMESH_Group)
36 #include <SALOMEDSClient_Study.hxx>
37 #include <SUIT_ResourceMgr.h>
39 ////////////////////////////////////////////////////////////////////////////////
40 /// \class SMESH::SelectionProxy
41 /// \brief Provide operations over the selected object.
43 /// The selection proxy class is aimed to use in dialogs to access mesh object
44 /// data either from actor or directly from CORBA reference, depending on what
45 /// of them is accessible.
46 /// This is useful in situations when some information is needed, but an actor
47 /// was not created yet.
49 /// Selection proxy can be constructed in two ways:
50 /// - From interactive object: this performs full proxy initialization including
51 /// pick-up of an actor from the current viewer if it exists.
52 /// - From mesh source object (CORBA reference); for performance reasons in this
53 /// case full initialization is not immediately done and performed only when
56 /// \todo To show min edge length with volumes, it is necessary to add new
58 /// \todo To avoid showing controls unsuitable for particular elements, the
59 /// corresponding check has to be done in each contro's IsSatisfy method.
60 ////////////////////////////////////////////////////////////////////////////////
63 \brief Default constructor. Creates null proxy.
65 SMESH::SelectionProxy::SelectionProxy(): myActor(0), myDirty(false)
71 \param io Interactive object.
73 SMESH::SelectionProxy::SelectionProxy( const Handle(SALOME_InteractiveObject)& io ): myActor(0), myDirty(true)
75 myObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( io );
81 \param object Mesh source.
83 SMESH::SelectionProxy::SelectionProxy( SMESH::SMESH_IDSource_ptr object ): myActor(0), myDirty(true)
85 if ( !CORBA::is_nil( object ) )
86 myObject = SMESH::SMESH_IDSource::_duplicate( object );
90 \brief Copy constructor.
91 \param other Proxy being copied.
93 SMESH::SelectionProxy::SelectionProxy( const SelectionProxy& other )
96 myObject = other.myObject;
97 myActor = other.myActor;
98 myDirty = other.myDirty;
102 \brief Perform internal initialization.
105 void SMESH::SelectionProxy::init()
108 myIO = new SALOME_InteractiveObject(); // create dummy IO to avoid crashes when accesing it
110 if ( !CORBA::is_nil( myObject ) )
112 if ( !myIO->hasEntry() )
114 _PTR(SObject) sobj = SMESH::ObjectToSObject( myObject.in() );
116 myIO = new SALOME_InteractiveObject( sobj->GetID().c_str(), "SMESH", sobj->GetName().c_str() );
118 if ( !myActor && myIO->hasEntry() )
119 myActor = SMESH::FindActorByEntry( myIO->getEntry() );
125 \brief Assignment operator.
126 \param other Proxy being copied.
128 SMESH::SelectionProxy& SMESH::SelectionProxy::operator= ( const SMESH::SelectionProxy& other )
131 myObject = other.myObject;
132 myActor = other.myActor;
133 myDirty = other.myDirty;
138 \brief Equality comparison operator.
139 \param other Proxy to compare with.
140 \return \c true if two proxies are equal; \c false otherwise.
142 bool SMESH::SelectionProxy::operator== ( const SMESH::SelectionProxy& other )
144 return !CORBA::is_nil( myObject ) && !CORBA::is_nil( other.myObject ) &&
145 myObject->_is_equivalent( other.myObject );
149 \brief Re-initialize proxy.
151 void SMESH::SelectionProxy::refresh()
157 \brief Check if proxy is null.
158 \return \c true if proxy is null; \c false otherwise.
160 bool SMESH::SelectionProxy::isNull() const
162 return CORBA::is_nil( myObject );
166 \brief Boolean conversion operator.
167 \return \c true if proxy is not null; \c false otherwise.
169 SMESH::SelectionProxy::operator bool() const
175 \brief Get interactive object.
176 \return Interactive object referenced by proxy.
178 const Handle(SALOME_InteractiveObject)& SMESH::SelectionProxy::io() const
181 const_cast<SMESH::SelectionProxy*>(this)->init();
186 \brief Get mesh object.
187 \return Mesh object (mesh, sub-mesh, group, etc.) referenced by proxy.
189 SMESH::SMESH_IDSource_ptr SMESH::SelectionProxy::object() const
191 return SMESH::SMESH_IDSource::_duplicate( myObject );
196 \return Actor referenced by proxy.
198 SMESH_Actor* SMESH::SelectionProxy::actor() const
201 const_cast<SMESH::SelectionProxy*>(this)->init();
206 \brief Get object's validity.
208 Mesh object is valid if it is not null and information stored in it is valid.
210 \return \c true if object is valid; \c false otherwise.
212 bool SMESH::SelectionProxy::isValid() const
214 return !isNull() && myObject->IsMeshInfoCorrect();
218 \brief Load mesh object from study file.
220 void SMESH::SelectionProxy::load()
224 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
225 if ( !CORBA::is_nil( mesh ) )
232 \return Mesh object's name.
234 QString SMESH::SelectionProxy::name() const
238 value = io()->getName();
244 \return Mesh object's type.
246 SMESH::SelectionProxy::Type SMESH::SelectionProxy::type() const
248 Type value = Unknown;
251 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
252 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( myObject );
253 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
254 SMESH::SMESH_Group_var sGroup = SMESH::SMESH_Group::_narrow( myObject );
255 SMESH::SMESH_GroupOnGeom_var gGroup = SMESH::SMESH_GroupOnGeom::_narrow( myObject );
256 SMESH::SMESH_GroupOnFilter_var fGroup = SMESH::SMESH_GroupOnFilter::_narrow( myObject );
258 if ( !CORBA::is_nil( mesh ) )
260 else if ( !CORBA::is_nil( submesh ) )
262 else if ( !CORBA::is_nil( sGroup ) )
264 else if ( !CORBA::is_nil( gGroup ) )
266 else if ( !CORBA::is_nil( fGroup ) )
268 else if ( !CORBA::is_nil( group ) )
275 \brief Get mesh information.
276 \return Statistics on stored mesh object.
278 SMESH::MeshInfo SMESH::SelectionProxy::meshInfo() const
280 SMESH::MeshInfo info;
283 SMESH::long_array_var data = myObject->GetMeshInfo();
284 for ( uint type = SMESH::Entity_Node; type < SMESH::Entity_Last; type++ )
286 if ( type < data->length() )
287 info.addInfo( type, data[ type ] );
294 \brief Get parent mesh.
295 \return Proxy object that stores parent mesh object.
296 \note For proxy that stores a mesh, returns its copy.
298 SMESH::SelectionProxy SMESH::SelectionProxy::mesh() const
300 SMESH::SelectionProxy parent;
302 parent = SMESH::SelectionProxy( (SMESH::SMESH_Mesh_var) myObject->GetMesh() ); // cast to var to avoid leaks
307 \brief Check if parent mesh has shape to mesh.
308 \return \c true if Parent mesh is built on a shape; \c false otherwise.
309 \note For group or submesh, this method checks that parent mesh has a shape.
311 bool SMESH::SelectionProxy::hasShapeToMesh() const
316 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
317 if ( !CORBA::is_nil( mesh ) )
318 result = mesh->HasShapeToMesh();
324 \brief Get referenced GEOM object.
325 \return GEOM object referenced by selection proxy.
327 The result contains valid pointer only if proxy refers to mesh, sub-mesh
328 or group created on a geometry.
330 GEOM::GEOM_Object_ptr SMESH::SelectionProxy::shape() const
332 GEOM::GEOM_Object_var shape;
335 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
336 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( myObject );
337 SMESH::SMESH_GroupOnGeom_var group = SMESH::SMESH_GroupOnGeom::_narrow( myObject );
338 if ( !CORBA::is_nil( mesh ) )
339 shape = mesh->GetShapeToMesh();
340 else if ( !CORBA::is_nil( submesh ) )
341 shape = submesh->GetSubShape();
342 else if ( !CORBA::is_nil( group ) )
343 shape = group->GetShape();
345 return shape._retn();
349 \brief Get name of referenced GEOM object.
350 \return Name of GEOM object referenced by selection proxy.
352 The result contains non-empty name only if proxy refers to mesh, sub-mesh
353 or group created on a geometry, and if that geometry has valid name.
355 QString SMESH::SelectionProxy::shapeName() const
360 GEOM::GEOM_Object_var gobj = shape();
361 _PTR(SObject) sobj = SMESH::ObjectToSObject( gobj );
363 name = QString::fromStdString( sobj->GetName() );
369 \brief Get type of referenced GEOM object.
370 \return Type of GEOM object referenced by selection proxy.
372 The result contains valid type only if proxy refers to mesh, sub-mesh
373 or group created on a geometry.
375 int SMESH::SelectionProxy::shapeType() const
380 GEOM::GEOM_Object_var gobj = shape();
381 if ( !CORBA::is_nil( gobj ) )
382 type = gobj->GetShapeType();
388 \brief Check if mesh has been loaded from study file.
389 \return \c true if mesh was loaded; \c false otherwise.
391 bool SMESH::SelectionProxy::isMeshLoaded() const
393 bool result = true; // set default to true to avoid side effects
396 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
397 if ( !CORBA::is_nil( mesh ) )
398 result = mesh->IsLoaded();
404 \brief Check if node with given ID is present in the mesh.
405 \param id Mesh node ID.
406 \return \c true if mesh contains node; \c false otherwise.
408 bool SMESH::SelectionProxy::hasNode( int id )
415 const SMDS_MeshNode* node = actor()->GetObject()->GetMesh()->FindNode( id );
420 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
421 if ( !CORBA::is_nil( mesh ) )
423 SMESH::double_array_var coords = mesh->GetNodeXYZ( id );
424 result = coords->length() >= 3;
432 \brief Get node coordinates.
433 \param id Mesh node ID.
434 \param xyz Returned node coordinates.
435 \return \c true if result is valid; \c false otherwise.
437 bool SMESH::SelectionProxy::nodeCoordinates( int id, SMESH::XYZ& xyz )
446 const SMDS_MeshNode* node = actor()->GetObject()->GetMesh()->FindNode( id );
449 xyz = SMESH::XYZ( node->X(), node->Y(), node->Z() );
455 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
456 if ( !CORBA::is_nil( mesh ) )
458 SMESH::double_array_var coords = mesh->GetNodeXYZ( id );
459 if ( coords->length() >= 3 )
461 xyz = SMESH::XYZ( coords[0], coords[1], coords[2] );
471 \brief Get node connectivity.
472 \param id Mesh node ID.
473 \param connectivity Returned node connectivity.
474 \return \c true if result is valid; \c false otherwise.
476 bool SMESH::SelectionProxy::nodeConnectivity( int id, SMESH::Connectivity& connectivity )
479 connectivity.clear();
484 const SMDS_MeshNode* node = actor()->GetObject()->GetMesh()->FindNode( id );
487 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
488 while ( it && it->more() )
490 const SMDS_MeshElement* ne = it->next();
491 connectivity[ ne->GetType() ] << ne->GetID();
498 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
499 if ( !CORBA::is_nil( mesh ) )
501 SMESH::long_array_var elements = mesh->GetNodeInverseElements( id );
502 for ( int i = 0, n = elements->length(); i < n; i++ )
504 SMESH::ElementType type = mesh->GetElementType( elements[i], true );
505 connectivity[ type ] << elements[i];
515 \brief Get node position on a shape.
516 \param id Mesh node ID.
517 \param position Returned node position.
518 \return \c true if result is valid; \c false otherwise.
520 bool SMESH::SelectionProxy::nodePosition( int id, Position& position )
523 position = Position();
526 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
527 if ( !CORBA::is_nil( mesh ) )
529 SMESH::NodePosition_var pos = mesh->GetNodePosition( id );
530 position.setShapeId( pos->shapeID );
531 if ( pos->shapeID > 0 )
533 position.setShapeType( pos->shapeType );
534 if ( pos->shapeType == GEOM::EDGE && pos->params.length() > 0 )
536 position.setU( pos->params[0] );
538 if ( pos->shapeType == GEOM::FACE && pos->params.length() > 1 )
540 position.setU( pos->params[0] );
541 position.setV( pos->params[1] );
551 \brief Get groups given node belongs to.
552 \param id Mesh node ID.
553 \return List of groups containing given node.
555 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::nodeGroups( int id ) const
557 QList<SMESH::SelectionProxy> result;
560 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
561 if ( !CORBA::is_nil( mesh ) )
563 SMESH::ListOfGroups_var groups = mesh->GetGroups();
564 for ( uint i = 0 ; i < groups->length(); i++ )
566 if ( groups[i]->GetType() == SMESH::NODE && groups[i]->Contains( id ) )
568 result << SMESH::SelectionProxy( groups[i].in() );
577 \brief Check if element with given ID is present in the mesh.
578 \param id Mesh element ID.
579 \return \c true if mesh contains element; \c false otherwise.
581 bool SMESH::SelectionProxy::hasElement( int id )
588 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
589 result = element != 0;
593 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
594 if ( !CORBA::is_nil( mesh ) )
596 SMESH::long_array_var nodes = mesh->GetElemNodes( id );
597 result = nodes->length() > 0;
605 \brief Get type of given mesh element.
606 \param id Mesh element ID.
607 \return Element type.
609 SMESH::ElementType SMESH::SelectionProxy::elementType( int id ) const
611 SMESH::ElementType value = SMESH::ALL;
616 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
619 value = (SMESH::ElementType)element->GetType();
624 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
625 if ( !CORBA::is_nil( mesh ) )
627 value = mesh->GetElementType( id, true );
635 \brief Get entity type of given mesh element.
636 \param id Mesh element ID.
639 int SMESH::SelectionProxy::elementEntityType( int id ) const
641 SMESH::EntityType value = SMESH::Entity_Last;
646 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
649 value = (SMESH::EntityType)element->GetEntityType();
654 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
655 if ( !CORBA::is_nil( mesh ) )
657 value = mesh->GetElementGeomType( id );
665 \brief Get element connectivity.
666 \param id Mesh element ID.
667 \param connectivity Returned element connectivity.
668 \return \c true if result is valid; \c false otherwise.
670 bool SMESH::SelectionProxy::elementConnectivity( int id, Connectivity& connectivity )
673 connectivity.clear();
678 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
682 SMDS_ElemIteratorPtr it = element->nodesIterator();
683 while ( it && it->more() )
684 nodes << static_cast<const SMDS_MeshNode*>( it->next() )->GetID();
685 connectivity[ SMDSAbs_Node ] = nodes.toList();
691 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
692 if ( !CORBA::is_nil( mesh ) )
694 SMESH::long_array_var nodes = mesh->GetElemNodes( id );
695 for ( int i = 0, n = nodes->length(); i < n; i++ )
697 connectivity[ SMDSAbs_Node ] << nodes[i];
707 \brief Get element position on a shape.
708 \param id Mesh element ID.
709 \param position Returned element position.
710 \return \c true if result is valid; \c false otherwise.
712 bool SMESH::SelectionProxy::elementPosition( int id, Position& position )
715 position = Position();
718 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
719 if ( !CORBA::is_nil( mesh ) )
721 SMESH::ElementPosition_var pos = mesh->GetElementPosition( id );
722 position.setShapeId( pos->shapeID );
723 if ( pos->shapeID > 0 )
725 position.setShapeType( pos->shapeType );
734 \brief Get gravity center of given element.
735 \param id Mesh element ID.
736 \param xyz Returned gravity center.
737 \return \c true if result is valid; \c false otherwise.
739 bool SMESH::SelectionProxy::elementGravityCenter( int id, SMESH::XYZ& xyz )
747 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
750 SMDS_ElemIteratorPtr it = element->nodesIterator();
753 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( it->next() );
754 xyz.add( node->X(), node->Y(), node->Z() );
756 xyz.divide( element->NbNodes() );
762 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
763 if ( !CORBA::is_nil( mesh ) )
765 SMESH::long_array_var nodes = mesh->GetElemNodes( id );
766 for ( int i = 0, n = nodes->length(); i < n; i++ )
768 SMESH::double_array_var coords = mesh->GetNodeXYZ( nodes[i] );
769 if ( coords->length() >= 3 )
771 xyz.add( coords[0], coords[1], coords[2] );
774 xyz.divide( nodes->length() );
783 \brief Get normal vector to given element (face).
784 \param id Mesh element ID.
785 \param xyz Returned normal vector.
786 \return \c true if result is valid; \c false otherwise.
788 bool SMESH::SelectionProxy::elementNormal( int id, SMESH::XYZ& xyz )
796 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
797 if ( element && element->GetType() == SMDSAbs_Face )
799 xyz = SMESH::getNormale( SMDS_Mesh::DownCast<SMDS_MeshFace>( element ) );
805 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
806 if ( !CORBA::is_nil( mesh ) )
808 SMESH::double_array_var normal = mesh->GetFaceNormal( id, true );
809 if ( normal->length() >= 3 )
811 xyz = SMESH::XYZ( normal[0], normal[1], normal[2] );
821 \brief Get quality control's value for given element.
822 \param id Mesh element ID.
823 \param control Quality control type.
824 \param precision Precision for control's value.
825 \param value Returned quality control's value.
826 \return \c true if result is valid; \c false otherwise.
828 bool SMESH::SelectionProxy::elementControl( int id, int control, double precision, double& value ) const
836 SMESH::Controls::NumericalFunctorPtr functor;
839 case SMESH::FT_AspectRatio:
840 functor.reset( new SMESH::Controls::AspectRatio() );
842 case SMESH::FT_AspectRatio3D:
843 functor.reset( new SMESH::Controls::AspectRatio3D() );
845 case SMESH::FT_Warping:
846 functor.reset( new SMESH::Controls::Warping() );
848 case SMESH::FT_MinimumAngle:
849 functor.reset( new SMESH::Controls::MinimumAngle() );
851 case SMESH::FT_Taper:
852 functor.reset( new SMESH::Controls::Taper() );
855 functor.reset( new SMESH::Controls::Skew() );
858 functor.reset( new SMESH::Controls::Area() );
860 case SMESH::FT_Volume3D:
861 functor.reset( new SMESH::Controls::Volume() );
863 case SMESH::FT_MaxElementLength2D:
864 functor.reset( new SMESH::Controls::MaxElementLength2D() );
866 case SMESH::FT_MaxElementLength3D:
867 functor.reset( new SMESH::Controls::MaxElementLength3D() );
869 case SMESH::FT_Length:
870 functor.reset( new SMESH::Controls::Length() );
872 case SMESH::FT_Length2D:
873 functor.reset( new SMESH::Controls::Length2D() );
875 case SMESH::FT_BallDiameter:
876 functor.reset( new SMESH::Controls::BallDiameter() );
881 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
882 if ( element && functor && element->GetType() == functor->GetType() )
884 functor->SetMesh( actor()->GetObject()->GetMesh() );
885 functor->SetPrecision( precision );
886 value = functor->GetValue( id );
899 \brief Get groups given element belongs to.
900 \param id Mesh element ID.
901 \return List of groups containing element.
903 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::elementGroups( int id ) const
905 QList<SMESH::SelectionProxy> result;
908 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
909 if ( !CORBA::is_nil( mesh ) )
911 SMESH::ListOfGroups_var groups = mesh->GetGroups();
912 for ( uint i = 0 ; i < groups->length(); i++ )
914 if ( groups[i]->GetType() != SMESH::NODE && groups[i]->Contains( id ) )
916 result << SMESH::SelectionProxy( groups[i].in() );
925 \brief Get MED file information.
926 \return MED file information.
928 The result contains valid data only if proxy refers to mesh object
929 which has been imported from the MED file.
931 SMESH::MedInfo SMESH::SelectionProxy::medFileInfo() const
936 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
937 if ( !CORBA::is_nil( mesh ) )
939 SMESH::MedFileInfo_var inf = mesh->GetMEDFileInfo();
940 info.setFileName( inf->fileName.in() );
941 info.setSize( inf->fileSize );
942 info.setVersion( inf->major, inf->minor, inf->release );
949 \brief Get child sub-meshes.
950 \return List of sub-meshes for mesh object; empty list for other types.
952 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::submeshes() const
954 QList<SMESH::SelectionProxy> lst;
957 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
958 if ( !CORBA::is_nil( mesh ) )
960 SMESH::submesh_array_var array = mesh->GetSubMeshes();
961 for ( uint i = 0 ; i < array->length(); i++ )
962 lst << SMESH::SelectionProxy( array[i].in() );
969 \brief Get child groups.
970 \return List of groups for mesh object; empty list for other types.
972 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::groups() const
974 QList<SMESH::SelectionProxy> lst;
977 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
978 if ( !CORBA::is_nil( mesh ) )
980 SMESH::ListOfGroups_var array = mesh->GetGroups();
981 for ( uint i = 0 ; i < array->length(); i++ )
982 lst << SMESH::SelectionProxy( array[i].in() );
989 \brief Get element type (for group). For other mesh objects result is undefined.
990 \return Group's element type.
992 SMESH::ElementType SMESH::SelectionProxy::groupElementType() const
994 SMESH::ElementType value = SMESH::ALL;
997 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
998 if ( !CORBA::is_nil( group ) )
999 value = group->GetType();
1005 \brief Get color (for group). For other mesh objects result is undefined.
1006 \return Group's color.
1008 QColor SMESH::SelectionProxy::color() const
1013 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1014 if ( !CORBA::is_nil( group ) )
1016 SALOMEDS::Color c = group->GetColor();
1017 result = QColor::fromRgbF( c.R, c.G, c.B );
1024 \brief Get size (for group). For other mesh objects result is undefined.
1025 \param autoCompute Compute size if it is unavailable. Defaults to \c false.
1026 \return Group's size.
1028 int SMESH::SelectionProxy::size( bool autoCompute ) const
1030 // note: size is not computed for group on filter for performance reasons, see IPAL52831
1034 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1035 if ( !CORBA::is_nil( group ) )
1037 if ( type() == GroupFilter )
1038 // for group on filter we check if value is already computed and cached
1039 autoCompute |= group->IsNodeInfoAvailable();
1041 // for other groups we force autoCompute to true
1044 result = group->Size();
1051 \brief Get number of underlying nodes (for group of elements). For other
1052 mesh objects result is undefined.
1053 \param autoCompute Compute size if it is unavailable. Defaults to \c false.
1054 \return Number of nodes contained in group.
1056 int SMESH::SelectionProxy::nbNodes( bool autoCompute ) const
1058 // note: nb of nodes is not computed automatically for performance reasons
1062 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1063 if ( !CORBA::is_nil( group ) && ( autoCompute || isMeshLoaded() ) )
1065 int groupSize = size( autoCompute );
1066 if ( groupSize >= 0 )
1068 int limit = SMESHGUI::resourceMgr()->integerValue( "SMESH", "info_groups_nodes_limit", 100000 );
1069 if ( group->IsNodeInfoAvailable() || limit <= 0 || groupSize <= limit )
1070 result = group->GetNumberOfNodes();
1078 \brief Get list of nodes / elements IDs for the mesh group.
1079 \return List of IDs for group object; empty list for other types.
1081 QSet<uint> SMESH::SelectionProxy::ids() const
1086 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1087 if ( !CORBA::is_nil( group ) )
1089 SMESH::long_array_var seq = group->GetListOfID();
1090 for ( int i = 0, n = seq->length(); i < n; i++ )
1091 result << (uint)seq[i];
1097 ////////////////////////////////////////////////////////////////////////////////
1098 /// \class SMESH::MeshInfo
1099 /// \brief Store statistics on mesh object.
1100 ////////////////////////////////////////////////////////////////////////////////
1105 SMESH::MeshInfo::MeshInfo()
1110 \brief Add information on given entity type.
1111 \param type Entity type.
1112 \param value Number of entities.
1114 void SMESH::MeshInfo::addInfo( int type, long value )
1116 myInfo[type] = value;
1120 \brief Get number of entities of given type.
1121 \param type Entity type.
1122 \return Number of entities.
1124 uint SMESH::MeshInfo::info( int type ) const
1126 return myInfo.value( type, 0U );
1130 \brief Access operator.
1131 \param type Entity type.
1132 \return Number of entities.
1134 uint SMESH::MeshInfo::operator[] ( int type )
1136 return (uint)info( type );
1140 \brief Get total number of entities for types in given range.
1141 \param fromType Lower entity type.
1142 \param toType Upper entity type.
1143 \return Number of entities.
1145 uint SMESH::MeshInfo::count( int fromType, int toType ) const
1148 for ( int type = fromType; type <= toType; type++ )
1149 value += info( type );
1153 ////////////////////////////////////////////////////////////////////////////////
1154 /// \class SMESH::MedInfo
1155 /// \brief Provide operations over the selected object
1156 ////////////////////////////////////////////////////////////////////////////////
1161 SMESH::MedInfo::MedInfo()
1166 \brief Get validity status.
1168 MED file information is valid if at least stored file name is not null.
1170 \return \c true if MED file info is valid; \c false otherwise.
1172 bool SMESH::MedInfo::isValid() const
1174 return !myFileName.isEmpty();
1178 \brief Get file name for mesh imported from MED file.
1179 \return MED file name.
1181 QString SMESH::MedInfo::fileName() const
1187 \brief Set file name for mesh imported from MED file.
1188 \param fileName MED file name.
1190 void SMESH::MedInfo::setFileName( const QString& fileName )
1192 myFileName = fileName;
1196 \brief Get file size for mesh imported from MED file.
1197 \return MED file size.
1199 uint SMESH::MedInfo::size() const
1205 \brief Set file size for mesh imported from MED file.
1206 \param size MED file size.
1208 void SMESH::MedInfo::setSize( uint size )
1214 \brief Get version of format for mesh imported from MED file.
1215 \return MED file format version.
1217 QString SMESH::MedInfo::version() const
1219 QString v = QString( "%1" ).arg( myMajor );
1220 if ( myMinor > 0 || myRelease > 0 ) v += QString( ".%1" ).arg( myMinor );
1221 else if ( myMajor > 0 ) v += ".0";
1222 if ( myRelease > 0 ) v += QString( ".%1" ).arg( myRelease );
1227 \brief Set version of format for mesh imported from MED file.
1228 \param major Major version number.
1229 \param minor Minor version number.
1230 \param release Release version number.
1232 void SMESH::MedInfo::setVersion( uint major, uint minor, uint release )
1236 myRelease = release;
1239 ////////////////////////////////////////////////////////////////////////////////
1240 /// \class SMESH::Position
1241 /// \brief Describes position of mesh node or element on a reference shape.
1242 ////////////////////////////////////////////////////////////////////////////////
1245 \brief Contructor. Creates invalid position.
1247 SMESH::Position::Position():
1248 myShapeId(-1), myShapeType(-1), myU(0), myV(0), myHasU(false), myHasV(false)
1253 \brief Check if position is valid.
1254 \return \c true if position is valid; \c false otherwise.
1256 bool SMESH::Position::isValid() const
1258 return myShapeId > 0 && myShapeType != -1;
1262 \brief Get reference shape ID.
1263 \return Shape / sub-shape ID.
1265 int SMESH::Position::shapeId() const
1271 \brief Set reference shape ID.
1272 \param id Shape / sub-shape ID.
1274 void SMESH::Position::setShapeId( int id )
1280 \brief Get reference shape type.
1283 int SMESH::Position::shapeType() const
1289 \brief Set reference shape type.
1290 \param type Shape type.
1292 void SMESH::Position::setShapeType( int type )
1298 \brief Check if there is U position on a shape.
1299 \return \c true if U position is valid; \c false otherwise.
1301 bool SMESH::Position::hasU() const
1307 \brief Get U position on a shape.
1310 double SMESH::Position::u() const
1316 \brief Set U position on a shape.
1319 void SMESH::Position::setU( double u )
1326 \brief Check if there is V position on a shape.
1327 \return \c true if V position is valid; \c false otherwise.
1329 bool SMESH::Position::hasV() const
1335 \brief Get V position on a shape.
1338 double SMESH::Position::v() const
1344 \brief Set V position on a shape.
1347 void SMESH::Position::setV( double v)
1353 ////////////////////////////////////////////////////////////////////////////////
1354 /// \class SMESH::XYZ
1355 /// \brief Simple structure to manage 3D coordinate.
1356 ////////////////////////////////////////////////////////////////////////////////
1359 \brief Default constructor.
1363 myX = myY = myZ = 0.0;
1367 \brief Base constructor.
1368 \param parameter x X coordinate.
1369 \param parameter y Y coordinate.
1370 \param parameter z Z coordinate.
1372 SMESH::XYZ::XYZ( double x, double y, double z )
1380 \brief Construction from geometrical point.
1381 \param parameter p Geometrical point.
1383 SMESH::XYZ::XYZ( const gp_XYZ& p )
1392 \param parameter x X coordinate.
1393 \param parameter y Y coordinate.
1394 \param parameter z Z coordinate.
1396 void SMESH::XYZ::add( double x, double y, double z )
1404 \brief Divide point to given coefficient.
1405 \param parameter a Divider coefficient.
1407 void SMESH::XYZ::divide( double a )
1418 \brief Get X coordinate.
1419 \return X coordinate.
1421 double SMESH::XYZ::x() const
1427 \brief Get Y coordinate.
1428 \return Y coordinate.
1430 double SMESH::XYZ::y() const
1436 \brief Get Z coordinate.
1437 \return Z coordinate.
1439 double SMESH::XYZ::z() const
1445 \brief Conversion to geometrical point.
1446 \return Geometrical point.
1448 SMESH::XYZ::operator gp_XYZ() const
1450 return gp_XYZ( myX, myY, myZ );