From: adv Date: Tue, 17 Dec 2013 07:00:38 +0000 (+0000) Subject: Groups of edges are added for geometry objects and calculation case (Feature #242). X-Git-Tag: BR_hydro_v_0_6~78 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4564a2513ac7a519741895560f26d7eef1d1400d;p=modules%2Fhydro.git Groups of edges are added for geometry objects and calculation case (Feature #242). --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 130f4988..a2a0ed56 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -13,6 +13,7 @@ set(PROJECT_HEADERS HYDROData_Digue.h HYDROData_Document.h HYDROData_DummyObject3D.h + HYDROData_EdgesGroup.h HYDROData_Entity.h HYDROData_IAltitudeObject.h HYDROData_Image.h @@ -50,6 +51,7 @@ set(PROJECT_SOURCES HYDROData_Digue.cxx HYDROData_Document.cxx HYDROData_DummyObject3D.cxx + HYDROData_EdgesGroup.cxx HYDROData_Entity.cxx HYDROData_IAltitudeObject.cxx HYDROData_Image.cxx diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 5a5b3ad2..64085eb5 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -4,6 +4,7 @@ #include "HYDROData_ArtificialObject.h" #include "HYDROData_Bathymetry.h" #include "HYDROData_Document.h" +#include "HYDROData_EdgesGroup.h" #include "HYDROData_Iterator.h" #include "HYDROData_NaturalObject.h" #include "HYDROData_PolylineXY.h" @@ -22,6 +23,7 @@ #include #include #include + #define CALCULATION_REGIONS_PREF GetName() + "_Reg" #define CALCULATION_ZONES_PREF GetName() + "_Zone" @@ -214,7 +216,7 @@ bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object AddReferenceObject( theObject, DataTag_GeometryObject ); - // Indicate model of the need to update zones splitting + // Indicate model of the need to update splitting SetToUpdate( true ); return true; @@ -232,7 +234,7 @@ void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Obj RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject ); - // Indicate model of the need to update zones splitting + // Indicate model of the need to update splitting SetToUpdate( true ); } @@ -240,7 +242,47 @@ void HYDROData_CalculationCase::RemoveGeometryObjects() { ClearReferenceObjects( DataTag_GeometryObject ); - // Indicate model of the need to update zones splitting + // Indicate model of the need to update splitting + SetToUpdate( true ); +} + +bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_EdgesGroup)& theGroup ) +{ + if ( theGroup.IsNull() ) + return false; + + if ( HasReference( theGroup, DataTag_GeometryGroup ) ) + return false; // Object is already in reference list + + AddReferenceObject( theGroup, DataTag_GeometryGroup ); + + // Indicate model of the need to update splitting + SetToUpdate( true ); + + return true; +} + +HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const +{ + return GetReferenceObjects( DataTag_GeometryGroup ); +} + +void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_EdgesGroup)& theGroup ) +{ + if ( theGroup.IsNull() ) + return; + + RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup ); + + // Indicate model of the need to update splitting + SetToUpdate( true ); +} + +void HYDROData_CalculationCase::RemoveGeometryGroups() +{ + ClearReferenceObjects( DataTag_GeometryGroup ); + + // Indicate model of the need to update splitting SetToUpdate( true ); } diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 7992f37a..d3f6bcda 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -13,6 +13,7 @@ class Handle(HYDROData_Object); class Handle(HYDROData_Region); class Handle(HYDROData_Zone); class Handle(HYDROData_PolylineXY); +class Handle(HYDROData_EdgesGroup); DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity) @@ -43,7 +44,9 @@ protected: DataTag_GeometryObject, ///< reference geometry objects DataTag_ChildRegion, ///< child regions DataTag_Region, ///< reference regions - DataTag_Polyline ///< reference boundary polyline + DataTag_Polyline, ///< reference boundary polyline + DataTag_GeometryGroup, ///< reference geometry groups + DataTag_SplittedGroups, ///< reference splitted groups }; public: @@ -101,6 +104,27 @@ public: HYDRODATA_EXPORT virtual void RemoveGeometryObjects(); + /** + * Add new one reference geometry group for calculation case. + */ + HYDRODATA_EXPORT virtual bool AddGeometryGroup( const Handle(HYDROData_EdgesGroup)& theGroup ); + + /** + * Returns all reference geometry groups of calculation case. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryGroups() const; + + /** + * Removes reference geometry group from calculation case. + */ + HYDRODATA_EXPORT virtual void RemoveGeometryGroup( const Handle(HYDROData_EdgesGroup)& theGroup ); + + /** + * Removes all reference geometry groups from calculation case. + */ + HYDRODATA_EXPORT virtual void RemoveGeometryGroups(); + + /** * Sets reference boundary polyline object for calculation case. */ diff --git a/src/HYDROData/HYDROData_EdgesGroup.cxx b/src/HYDROData/HYDROData_EdgesGroup.cxx new file mode 100644 index 00000000..2b30ae85 --- /dev/null +++ b/src/HYDROData/HYDROData_EdgesGroup.cxx @@ -0,0 +1,89 @@ + +#include "HYDROData_EdgesGroup.h" + +#include + +#include +#include + +#include +#include + +IMPLEMENT_STANDARD_HANDLE(HYDROData_EdgesGroup,HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_EdgesGroup,HYDROData_Entity) + +HYDROData_EdgesGroup::HYDROData_EdgesGroup() +: HYDROData_Entity() +{ +} + +HYDROData_EdgesGroup::~HYDROData_EdgesGroup() +{ +} + +bool HYDROData_EdgesGroup::CanBeUpdated() const +{ + return false; +} + +bool HYDROData_EdgesGroup::CanRemove() +{ + return false; +} + +void HYDROData_EdgesGroup::AddEdge( const TopoDS_Edge& theEdge ) +{ + if ( theEdge.IsNull() ) + return; + + TDF_Label aNewLab = myLab.FindChild( DataTag_Edge ).NewChild(); + + TNaming_Builder aBuilder( aNewLab ); + aBuilder.Generated( theEdge ); +} + +void HYDROData_EdgesGroup::SetEdges( const HYDROData_SequenceOfEdges& theEdges ) +{ + RemoveEdges(); + + for ( int i = 1, n = theEdges.Length(); i <= n; ++i ) + { + const TopoDS_Edge& anEdge = theEdges.Value( i ); + AddEdge( anEdge ); + } +} + +HYDROData_SequenceOfEdges HYDROData_EdgesGroup::GetEdges() const +{ + HYDROData_SequenceOfEdges aResSeq; + + TDF_Label aLabel = myLab.FindChild( DataTag_Edge, false ); + if ( aLabel.IsNull() ) + return aResSeq; + + TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() ); + for ( ; aChildIt.More(); aChildIt.Next() ) + { + Handle(TNaming_NamedShape) aNamedShape = + Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() ); + if ( aNamedShape.IsNull() ) + continue; + + TopoDS_Shape aStoredShape = aNamedShape->Get(); + if ( aStoredShape.IsNull() || aStoredShape.ShapeType() != TopAbs_EDGE ) + continue; + + TopoDS_Edge aStoredEdge = TopoDS::Edge( aStoredShape ); + aResSeq.Append( aStoredEdge ); + } + + return aResSeq; +} + +void HYDROData_EdgesGroup::RemoveEdges() +{ + TDF_Label aLabel = myLab.FindChild( DataTag_Edge, false ); + if ( !aLabel.IsNull() ) + aLabel.ForgetAllAttributes(); +} + diff --git a/src/HYDROData/HYDROData_EdgesGroup.h b/src/HYDROData/HYDROData_EdgesGroup.h new file mode 100644 index 00000000..4fadbdb6 --- /dev/null +++ b/src/HYDROData/HYDROData_EdgesGroup.h @@ -0,0 +1,87 @@ + +#ifndef HYDROData_EdgesGroup_HeaderFile +#define HYDROData_EdgesGroup_HeaderFile + +#include + +class TopoDS_Edge; + +DEFINE_STANDARD_HANDLE(HYDROData_EdgesGroup, HYDROData_Entity) + +typedef NCollection_Sequence HYDROData_SequenceOfEdges; + +/**\class HYDROData_EdgesGroup + * \brief The artificial objects are objects created or planned for creation by human. + * + */ +class HYDROData_EdgesGroup : public HYDROData_Entity +{ +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + DataTag_Edge, ///< reference edges + }; + +public: + DEFINE_STANDARD_RTTI(HYDROData_EdgesGroup); + + /** + * Returns the kind of this object. Must be redefined in all objects of known type. + */ + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_EDGES_GROUP; } + + /** + * Returns flag indicating that object is updateble or not. + */ + HYDRODATA_EXPORT virtual bool CanBeUpdated() const; + + /** + * Returns flag indicating that object can be removed or not. + */ + HYDRODATA_EXPORT virtual bool CanRemove(); + +public: + // Public methods to work with reference Edges + + /** + * Add new one edge for the group. + */ + HYDRODATA_EXPORT virtual void AddEdge( const TopoDS_Edge& theEdge ); + + /** + * Sets new sequence of edges for the group. + */ + HYDRODATA_EXPORT virtual void SetEdges( const HYDROData_SequenceOfEdges& theEdges ); + + /** + * Returns all edges of the group. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfEdges GetEdges() const; + + /** + * Removes all edges from the group. + */ + HYDRODATA_EXPORT virtual void RemoveEdges(); + + +protected: + + friend class HYDROData_Iterator; + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDRODATA_EXPORT HYDROData_EdgesGroup(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual HYDRODATA_EXPORT ~HYDROData_EdgesGroup(); +}; + +#endif diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index de2fa87d..00a91985 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -42,7 +42,8 @@ const ObjectKind KIND_VISUAL_STATE = 18; const ObjectKind KIND_ARTIFICIAL_OBJECT = 19; const ObjectKind KIND_NATURAL_OBJECT = 20; const ObjectKind KIND_DUMMY_3D = 21; -const ObjectKind KIND_LAST = KIND_DUMMY_3D; +const ObjectKind KIND_EDGES_GROUP = 22; +const ObjectKind KIND_LAST = KIND_EDGES_GROUP; DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared) diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index 4d61c150..f1dde62f 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -8,6 +8,7 @@ #include "HYDROData_Confluence.h" #include "HYDROData_DummyObject3D.h" #include "HYDROData_Digue.h" +#include "HYDROData_EdgesGroup.h" #include "HYDROData_Image.h" #include "HYDROData_ImmersibleZone.h" #include "HYDROData_Obstacle.h" @@ -105,65 +106,27 @@ Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel ) switch( aKind ) { - case KIND_IMAGE: - aResult = new HYDROData_Image(); - break; - case KIND_POLYLINE: - aResult = new HYDROData_Polyline3D(); - break; - case KIND_BATHYMETRY: - aResult = new HYDROData_Bathymetry(); - break; - case KIND_ALTITUDE: - aResult = new HYDROData_AltitudeObject(); - break; - case KIND_IMMERSIBLE_ZONE: - aResult = new HYDROData_ImmersibleZone(); - break; - case KIND_RIVER: - aResult = new HYDROData_River(); - break; - case KIND_STREAM: - aResult = new HYDROData_Stream(); - break; - case KIND_CONFLUENCE: - aResult = new HYDROData_Confluence(); - break; - case KIND_CHANNEL: - aResult = new HYDROData_Channel(); - break; - case KIND_OBSTACLE: - aResult = new HYDROData_Obstacle(); - break; - case KIND_DIGUE: - aResult = new HYDROData_Digue(); - break; - case KIND_PROFILE: - aResult = new HYDROData_Profile(); - break; - case KIND_PROFILEUZ: - aResult = new HYDROData_ProfileUZ(); - break; - case KIND_POLYLINEXY: - aResult = new HYDROData_PolylineXY(); - break; - case KIND_CALCULATION: - aResult = new HYDROData_CalculationCase(); - break; - case KIND_REGION: - aResult = new HYDROData_Region(); - break; - case KIND_ZONE: - aResult = new HYDROData_Zone(); - break; - case KIND_VISUAL_STATE: - aResult = new HYDROData_VisualState(); - break; - case KIND_DUMMY_3D: - aResult = new HYDROData_DummyObject3D(); - break; - default: - break; + case KIND_IMAGE: aResult = new HYDROData_Image(); break; + case KIND_POLYLINE: aResult = new HYDROData_Polyline3D(); break; + case KIND_BATHYMETRY: aResult = new HYDROData_Bathymetry(); break; + case KIND_ALTITUDE: aResult = new HYDROData_AltitudeObject(); break; + case KIND_IMMERSIBLE_ZONE: aResult = new HYDROData_ImmersibleZone(); break; + case KIND_RIVER: aResult = new HYDROData_River(); break; + case KIND_STREAM: aResult = new HYDROData_Stream(); break; + case KIND_CONFLUENCE: aResult = new HYDROData_Confluence(); break; + case KIND_CHANNEL: aResult = new HYDROData_Channel(); break; + case KIND_OBSTACLE: aResult = new HYDROData_Obstacle(); break; + case KIND_DIGUE: aResult = new HYDROData_Digue(); break; + case KIND_PROFILE: aResult = new HYDROData_Profile(); break; + case KIND_PROFILEUZ: aResult = new HYDROData_ProfileUZ(); break; + case KIND_POLYLINEXY: aResult = new HYDROData_PolylineXY(); break; + case KIND_CALCULATION: aResult = new HYDROData_CalculationCase(); break; + case KIND_REGION: aResult = new HYDROData_Region(); break; + case KIND_ZONE: aResult = new HYDROData_Zone(); break; + case KIND_VISUAL_STATE: aResult = new HYDROData_VisualState(); break; + case KIND_DUMMY_3D: aResult = new HYDROData_DummyObject3D(); break; + case KIND_EDGES_GROUP: aResult = new HYDROData_EdgesGroup(); break; + default: break; } if ( !aResult.IsNull() ) diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index ce02f9d9..14304d78 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -3,6 +3,7 @@ #include "HYDROData_Bathymetry.h" #include "HYDROData_DummyObject3D.h" +#include "HYDROData_EdgesGroup.h" #include "HYDROData_Iterator.h" #include @@ -24,6 +25,14 @@ HYDROData_Object::~HYDROData_Object() { } +void HYDROData_Object::Update() +{ + HYDROData_Entity::Update(); + removeTopShape(); + removeShape3D(); + removeGroupObjects(); +} + HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const { HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects(); @@ -87,11 +96,9 @@ void HYDROData_Object::checkAndSetObject3D() HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D ); } -void HYDROData_Object::Update() +HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const { - HYDROData_Entity::Update(); - removeTopShape(); - removeShape3D(); + return GetReferenceObjects( DataTag_EdgesGroup ); } bool HYDROData_Object::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ) @@ -130,46 +137,6 @@ void HYDROData_Object::RemoveBathymetry() SetToUpdate( true ); } -TopoDS_Shape HYDROData_Object::getTopShape() const -{ - TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false ); - if ( !aLabel.IsNull() ) - { - Handle(TNaming_NamedShape) aNamedShape; - if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) - return aNamedShape->Get(); - } - - return TopoDS_Shape(); -} - -void HYDROData_Object::removeTopShape() -{ - TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false ); - if ( !aLabel.IsNull() ) - aLabel.ForgetAllAttributes(); -} - -TopoDS_Shape HYDROData_Object::getShape3D() const -{ - TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false ); - if ( !aLabel.IsNull() ) - { - Handle(TNaming_NamedShape) aNamedShape; - if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) - return aNamedShape->Get(); - } - - return TopoDS_Shape(); -} - -void HYDROData_Object::removeShape3D() -{ - TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false ); - if ( !aLabel.IsNull() ) - aLabel.ForgetAllAttributes(); -} - void HYDROData_Object::SetFillingColor( const QColor& theColor ) { SetColor( theColor, DataTag_FillingColor ); @@ -210,3 +177,65 @@ QColor HYDROData_Object::getDefaultBorderColor() const return DefaultBorderColor(); } +Handle(HYDROData_EdgesGroup) HYDROData_Object::createGroupObject() +{ + TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild(); + + Handle(HYDROData_EdgesGroup) aNewGroup = + Handle(HYDROData_EdgesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_EDGES_GROUP ) ); + AddReferenceObject( aNewGroup, DataTag_EdgesGroup ); + + return aNewGroup; +} + +void HYDROData_Object::createGroupObjects() +{ +} + +void HYDROData_Object::removeGroupObjects() +{ + TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false ); + if ( !aLabel.IsNull() ) + aLabel.ForgetAllAttributes(); +} + +TopoDS_Shape HYDROData_Object::getTopShape() const +{ + TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false ); + if ( !aLabel.IsNull() ) + { + Handle(TNaming_NamedShape) aNamedShape; + if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) + return aNamedShape->Get(); + } + + return TopoDS_Shape(); +} + +void HYDROData_Object::removeTopShape() +{ + TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false ); + if ( !aLabel.IsNull() ) + aLabel.ForgetAllAttributes(); +} + +TopoDS_Shape HYDROData_Object::getShape3D() const +{ + TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false ); + if ( !aLabel.IsNull() ) + { + Handle(TNaming_NamedShape) aNamedShape; + if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) + return aNamedShape->Get(); + } + + return TopoDS_Shape(); +} + +void HYDROData_Object::removeShape3D() +{ + TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false ); + if ( !aLabel.IsNull() ) + aLabel.ForgetAllAttributes(); +} + diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index 949372ca..3bf31fe1 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -10,6 +10,7 @@ DEFINE_STANDARD_HANDLE(HYDROData_Object, HYDROData_Entity) class TopoDS_Shape; class Handle(HYDROData_Bathymetry); class Handle(HYDROData_DummyObject3D); +class Handle(HYDROData_EdgesGroup); /**\class HYDROData_Object * \brief The base class for all geometrical objects in the HYDRO module. @@ -29,7 +30,8 @@ protected: DataTag_Bathymetry, ///< reference bathymetry DataTag_FillingColor, ///< filling color of geometrical object DataTag_BorderColor, ///< border color of geometrical object - DataTag_Object3D ///< child 3D object + DataTag_Object3D, ///< child 3D object + DataTag_EdgesGroup, ///< child group objects }; public: @@ -76,10 +78,14 @@ public: /** * Returns reference object which represent the 3D shape of object. - * Base implementation returns NULL pointer. */ HYDRODATA_EXPORT virtual Handle(HYDROData_DummyObject3D) GetObject3D() const; + /** + * Returns sequence of object groups. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGroups() const; + /** * Set reference bathymetry object for geometry object. @@ -160,6 +166,24 @@ protected: */ HYDRODATA_EXPORT virtual void checkAndSetObject3D(); + + /** + * Create new one child group object. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_EdgesGroup) createGroupObject(); + + /** + * Create all necessary child group objects. + * Base implementation does nothing. + */ + HYDRODATA_EXPORT virtual void createGroupObjects(); + + /** + * Remove all child group objects. + */ + HYDRODATA_EXPORT virtual void removeGroupObjects(); + + /** * Retrieve the top shape of the object from data label. */