From 1627f32b3e7df56354aeac06c12caa31ce8c6405 Mon Sep 17 00:00:00 2001 From: adv Date: Tue, 17 Dec 2013 08:02:11 +0000 Subject: [PATCH] Splitting data for calculation case edges (Feature #242). --- src/HYDROData/CMakeLists.txt | 2 + src/HYDROData/HYDROData_CalculationCase.cxx | 124 +++++++++++++----- src/HYDROData/HYDROData_CalculationCase.h | 17 +++ src/HYDROData/HYDROData_Entity.h | 3 +- src/HYDROData/HYDROData_Iterator.cxx | 2 + src/HYDROData/HYDROData_SplitToZonesTool.cxx | 19 +-- src/HYDROData/HYDROData_SplitToZonesTool.h | 36 +++-- .../HYDROData_SplittedEdgesGroup.cxx | 16 +++ src/HYDROData/HYDROData_SplittedEdgesGroup.h | 49 +++++++ 9 files changed, 213 insertions(+), 55 deletions(-) create mode 100644 src/HYDROData/HYDROData_SplittedEdgesGroup.cxx create mode 100644 src/HYDROData/HYDROData_SplittedEdgesGroup.h diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index a2a0ed56..3aa79d56 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -32,6 +32,7 @@ set(PROJECT_HEADERS HYDROData_Projection.h HYDROData_Region.h HYDROData_River.h + HYDROData_SplittedEdgesGroup.h HYDROData_SplitToZonesTool.h HYDROData_Stream.h HYDROData_Tool.h @@ -70,6 +71,7 @@ set(PROJECT_SOURCES HYDROData_Projection.cxx HYDROData_Region.cxx HYDROData_River.cxx + HYDROData_SplittedEdgesGroup.cxx HYDROData_SplitToZonesTool.cxx HYDROData_Stream.cxx HYDROData_Tool.cxx diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 64085eb5..22079005 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -9,20 +9,25 @@ #include "HYDROData_NaturalObject.h" #include "HYDROData_PolylineXY.h" #include "HYDROData_SplitToZonesTool.h" +#include "HYDROData_SplittedEdgesGroup.h" #include "HYDROData_Region.h" #include "HYDROData_Tool.h" #include "HYDROData_Zone.h" #include #include +#include + #include #include +#include + +#include #include #include #include #include -#include -#include + #define CALCULATION_REGIONS_PREF GetName() + "_Reg" #define CALCULATION_ZONES_PREF GetName() + "_Zone" @@ -151,8 +156,9 @@ void HYDROData_CalculationCase::Update() { HYDROData_Entity::Update(); - // At first we remove previously created regions + // At first we remove previously created objects RemoveRegions(); + RemoveSplittedGroups(); Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); if ( aDocument.IsNull() ) @@ -163,45 +169,73 @@ void HYDROData_CalculationCase::Update() if ( aGeomObjects.IsEmpty() ) return; - HYDROData_SplitToZonesTool::SplitDataList aSplitedZones = - HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects, aBoundaryPolyline ); - if ( aSplitedZones.isEmpty() ) + HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups(); + + HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects = + HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline ); + if ( aSplitedObjects.isEmpty() ) return; QString aRegsPref = CALCULATION_REGIONS_PREF; QString aZonesPref = CALCULATION_ZONES_PREF; + QMap aSplittedEdgesGroupsMap; + // Create result regions for case, by default one zone for one region - HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones ); + HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects ); while( anIter.hasNext() ) { const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next(); - // Create new region - Handle(HYDROData_Region) aRegion = addNewRegion(); + if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone ) + { + // Create new region + Handle(HYDROData_Region) aRegion = addNewRegion(); - QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref ); - aRegion->SetName( aRegionName ); + QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref ); + aRegion->SetName( aRegionName ); - // Add the zone for region - Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone(); + // Add the zone for region + Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone(); - QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref ); - aRegionZone->SetName( aZoneName ); + QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref ); + aRegionZone->SetName( aZoneName ); - aRegionZone->SetShape( aSplitData.Face() ); + aRegionZone->SetShape( aSplitData.Face() ); - // Add the reference object for zone - for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i ) + // Add the reference object for zone + for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i ) + { + const QString& anObjName = aSplitData.ObjectNames.at( i ); + + Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast( + HYDROData_Tool::FindObjectByName( aDocument, anObjName ) ); + if ( aRefObject.IsNull() ) + continue; + + aRegionZone->AddGeometryObject( aRefObject ); + } + } + else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ) { - const QString& anObjName = aSplitData.ObjectNames.at( i ); - - Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast( - HYDROData_Tool::FindObjectByName( aDocument, anObjName ) ); - if ( aRefObject.IsNull() ) + // Create new edges group + if ( aSplitData.ObjectNames.isEmpty() || + aSplitData.Shape.IsNull() || aSplitData.Shape.ShapeType() != TopAbs_EDGE ) + continue; + + QString anObjName = aSplitData.ObjectNames.first(); + if ( anObjName.isEmpty() ) continue; - aRegionZone->AddGeometryObject( aRefObject ); + if ( !aSplittedEdgesGroupsMap.contains( anObjName ) ) + aSplittedEdgesGroupsMap.insert( anObjName, addNewSplittedGroup() ); + + Handle(HYDROData_SplittedEdgesGroup) aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ]; + if ( aSplittedGroup.IsNull() ) + continue; + + TopoDS_Edge anEdge = TopoDS::Edge( aSplitData.Shape ); + aSplittedGroup->AddEdge( anEdge ); } } } @@ -416,19 +450,17 @@ void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& th void HYDROData_CalculationCase::RemoveRegions() { - ClearReferenceObjects( DataTag_Region ); - myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes( true ); + myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes(); } -Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion() +HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const { - TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild(); - - Handle(HYDROData_Region) aNewRegion = - Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) ); - AddRegion( aNewRegion ); + return GetReferenceObjects( DataTag_SplittedGroups ); +} - return aNewRegion; +void HYDROData_CalculationCase::RemoveSplittedGroups() +{ + myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes(); } TopoDS_Shell HYDROData_CalculationCase::GetShell() @@ -663,6 +695,7 @@ Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& return aResZone; } + HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification( const gp_XY& thePoint, const Handle(HYDROData_Zone)& theZone ) const @@ -685,3 +718,28 @@ HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPoi aRes = POINT_ON; return aRes; } + +Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion() +{ + TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild(); + + Handle(HYDROData_Region) aNewRegion = + Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) ); + AddRegion( aNewRegion ); + + return aNewRegion; +} + +Handle(HYDROData_SplittedEdgesGroup) HYDROData_CalculationCase::addNewSplittedGroup() +{ + TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild(); + + Handle(HYDROData_SplittedEdgesGroup) aNewGroup = + Handle(HYDROData_SplittedEdgesGroup)::DownCast( + HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) ); + AddReferenceObject( aNewGroup, DataTag_SplittedGroups ); + + return aNewGroup; +} + + diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index d3f6bcda..eef8ea0b 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -14,6 +14,7 @@ class Handle(HYDROData_Region); class Handle(HYDROData_Zone); class Handle(HYDROData_PolylineXY); class Handle(HYDROData_EdgesGroup); +class Handle(HYDROData_SplittedEdgesGroup); DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity) @@ -176,6 +177,18 @@ public: */ HYDRODATA_EXPORT virtual void RemoveRegions(); + + /** + * Returns all reference geometry groups of calculation case. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetSplittedGroups() const; + + /** + * Removes all reference geometry groups from calculation case. + */ + HYDRODATA_EXPORT virtual void RemoveSplittedGroups(); + + /** * Returns shell containing faces which correspond to regions. * \return shell as TopoDS_Shell @@ -218,6 +231,10 @@ private: */ HYDRODATA_EXPORT virtual Handle(HYDROData_Region) addNewRegion(); + /** + * Add new one splitted edges group for calculation case. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_SplittedEdgesGroup) addNewSplittedGroup(); protected: diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index 00a91985..c1a5fccc 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -43,7 +43,8 @@ const ObjectKind KIND_ARTIFICIAL_OBJECT = 19; const ObjectKind KIND_NATURAL_OBJECT = 20; const ObjectKind KIND_DUMMY_3D = 21; const ObjectKind KIND_EDGES_GROUP = 22; -const ObjectKind KIND_LAST = KIND_EDGES_GROUP; +const ObjectKind KIND_SPLITTED_GROUP = 23; +const ObjectKind KIND_LAST = KIND_SPLITTED_GROUP; DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared) diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index f1dde62f..f0fa49b2 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -19,6 +19,7 @@ #include "HYDROData_VisualState.h" #include "HYDROData_Region.h" #include "HYDROData_River.h" +#include "HYDROData_SplittedEdgesGroup.h" #include "HYDROData_Stream.h" #include "HYDROData_Zone.h" @@ -126,6 +127,7 @@ Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel ) 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; + case KIND_SPLITTED_GROUP: aResult = new HYDROData_SplittedEdgesGroup();break; default: break; } diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index 9b279724..a3fe087a 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -35,8 +35,9 @@ TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const } HYDROData_SplitToZonesTool::SplitDataList -HYDROData_SplitToZonesTool::SplitToZones( const HYDROData_SequenceOfObjects& theObjectList, - const Handle(HYDROData_PolylineXY)& thePolyline ) + HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList, + const HYDROData_SequenceOfObjects& theGroupsList, + const Handle(HYDROData_PolylineXY)& thePolyline ) { SplitDataList anOutputSplitDataList; @@ -59,12 +60,12 @@ HYDROData_SplitToZonesTool::SplitToZones( const HYDROData_SequenceOfObjects& the for ( ; anExp.More(); anExp.Next() ) { TopoDS_Face aFace = TopoDS::Face( anExp.Current() ); if ( !aFace.IsNull() ) { - SplitData aSplitData( aFace, aGeomObj->GetName() ); + SplitData aSplitData( SplitData::Data_Zone, aFace, aGeomObj->GetName() ); anInputSplitDataList.append( aSplitData ); } } } else { - SplitData aSplitData( aShape, aGeomObj->GetName() ); + SplitData aSplitData( SplitData::Data_Zone, aShape, aGeomObj->GetName() ); anInputSplitDataList.append( aSplitData ); } } @@ -116,7 +117,7 @@ HYDROData_SplitToZonesTool::SplitToZones( const HYDROData_SequenceOfObjects& the aMakeFace.Build(); if( aMakeFace.IsDone() ) { - SplitData aBoundarySplitData( aMakeFace.Face(), "" ); + SplitData aBoundarySplitData( SplitData::Data_Zone, aMakeFace.Face(), "" ); SplitDataList aCutSplitDataList; SplitDataListIterator anOutputIter( anOutputSplitDataList ); @@ -173,9 +174,9 @@ bool HYDROData_SplitToZonesTool::SplitTwoData( const SplitData& theData1, BRepAlgoAPI_Cut aCut2( aShape2, aShape1 ); TopoDS_Shape aCut2Shape = aCut2.Shape(); - theData1Subtracted = SplitData( aCut1Shape, anObjectNames1 ); - theData2Subtracted = SplitData( aCut2Shape, anObjectNames2 ); - theDataIntersected = SplitData( aCommonShape, anObjectNames1 + anObjectNames2 ); + theData1Subtracted = SplitData( SplitData::Data_Zone, aCut1Shape, anObjectNames1 ); + theData2Subtracted = SplitData( SplitData::Data_Zone, aCut2Shape, anObjectNames2 ); + theDataIntersected = SplitData( SplitData::Data_Zone, aCommonShape, anObjectNames1 + anObjectNames2 ); return true; } @@ -193,7 +194,7 @@ HYDROData_SplitToZonesTool::ExtractSeparateData( const SplitData& theData ) TopoDS_Face aFace = TopoDS::Face( aShape ); if( !aFace.IsNull() ) { - SplitData aSplitData( aFace, theData.ObjectNames ); + SplitData aSplitData( SplitData::Data_Zone, aFace, theData.ObjectNames ); aSplitDataList.append( aSplitData ); } } diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.h b/src/HYDROData/HYDROData_SplitToZonesTool.h index 4d7780f3..28413ef7 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.h +++ b/src/HYDROData/HYDROData_SplitToZonesTool.h @@ -20,18 +20,29 @@ class HYDRODATA_EXPORT HYDROData_SplitToZonesTool public: struct HYDRODATA_EXPORT SplitData { - TopoDS_Shape Shape; - QStringList ObjectNames; - - SplitData() {} + enum SplitObjectType + { + Data_None, + Data_Zone, + Data_Edge + }; + + TopoDS_Shape Shape; + QStringList ObjectNames; + SplitObjectType Type; + + SplitData() : + Type( Data_None ) {} - SplitData( const TopoDS_Shape& theShape, - const QStringList& theObjectNames ) : - Shape( theShape ), ObjectNames( theObjectNames ) {} + SplitData( const SplitObjectType& theType, + const TopoDS_Shape& theShape, + const QStringList& theObjectNames ) : + Type( theType ), Shape( theShape ), ObjectNames( theObjectNames ) {} - SplitData( const TopoDS_Shape& theShape, - const QString& theObjectNames ) : - Shape( theShape ), ObjectNames( theObjectNames ) {} + SplitData( const SplitObjectType& theType, + const TopoDS_Shape& theShape, + const QString& theObjectName ) : + Type( theType ), Shape( theShape ), ObjectNames( theObjectName ) {} TopoDS_Face Face() const; }; @@ -41,8 +52,9 @@ public: public: - static SplitDataList SplitToZones( const HYDROData_SequenceOfObjects& theObjectList, - const Handle(HYDROData_PolylineXY)& thePolyline ); + static SplitDataList Split( const HYDROData_SequenceOfObjects& theObjectList, + const HYDROData_SequenceOfObjects& theGroupsList, + const Handle(HYDROData_PolylineXY)& thePolyline ); private: diff --git a/src/HYDROData/HYDROData_SplittedEdgesGroup.cxx b/src/HYDROData/HYDROData_SplittedEdgesGroup.cxx new file mode 100644 index 00000000..92a54e94 --- /dev/null +++ b/src/HYDROData/HYDROData_SplittedEdgesGroup.cxx @@ -0,0 +1,16 @@ + +#include "HYDROData_SplittedEdgesGroup.h" + +IMPLEMENT_STANDARD_HANDLE(HYDROData_SplittedEdgesGroup,HYDROData_EdgesGroup) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_SplittedEdgesGroup,HYDROData_EdgesGroup) + +HYDROData_SplittedEdgesGroup::HYDROData_SplittedEdgesGroup() +: HYDROData_EdgesGroup() +{ +} + +HYDROData_SplittedEdgesGroup::~HYDROData_SplittedEdgesGroup() +{ +} + + diff --git a/src/HYDROData/HYDROData_SplittedEdgesGroup.h b/src/HYDROData/HYDROData_SplittedEdgesGroup.h new file mode 100644 index 00000000..e62cadbf --- /dev/null +++ b/src/HYDROData/HYDROData_SplittedEdgesGroup.h @@ -0,0 +1,49 @@ + +#ifndef HYDROData_SplittedEdgesGroup_HeaderFile +#define HYDROData_SplittedEdgesGroup_HeaderFile + +#include + +DEFINE_STANDARD_HANDLE(HYDROData_SplittedEdgesGroup, HYDROData_EdgesGroup) + + +/**\class HYDROData_SplittedEdgesGroup + * \brief The artificial objects are objects created or planned for creation by human. + * + */ +class HYDROData_SplittedEdgesGroup : public HYDROData_EdgesGroup +{ +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_EdgesGroup::DataTag_First + 100 ///< first tag, to reserve + }; + +public: + DEFINE_STANDARD_RTTI(HYDROData_SplittedEdgesGroup); + + /** + * Returns the kind of this object. Must be redefined in all objects of known type. + */ + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_SPLITTED_GROUP; } + +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_SplittedEdgesGroup(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual HYDRODATA_EXPORT ~HYDROData_SplittedEdgesGroup(); +}; + +#endif -- 2.39.2