From: adv Date: Thu, 24 Oct 2013 11:23:30 +0000 (+0000) Subject: The data model has been redesigned to new format. X-Git-Tag: BR_hydro_v_0_3~89 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=84f8b4a57d3cdad820bc1333a5066699cd1c8ae3;p=modules%2Fhydro.git The data model has been redesigned to new format. --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index fed28edf..5e968068 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -1,42 +1,50 @@ include(../../CMake/Common.cmake) -set(PROJECT_HEADERS +set(PROJECT_HEADERS HYDROData.h HYDROData_Application.h + HYDROData_ArtificialObject.h HYDROData_Bathymetry.h + HYDROData_BSplineOperation.h HYDROData_Calculation.h HYDROData_Document.h - HYDROData_Domain.h + HYDROData_Entity.h HYDROData_Image.h + HYDROData_ImmersibleZone.h HYDROData_Iterator.h HYDROData_Lambert93.h + HYDROData_NaturalObject.h HYDROData_Object.h + HYDROData_OperationsFactory.h HYDROData_Polyline.h HYDROData_Region.h + HYDROData_SplitToZonesTool.h HYDROData_Tool.h HYDROData_VisualState.h HYDROData_Zone.h - HYDROOperations_BSpline.h - HYDROOperations_Factory.h ) set(PROJECT_SOURCES HYDROData_Application.cxx + HYDROData_ArtificialObject.cxx HYDROData_Bathymetry.cxx + HYDROData_BSplineOperation.cxx HYDROData_Calculation.cxx HYDROData_Document.cxx - HYDROData_Domain.cxx + HYDROData_Entity.cxx HYDROData_Image.cxx + HYDROData_ImmersibleZone.cxx HYDROData_Iterator.cxx HYDROData_Lambert93.cxx + HYDROData_NaturalObject.cxx HYDROData_Object.cxx + HYDROData_OperationsFactory.cxx HYDROData_Polyline.cxx HYDROData_Region.cxx + HYDROData_SplitToZonesTool.cxx HYDROData_Tool.cxx HYDROData_VisualState.cxx HYDROData_Zone.cxx - HYDROOperations_BSpline.cxx - HYDROOperations_Factory.cxx ) add_definitions( @@ -69,8 +77,8 @@ if(CPPUNIT_IS_OK) test_HYDROData_Polyline.h test_HYDROData_Bathymetry.h test_HYDROData_Calculation.h - test_HYDROOperations_BSpline.h - test_HYDROOperations_Factory.h + test_HYDROData_BSplineOperation.h + test_HYDROData_OperationsFactory.h ) set(TEST_SOURCES @@ -82,8 +90,8 @@ if(CPPUNIT_IS_OK) test_HYDROData_Polyline.cxx test_HYDROData_Bathymetry.cxx test_HYDROData_Calculation.cxx - test_HYDROOperations_BSpline.cxx - test_HYDROOperations_Factory.cxx + test_HYDROData_BSplineOperation.cxx + test_HYDROData_OperationsFactory.cxx ) set(TEST_EXE test_HYDROData) diff --git a/src/HYDROData/HYDROData.vcproj b/src/HYDROData/HYDROData.vcproj index 318ffca1..1c6c0665 100644 --- a/src/HYDROData/HYDROData.vcproj +++ b/src/HYDROData/HYDROData.vcproj @@ -1,7 +1,7 @@ + + @@ -142,13 +146,17 @@ > + + @@ -157,6 +165,10 @@ RelativePath=".\HYDROData_Lambert93.cxx" > + + @@ -198,14 +210,18 @@ + + @@ -222,6 +238,10 @@ RelativePath=".\HYDROData_Application.h" > + + @@ -235,13 +255,17 @@ > + + @@ -250,6 +274,10 @@ RelativePath=".\HYDROData_Lambert93.h" > + + @@ -275,14 +303,18 @@ > + + diff --git a/src/HYDROData/HYDROData_ArtificialObject.cxx b/src/HYDROData/HYDROData_ArtificialObject.cxx new file mode 100644 index 00000000..8a71a5b0 --- /dev/null +++ b/src/HYDROData/HYDROData_ArtificialObject.cxx @@ -0,0 +1,16 @@ + +#include "HYDROData_ArtificialObject.h" + +IMPLEMENT_STANDARD_HANDLE(HYDROData_ArtificialObject,HYDROData_Object) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ArtificialObject,HYDROData_Object) + +HYDROData_ArtificialObject::HYDROData_ArtificialObject() +: HYDROData_Object() +{ +} + +HYDROData_ArtificialObject::~HYDROData_ArtificialObject() +{ +} + + diff --git a/src/HYDROData/HYDROData_ArtificialObject.h b/src/HYDROData/HYDROData_ArtificialObject.h new file mode 100644 index 00000000..34d786b9 --- /dev/null +++ b/src/HYDROData/HYDROData_ArtificialObject.h @@ -0,0 +1,42 @@ + +#ifndef HYDROData_ArtificialObject_HeaderFile +#define HYDROData_ArtificialObject_HeaderFile + +#include + +DEFINE_STANDARD_HANDLE(HYDROData_ArtificialObject, HYDROData_Object) + + +/**\class HYDROData_ArtificialObject + * \brief The artificial objects are objects created or planned for creation by human. + * + */ +class HYDROData_ArtificialObject : public HYDROData_Object +{ +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_Object::DataTag_First + 100 ///< first tag, to reserve + }; + +public: + DEFINE_STANDARD_RTTI(HYDROData_ArtificialObject); + +protected: + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDRODATA_EXPORT HYDROData_ArtificialObject(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual HYDRODATA_EXPORT ~HYDROData_ArtificialObject(); +}; + +#endif diff --git a/src/HYDROData/HYDROData_BSplineOperation.cxx b/src/HYDROData/HYDROData_BSplineOperation.cxx new file mode 100644 index 00000000..df0b2e44 --- /dev/null +++ b/src/HYDROData/HYDROData_BSplineOperation.cxx @@ -0,0 +1,61 @@ +#include + +#include +#include +#include +#include + +HYDROData_BSplineOperation::HYDROData_BSplineOperation( + const QList& thePoints, + const double theZValue, + const bool theIsClosed) +{ + // fill array for algorithm by the received coordinates + int aLen = thePoints.size() / 2; + Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen); + QList::const_iterator aListIter = thePoints.begin(); + for (int ind = 1; ind <= aLen; ind++) { + gp_Pnt aPnt(gp::Origin()); + aPnt.SetX(*aListIter); + aListIter++; + aPnt.SetY(*aListIter); + aListIter++; + aPnt.SetZ(theZValue); + aHCurvePoints->SetValue(ind, aPnt); + } + // compute BSpline + GeomAPI_Interpolate aGBC(aHCurvePoints, theIsClosed, gp::Resolution()); + aGBC.Perform(); + if (aGBC.IsDone()) { + myCurve = aGBC.Curve(); + } +} + +QPainterPath HYDROData_BSplineOperation::ComputePath() const +{ + QPainterPath aResult; + if (myCurve.IsNull()) // returns an empty Path if original curve is invalid + return aResult; + GeomConvert_BSplineCurveToBezierCurve aConverter(myCurve); + int a, aNumArcs = aConverter.NbArcs(); + for(a = 1; a <= aNumArcs; a++) { + Handle(Geom_BezierCurve) anArc = aConverter.Arc(a); + if (a == 1) { // set a start point + gp_Pnt aStart = anArc->StartPoint(); + aResult.moveTo(aStart.X(), aStart.Y()); + } + gp_Pnt anEnd = anArc->EndPoint(); + if (anArc->NbPoles() == 3) { // quadric segment in the path (pole 1 is start, pole 3 is end) + gp_Pnt aPole = anArc->Pole(2); + aResult.quadTo(aPole.X(), aPole.Y(), anEnd.X(), anEnd.Y()); + } else if (anArc->NbPoles() == 4) { // cubic segment (usually this is used) + gp_Pnt aPole1 = anArc->Pole(2); + gp_Pnt aPole2 = anArc->Pole(3); + aResult.cubicTo( + aPole1.X(), aPole1.Y(), aPole2.X(), aPole2.Y(), anEnd.X(), anEnd.Y()); + } else { // error, another number of poles is not supported + return QPainterPath(); + } + } + return aResult; +} diff --git a/src/HYDROData/HYDROData_BSplineOperation.h b/src/HYDROData/HYDROData_BSplineOperation.h new file mode 100644 index 00000000..96be8d09 --- /dev/null +++ b/src/HYDROData/HYDROData_BSplineOperation.h @@ -0,0 +1,40 @@ +#ifndef HYDROData_BSplineOperation_HeaderFile +#define HYDROData_BSplineOperation_HeaderFile + +#include +#include +#include +#include + +/**\class HYDROData_BSplineOperation + * + * \brief Allows to work with splines: create, convert to Qt ToolPath. + * + * Uses GEOM module for creation of BSplines, OCCT algorithms for + * manipulation and conversion. + */ + +class HYDRODATA_EXPORT HYDROData_BSplineOperation +{ +public: + + //! Creates a spline by list of coordinates: pairs X and Y + //! \param thePoints coordinates in format X1, Y1, X2, Y2, etc. must be even number of elements + //! \param theZValue constant value of the spline Z coordinate + //! \param theIsClosed flag indicating that the result spline should be closed + HYDROData_BSplineOperation(const QList& thePoints, + const double theZValue, + const bool theIsClosed); + + //! Returns the BSpline curve passing through the points + //! \returns Null if Computation of BSpline was failed + Handle(Geom_BSplineCurve) Curve() const {return myCurve;} + + //! Performs conversion from BSpline curve to QPainterPath made from Bezier curves + //! \returns computed PainterPath, not stored in this class, so calling of this method is not fast + QPainterPath ComputePath() const; +private: + Handle(Geom_BSplineCurve) myCurve; ///< resulting BSpline, null if something is wrong +}; + +#endif diff --git a/src/HYDROData/HYDROData_Bathymetry.cxx b/src/HYDROData/HYDROData_Bathymetry.cxx index 43b2b105..29ec179c 100644 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@ -19,10 +19,11 @@ #define PYTHON_BATHYMETRY_ID "KIND_BATHYMETRY" -IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_Object) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_Object) +IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_Entity) HYDROData_Bathymetry::HYDROData_Bathymetry() +: HYDROData_Entity() { } diff --git a/src/HYDROData/HYDROData_Bathymetry.h b/src/HYDROData/HYDROData_Bathymetry.h index 68d08aac..7c60181f 100644 --- a/src/HYDROData/HYDROData_Bathymetry.h +++ b/src/HYDROData/HYDROData_Bathymetry.h @@ -2,14 +2,14 @@ #ifndef HYDROData_Bathymetry_HeaderFile #define HYDROData_Bathymetry_HeaderFile -#include +#include class gp_XY; class gp_XYZ; class QPointF; class QFile; -DEFINE_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_Object) +DEFINE_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_Entity) /**\class HYDROData_Bathymetry @@ -17,7 +17,7 @@ DEFINE_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_Object) * * The Bathymetry represents measurement of the altitude of points on the terrain. */ -class HYDROData_Bathymetry : public HYDROData_Object +class HYDROData_Bathymetry : public HYDROData_Entity { public: @@ -31,7 +31,7 @@ protected: */ enum DataTag { - DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve DataTag_AltitudePoints, ///< altitude points, array of reals DataTag_FilePath ///< bathymetry imported file path }; diff --git a/src/HYDROData/HYDROData_Calculation.cxx b/src/HYDROData/HYDROData_Calculation.cxx index 9514bcbd..33e91daf 100644 --- a/src/HYDROData/HYDROData_Calculation.cxx +++ b/src/HYDROData/HYDROData_Calculation.cxx @@ -3,20 +3,21 @@ #include "HYDROData_Document.h" #include "HYDROData_Iterator.h" -#include "HYDROData_Polyline.h" -#include "HYDROData_Zone.h" +#include "HYDROData_Object.h" +#include "HYDROData_SplitToZonesTool.h" #include "HYDROData_Region.h" - -#include +#include "HYDROData_Tool.h" +#include "HYDROData_Zone.h" #include #define PYTHON_CALCULATION_ID "KIND_CALCULATION" -IMPLEMENT_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Object) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Calculation, HYDROData_Object) +IMPLEMENT_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Calculation, HYDROData_Entity) HYDROData_Calculation::HYDROData_Calculation() +: HYDROData_Entity() { } @@ -41,85 +42,141 @@ QStringList HYDROData_Calculation::DumpToPython( MapOfTreatedObjects& theTreated .arg( aCalculName ).arg( aCalculName ); aResList << QString( "" ); - Handle(HYDROData_Polyline) aBoundaryPolyline = GetBoundaryPolyline(); - setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" ); - aResList << QString( "" ); - - HYDROData_SequenceOfObjects aZones = GetZones(); - HYDROData_SequenceOfObjects::Iterator anIter( aZones ); + HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects ); for ( ; anIter.More(); anIter.Next() ) { - Handle(HYDROData_Zone) aRefZone = - Handle(HYDROData_Zone)::DownCast( anIter.Value() ); - if ( !aRefZone.IsNull() ) - setPythonReferenceObject( theTreatedObjects, aResList, aRefZone, "AddZone" ); + Handle(HYDROData_Object) aRefGeomObj = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( !aRefGeomObj.IsNull() ) + setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" ); } aResList << QString( "" ); - aZones = GetRegions(); - anIter.Init( aZones ); + aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName ); + aResList << QString( "" ); + + // Now we restore the regions and zones order + HYDROData_SequenceOfObjects aRegions = GetRegions(); + anIter.Init( aRegions ); for ( ; anIter.More(); anIter.Next() ) { Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() ); - if ( !aRegion.IsNull() ) - setPythonReferenceObject( theTreatedObjects, aResList, aRegion, "AddRegion" ); + if ( aRegion.IsNull() ) + continue; + + QString aRegionName = aRegion->GetName(); + // TODO } return aResList; } -void HYDROData_Calculation::SetBoundaryPolyline( const Handle(HYDROData_Polyline)& thePolyline ) +void HYDROData_Calculation::SplitGeometryObjects() { - SetReferenceObject( thePolyline, DataTag_BoundaryPolyline ); + // At first we remove previously created regions + RemoveRegions(); + RemoveChildRegions(); + + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); + if ( aDocument.IsNull() ) + return; + + HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects(); + if ( aGeomObjects.IsEmpty() ) + return; + + HYDROData_SplitToZonesTool::SplitDataList aSplitedZones = + HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects ); + if ( aSplitedZones.isEmpty() ) + return; + + // Create result regions for case, by default one zone for one region + HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones ); + while( anIter.hasNext() ) + { + const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next(); + + // Create new region + Handle(HYDROData_Region) aRegion = AddNewRegion(); + AddRegion( aRegion ); + + QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" ); + aRegion->SetName( aRegionName ); + + // Add the zone for region + Handle(HYDROData_Zone) aRegionZone = aRegion->AddNewZone(); + aRegion->AddZone( aRegionZone ); + + QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" ); + aRegionZone->SetName( aZoneName ); + + aRegionZone->SetShape( aSplitData.Face() ); + + // 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 ); + } + } } -Handle(HYDROData_Polyline) HYDROData_Calculation::GetBoundaryPolyline() const +int HYDROData_Calculation::NbGeometryObjects() const { - return Handle(HYDROData_Polyline)::DownCast( - GetReferenceObject( DataTag_BoundaryPolyline ) ); + return NbReferenceObjects( DataTag_GeometryObject ); } -void HYDROData_Calculation::RemoveBoundaryPolyline() +void HYDROData_Calculation::AddGeometryObject( const Handle(HYDROData_Object)& theObject ) { - ClearReferenceObjects( DataTag_BoundaryPolyline ); + AddReferenceObject( theObject, DataTag_GeometryObject ); } -int HYDROData_Calculation::NbZones() const +void HYDROData_Calculation::SetGeometryObject( const int theIndex, + const Handle(HYDROData_Object)& theObject ) { - return NbReferenceObjects( DataTag_Zone ); + SetReferenceObject( theObject, DataTag_GeometryObject, theIndex ); } -void HYDROData_Calculation::AddZone( const Handle(HYDROData_Zone)& theZone ) +void HYDROData_Calculation::SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ) { - AddReferenceObject( theZone, DataTag_Zone ); + SetReferenceObjects( theObjects, DataTag_GeometryObject ); } -void HYDROData_Calculation::SetZone( const int theIndex, - const Handle(HYDROData_Zone)& theZone ) +Handle(HYDROData_Object) HYDROData_Calculation::GetGeometryObject( const int theIndex ) const { - SetReferenceObject( theZone, DataTag_Zone, theIndex ); + return Handle(HYDROData_Object)::DownCast( + GetReferenceObject( DataTag_GeometryObject, theIndex ) ); } -void HYDROData_Calculation::SetZones( const HYDROData_SequenceOfObjects& theZones ) +HYDROData_SequenceOfObjects HYDROData_Calculation::GetGeometryObjects() const { - SetReferenceObjects( theZones, DataTag_Zone ); + return GetReferenceObjects( DataTag_GeometryObject ); } -Handle(HYDROData_Zone) HYDROData_Calculation::GetZone( const int theIndex ) const +void HYDROData_Calculation::RemoveGeometryObjects() { - return Handle(HYDROData_Zone)::DownCast( - GetReferenceObject( DataTag_Zone, theIndex ) ); + ClearReferenceObjects( DataTag_GeometryObject ); } -HYDROData_SequenceOfObjects HYDROData_Calculation::GetZones() const +Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion() { - return GetReferenceObjects( DataTag_Zone ); + TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild(); + + return Handle(HYDROData_Region)::DownCast( + HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) ); } -void HYDROData_Calculation::RemoveZones() +void HYDROData_Calculation::RemoveChildRegions() { - ClearReferenceObjects( DataTag_Zone ); + myLab.FindChild( ChildTag_Region ).ForgetAllAttributes( true ); } int HYDROData_Calculation::NbRegions() const @@ -138,6 +195,12 @@ void HYDROData_Calculation::SetRegion( const int theIndex, SetReferenceObject( theRegion, DataTag_Region, theIndex ); } +void HYDROData_Calculation::InsertRegion( const int theBeforeIndex, + const Handle(HYDROData_Region)& theRegion ) +{ + InsertReferenceObject( theRegion, DataTag_Region, theBeforeIndex ); +} + void HYDROData_Calculation::SetRegions( const HYDROData_SequenceOfObjects& theRegions ) { SetReferenceObjects( theRegions, DataTag_Region ); @@ -154,8 +217,20 @@ HYDROData_SequenceOfObjects HYDROData_Calculation::GetRegions() const return GetReferenceObjects( DataTag_Region ); } +void HYDROData_Calculation::RemoveRegion( const Handle(HYDROData_Region)& theRegion ) +{ + if ( theRegion.IsNull() ) + return; + + RemoveReferenceObject( theRegion->Label(), DataTag_Region ); +} + +void HYDROData_Calculation::RemoveRegion( const int theIndex ) +{ + RemoveReferenceObject( DataTag_Region, theIndex ); +} + void HYDROData_Calculation::RemoveRegions() { ClearReferenceObjects( DataTag_Region ); } - diff --git a/src/HYDROData/HYDROData_Calculation.h b/src/HYDROData/HYDROData_Calculation.h index a5b72c0f..60acfb8d 100644 --- a/src/HYDROData/HYDROData_Calculation.h +++ b/src/HYDROData/HYDROData_Calculation.h @@ -1,27 +1,21 @@ -#ifndef HYDROData_HYDROData_Calculation -#define HYDROData_HYDROData_Calculation -#include +#ifndef HYDROData_Calculation_HeaderFile +#define HYDROData_Calculation_HeaderFile -class gp_XY; -class gp_XYZ; -class QPointF; -class QFile; +#include -class Handle(HYDROData_Polyline); -class Handle(HYDROData_Zone); +class Handle(HYDROData_Object); class Handle(HYDROData_Region); -DEFINE_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Object) +DEFINE_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Entity) /**\class HYDROData_Calculation - * \brief Class that stores/retreives information about the Calculation case. + * \brief Calculation case is defined by selection of Geometry objects with or without “Zone of water”. * - * Calculation case is defined by selection of Geometry objects with or without “Zone of water”. */ -class HYDROData_Calculation : public HYDROData_Object +class HYDROData_Calculation : public HYDROData_Entity { protected: @@ -31,10 +25,18 @@ protected: */ enum DataTag { - DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve - DataTag_BoundaryPolyline, ///< reference boundary polyline - DataTag_Zone, ///< reference zones - DataTag_Region ///< reference regions + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + DataTag_GeometryObject, ///< reference geometry objects + DataTag_Region ///< reference regions + }; + + /** + * Enumeration of tags corresponding to the child sub-objects of object. + */ + enum ChildTag + { + ChildTag_First = HYDROData_Entity::ChildTag_First + 100, ///< first tag, to reserve + ChildTag_Region ///< child regions }; public: @@ -56,91 +58,109 @@ public: // Public methods to work with Calculation /** - * Sets boundary polyline for calculation case. + * Split reference geometry objects to non-intersected regions. */ - HYDRODATA_EXPORT virtual void SetBoundaryPolyline( const Handle(HYDROData_Polyline)& thePolyline ); + HYDRODATA_EXPORT virtual void SplitGeometryObjects(); + /** - * Returns boundary polyline of calculation case. + * Returns number of geometry objects for calculation case. */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline) GetBoundaryPolyline() const; + HYDRODATA_EXPORT virtual int NbGeometryObjects() const; /** - * Removes boundary polyline of calculation case. + * Add new one geometry object for calculation case. */ - HYDRODATA_EXPORT virtual void RemoveBoundaryPolyline(); - + HYDRODATA_EXPORT virtual void AddGeometryObject( const Handle(HYDROData_Object)& theObject ); /** - * Returns number of refrence zones for calculation case. + * Replace the geometry object for calculation case. */ - HYDRODATA_EXPORT virtual int NbZones() const; + HYDRODATA_EXPORT virtual void SetGeometryObject( const int theIndex, + const Handle(HYDROData_Object)& theObject ); /** - * Add new one refrence zone for calculation case. + * Sets the geometry object for calculation case. */ - HYDRODATA_EXPORT virtual void AddZone( const Handle(HYDROData_Zone)& theZone ); + HYDRODATA_EXPORT virtual void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); /** - * Replace the refrence zone for calculation case. + * Returns geometry object of calculation case by index. */ - HYDRODATA_EXPORT virtual void SetZone( const int theIndex, - const Handle(HYDROData_Zone)& theZone ); + HYDRODATA_EXPORT virtual Handle(HYDROData_Object) GetGeometryObject( const int theIndex ) const; /** - * Sets the refrence zones for calculation case. + * Returns all geometry objects of calculation case. */ - HYDRODATA_EXPORT virtual void SetZones( const HYDROData_SequenceOfObjects& theZones ); + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryObjects() const; /** - * Returns refrence zone of calculation case by index. + * Removes all geometry objects from calculation case. */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZone( const int theIndex ) const; + HYDRODATA_EXPORT virtual void RemoveGeometryObjects(); + /** - * Returns all refrence zone of calculation case. + * Add new one region for calculation case. + * The new region is not added into the list of reference regions. */ - HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetZones() const; + HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion(); /** - * Removes all refrence zone of calculation case. + * Removes all child regions from calculation case. */ - HYDRODATA_EXPORT virtual void RemoveZones(); + HYDRODATA_EXPORT virtual void RemoveChildRegions(); /** - * Returns number of regions for calculation case. + * Returns number of reference regions of calculation case. */ - HYDRODATA_EXPORT virtual int NbRegions() const; + int NbRegions() const; /** - * Add new one region for calculation case. + * Add new one reference region for calculation case. */ HYDRODATA_EXPORT virtual void AddRegion( const Handle(HYDROData_Region)& theRegion ); /** - * Replace the region for calculation case. + * Replace the reference region for calculation case. */ HYDRODATA_EXPORT virtual void SetRegion( const int theIndex, const Handle(HYDROData_Region)& theRegion ); /** - * Sets the refrence region for calculation case. + * Inserts the reference region for calculation case before given index. + */ + HYDRODATA_EXPORT virtual void InsertRegion( const int theBeforeIndex, + const Handle(HYDROData_Region)& theRegion ); + + /** + * Sets reference regions for calculation case. */ HYDRODATA_EXPORT virtual void SetRegions( const HYDROData_SequenceOfObjects& theRegions ); /** - * Returns region of calculation case by index. + * Returns reference region of calculation case by index. */ HYDRODATA_EXPORT virtual Handle(HYDROData_Region) GetRegion( const int theIndex ) const; /** - * Returns all regions of calculation case. + * Returns all reference regions of calculation case. */ HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetRegions() const; /** - * Removes all regions of calculation case. + * Removes reference region from calculation case. + */ + HYDRODATA_EXPORT virtual void RemoveRegion( const Handle(HYDROData_Region)& theRegion ); + + /** + * Removes reference region from calculation case by it index. + */ + HYDRODATA_EXPORT virtual void RemoveRegion( const int theIndex ); + + /** + * Removes all reference regions from calculation case. */ HYDRODATA_EXPORT virtual void RemoveRegions(); diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index 7c43e53e..43ce2a1f 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -38,7 +38,7 @@ Handle(HYDROData_Document) HYDROData_Document::Document(const int theStudyID) } Handle(HYDROData_Document) HYDROData_Document::Document( - const Handle(HYDROData_Object)& theObject ) + const Handle(HYDROData_Entity)& theObject ) { Handle(HYDROData_Document) aResDoc; if ( theObject.IsNull() ) @@ -197,7 +197,7 @@ bool HYDROData_Document::DumpToPython( const QString& theFileName ) const aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_IMAGE ); aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_POLYLINE ); aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_BATHYMETRY ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_ZONE ); + aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE ); aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_CALCULATION ); return aRes; @@ -250,7 +250,7 @@ bool HYDROData_Document::dumpPartitionToPython( QFile& theFile, HYDROData_Iterator anIterator( this, theObjectKind ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Object) anObject = anIterator.Current(); + Handle(HYDROData_Entity) anObject = anIterator.Current(); if ( anObject.IsNull() ) continue; @@ -352,7 +352,7 @@ void HYDROData_Document::Redo() myTransactionsAfterSave++; } -Handle_HYDROData_Object HYDROData_Document::CreateObject(const ObjectKind theKind) +Handle(HYDROData_Entity) HYDROData_Document::CreateObject(const ObjectKind theKind) { return HYDROData_Iterator::CreateObject(this, theKind); } diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 0701b884..a702b03c 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -2,7 +2,7 @@ #define HYDROData_Document_HeaderFile #include -#include +#include #include @@ -43,7 +43,7 @@ public: //! Returns the document by object HYDRODATA_EXPORT static Handle(HYDROData_Document) Document( - const Handle(HYDROData_Object)& theObject ); + const Handle(HYDROData_Entity)& theObject ); //! Returns true if data model contains document for this study HYDRODATA_EXPORT static bool HasDocument(const int theStudyID); @@ -110,7 +110,7 @@ public: //! Creates and locates in the document a new object //! \param theKind kind of the created object, can not be UNKNOWN //! \returns the created object - HYDRODATA_EXPORT Handle_HYDROData_Object CreateObject(const ObjectKind theKind); + HYDRODATA_EXPORT Handle(HYDROData_Entity) CreateObject(const ObjectKind theKind); protected: diff --git a/src/HYDROData/HYDROData_Domain.cxx b/src/HYDROData/HYDROData_Domain.cxx deleted file mode 100644 index 8491c19d..00000000 --- a/src/HYDROData/HYDROData_Domain.cxx +++ /dev/null @@ -1,128 +0,0 @@ - -#include "HYDROData_Domain.h" - -#include "HYDROData_Bathymetry.h" -#include "HYDROData_Document.h" -#include "HYDROData_Iterator.h" - -#include - -#include -#include - -IMPLEMENT_STANDARD_HANDLE(HYDROData_Domain, HYDROData_Object) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Domain, HYDROData_Object) - -HYDROData_Domain::HYDROData_Domain() -{ -} - -HYDROData_Domain::~HYDROData_Domain() -{ -} - -QStringList HYDROData_Domain::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const -{ - QStringList aResList; - - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); - if ( aDocument.IsNull() ) - return aResList; - - QString aDocName = aDocument->GetDocPyName(); - QString aZoneName = GetName(); - - aResList << QString( "%1 = %2.CreateObject( %3 );" ) - .arg( aZoneName ).arg( aDocName ).arg( getPythonKindId() ); - aResList << QString( "%1.SetName( \"%2\" );" ) - .arg( aZoneName ).arg( aZoneName ); - aResList << QString( "" ); - - QColor aFillingColor = GetFillingColor(); - aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" ) - .arg( aFillingColor.red() ).arg( aFillingColor.green() ) - .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() ); - aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName ); - aResList << QString( "" ); - - QColor aBorderColor = GetBorderColor(); - aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" ) - .arg( aBorderColor.red() ).arg( aBorderColor.green() ) - .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() ); - aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName ); - aResList << QString( "" ); - - HYDROData_SequenceOfObjects aZoneBaths = GetBathymetries(); - HYDROData_SequenceOfObjects::Iterator aBathsIter( aZoneBaths ); - for ( ; aBathsIter.More(); aBathsIter.Next() ) - { - Handle(HYDROData_Bathymetry) aRefBath = - Handle(HYDROData_Bathymetry)::DownCast( aBathsIter.Value() ); - if ( !aRefBath.IsNull() ) - setPythonReferenceObject( theTreatedObjects, aResList, aRefBath, "AddBathymetry" ); - } - - return aResList; -} - -QColor HYDROData_Domain::DefaultFillingColor() -{ - return QColor( Qt::green ); -} - -void HYDROData_Domain::SetFillingColor( const QColor& theColor ) -{ - return SetColor( theColor, DataTag_FillingColor ); -} - -QColor HYDROData_Domain::GetFillingColor() const -{ - return GetColor( DefaultFillingColor(), DataTag_FillingColor ); -} - -QColor HYDROData_Domain::DefaultBorderColor() -{ - return QColor( Qt::transparent ); -} - -void HYDROData_Domain::SetBorderColor( const QColor& theColor ) -{ - return SetColor( theColor, DataTag_BorderColor ); -} - -QColor HYDROData_Domain::GetBorderColor() const -{ - return GetColor( DefaultBorderColor(), DataTag_BorderColor ); -} - -int HYDROData_Domain::NbBathymetries() const -{ - return NbReferenceObjects( DataTag_Bathymetry ); -} - -void HYDROData_Domain::AddBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ) -{ - AddReferenceObject( theBathymetry, DataTag_Bathymetry ); -} - -void HYDROData_Domain::SetBathymetry( const int theIndex, - const Handle(HYDROData_Bathymetry)& theBathymetry ) -{ - SetReferenceObject( theBathymetry, DataTag_Bathymetry, theIndex ); -} - -Handle(HYDROData_Bathymetry) HYDROData_Domain::GetBathymetry( const int theIndex ) const -{ - return Handle(HYDROData_Bathymetry)::DownCast( - GetReferenceObject( DataTag_Bathymetry, theIndex ) ); -} - -HYDROData_SequenceOfObjects HYDROData_Domain::GetBathymetries() const -{ - return GetReferenceObjects( DataTag_Bathymetry ); -} - -void HYDROData_Domain::RemoveBathymetries() -{ - ClearReferenceObjects( DataTag_Bathymetry ); -} diff --git a/src/HYDROData/HYDROData_Domain.h b/src/HYDROData/HYDROData_Domain.h deleted file mode 100644 index ac1a9101..00000000 --- a/src/HYDROData/HYDROData_Domain.h +++ /dev/null @@ -1,144 +0,0 @@ - -#ifndef HYDROData_Domain_HeaderFile -#define HYDROData_Domain_HeaderFile - -#include - -#include - -#include -#include - -class Handle(HYDROData_Bathymetry); - -DEFINE_STANDARD_HANDLE(HYDROData_Domain, HYDROData_Object) - - -/**\class HYDROData_Domain - * \brief Class that stores/retreives information about the 2d surface. - */ -class HYDROData_Domain : public HYDROData_Object -{ - -protected: - /** - * Enumeration of tags corresponding to the persistent object parameters. - */ - enum DataTag - { - DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve - DataTag_Bathymetry, ///< reference bathymetries - DataTag_FillingColor, ///< filling color of zone - DataTag_BorderColor, ///< border color of zone - }; - -public: - DEFINE_STANDARD_RTTI(HYDROData_Domain); - - /** - * Returns the kind of this object. Must be redefined in all objects of known type. - */ - HYDRODATA_EXPORT virtual const ObjectKind GetKind() const = 0; - - /** - * Dump object to Python script representation. - */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; - - - /** - * Returns default filling color for new zone. - */ - HYDRODATA_EXPORT static QColor DefaultFillingColor(); - - /** - * Sets filling color for zone. - */ - HYDRODATA_EXPORT virtual void SetFillingColor( const QColor& theColor ); - - /** - * Returns filling color of zone. - */ - HYDRODATA_EXPORT virtual QColor GetFillingColor() const; - - - /** - * Returns default border color for new zone. - */ - HYDRODATA_EXPORT static QColor DefaultBorderColor(); - - /** - * Sets border color for zone. - */ - HYDRODATA_EXPORT virtual void SetBorderColor( const QColor& theColor ); - - /** - * Returns border color of zone. - */ - HYDRODATA_EXPORT virtual QColor GetBorderColor() const; - - - /** - * Returns number of bathymetry objects for zone. - */ - HYDRODATA_EXPORT virtual int NbBathymetries() const; - - /** - * Add reference bathymetry object for zone. - */ - HYDRODATA_EXPORT virtual void AddBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ); - - /** - * Change reference bathymetry object with given index for zone. - */ - HYDRODATA_EXPORT virtual void SetBathymetry( const int theIndex, - const Handle(HYDROData_Bathymetry)& theBathymetry ); - - /** - * Returns reference bathymetry object of zone by it index. - */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Bathymetry) GetBathymetry( const int theIndex ) const; - - /** - * Returns list of all reference bathymetry objects of zone. - */ - HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetBathymetries() const; - - /** - * Clear list of bathymetry objects of zone. - */ - HYDRODATA_EXPORT virtual void RemoveBathymetries(); - - /** - * Returns data of object wrapped to QVariant. - * Reimplemented to wrap and return saved 2d polyline. - */ - //HYDRODATA_EXPORT virtual QVariant GetDataVariant(); - - /** - * Returns the shape of the the object. - */ - HYDRODATA_EXPORT virtual TopoDS_Face Face() const = 0; - -protected: - - friend class HYDROData_Iterator; - - /** - * Creates new object in the internal data structure. Use higher level objects - * to create objects with real content. - */ - HYDROData_Domain(); - - /** - * Destructs properties of the object and object itself, removes it from the document. - */ - ~HYDROData_Domain(); - - /** - * Returns id for creation of object in python scripting. - */ - virtual QString getPythonKindId() const = 0; -}; - -#endif diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx new file mode 100644 index 00000000..be8a51ed --- /dev/null +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -0,0 +1,392 @@ + +#include "HYDROData_Entity.h" + +#include "HYDROData_Iterator.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE(HYDROData_Entity,MMgt_TShared) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Entity,MMgt_TShared) + +// is equal function for unique object mapping +bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2) +{ + if ( !theObj1.IsNull() && !theObj2.IsNull() ) + return theObj1->ID() == theObj2->ID(); + return false; +} + +QString HYDROData_Entity::GetName() const +{ + Handle(TDataStd_Name) aName; + if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) { + TCollection_AsciiString aStr(aName->Get()); + return QString(aStr.ToCString()); + } + return QString(); +} + +void HYDROData_Entity::SetName(const QString& theName) +{ + TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); +} + +QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList anEmptyList; + return anEmptyList; +} + +void HYDROData_Entity::Update( const bool theIsForce ) +{ +} + +QVariant HYDROData_Entity::GetDataVariant() +{ + return QVariant(); +} + +bool HYDROData_Entity::IsRemoved() const +{ + return !myLab.HasAttribute(); +} + +void HYDROData_Entity::Remove() +{ + return myLab.ForgetAllAttributes( true ); +} + +HYDROData_Entity::HYDROData_Entity() +{ +} + +HYDROData_Entity::~HYDROData_Entity() +{ +} + +void HYDROData_Entity::CopyTo(Handle_HYDROData_Entity theDestination) const +{ + TDF_CopyLabel aCopy(myLab, theDestination->Label()); + aCopy.Perform(); +} + +void HYDROData_Entity::SetLabel(TDF_Label theLabel) +{ + myLab = theLabel; +} + +void HYDROData_Entity::SaveByteArray(const int theTag, + const char* theData, const int theLen) +{ + TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag); + // array is empty, remove the attribute + if (theLen <= 0) { + aLab.ForgetAttribute(TDataStd_ByteArray::GetID()); + return; + } + // store data of image in byte array + Handle(TDataStd_ByteArray) aData; + if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) { + aData = TDataStd_ByteArray::Set(aLab, 1, theLen); + } + // copy bytes one by one + if (aData->Length() != theLen) { + Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen); + for(int a = 0; a < theLen; a++) + aNewData->SetValue(a + 1, theData[a]); + aData->ChangeArray(aNewData); + } else { + for(int a = 0; a < theLen; a++) + aData->SetValue(a + 1, theData[a]); + } +} + +const char* HYDROData_Entity::ByteArray(const int theTag, int& theLen) const +{ + TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag); + Handle(TDataStd_ByteArray) aData; + if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) + return NULL; // return empty image if there is no array + theLen = aData->Length(); + if (theLen) + return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1))); + return NULL; +} + +int HYDROData_Entity::NbReferenceObjects( const int theTag ) const +{ + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); + return aRefs.IsNull() ? 0 : aRefs->Extent(); +} + +void HYDROData_Entity::AddReferenceObject( const Handle_HYDROData_Entity& theObj, + const int theTag ) +{ + if ( theObj.IsNull() ) + return; + + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true ); + aRefs->Append( theObj->Label() ); +} + +void HYDROData_Entity::SetReferenceObject( const Handle_HYDROData_Entity& theObj, + const int theTag, + const int theIndex ) +{ + if ( theObj.IsNull() ) + { + RemoveReferenceObject( theTag, theIndex ); + return; + } + + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true ); + + if ( theIndex >= aRefs->Extent() ) + { + aRefs->Append( theObj->Label() ); + } + else if ( theIndex < 0 ) + { + aRefs->Prepend( theObj->Label() ); + } + else + { + RemoveReferenceObject( theTag, theIndex ); + + Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theIndex ); + + aRefs = getReferenceList( theTag, true ); // because reference list can be removed + if ( !aBeforeObj.IsNull() ) + aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() ); + else + aRefs->Append( theObj->Label() ); + } +} + +void HYDROData_Entity::InsertReferenceObject( const Handle_HYDROData_Entity& theObj, + const int theTag, + const int theBeforeIndex ) +{ + if ( theObj.IsNull() ) + return; + + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true ); + + if ( theBeforeIndex >= aRefs->Extent() ) + { + aRefs->Append( theObj->Label() ); + } + else if ( theBeforeIndex < 0 ) + { + aRefs->Prepend( theObj->Label() ); + } + else + { + Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theBeforeIndex ); + if ( !aBeforeObj.IsNull() ) + aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() ); + else + aRefs->Append( theObj->Label() ); + } +} + +void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects, + const int theTag ) +{ + ClearReferenceObjects( theTag ); + if ( theObjects.IsEmpty() ) + return; + + HYDROData_SequenceOfObjects::Iterator anIter( theObjects ); + for ( ; anIter.More(); anIter.Next() ) + AddReferenceObject( anIter.Value(), theTag ); +} + +Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag, + const int theIndex ) const +{ + Handle(HYDROData_Entity) aRes; + + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); + if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() ) + return aRes; + + TDF_ListIteratorOfLabelList anIter( aRefs->List() ); + for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex ); + + const TDF_Label& aRefLabel = anIter.Value(); + aRes = HYDROData_Iterator::Object( aRefLabel ); + + return aRes; +} + +HYDROData_SequenceOfObjects HYDROData_Entity::GetReferenceObjects( const int theTag ) const +{ + HYDROData_SequenceOfObjects aRes; + + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); + if ( aRefs.IsNull() ) + return aRes; + + TDF_ListIteratorOfLabelList anIter( aRefs->List() ); + for ( ; anIter.More(); anIter.Next() ) + { + const TDF_Label& aRefLabel = anIter.Value(); + + Handle(HYDROData_Entity) aRefObject = HYDROData_Iterator::Object( aRefLabel ); + if ( aRefObject.IsNull() ) + continue; + + aRes.Append( aRefObject ); + } + + return aRes; +} + +void HYDROData_Entity::RemoveReferenceObject( const TDF_Label& theRefLabel, + const int theTag ) +{ + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); + if ( aRefs.IsNull() ) + return; + + if ( aRefs->Extent() == 1 ) + { + // remove all if only one + ClearReferenceObjects( theTag ); + return; + } + + aRefs->Remove( theRefLabel ); +} + +void HYDROData_Entity::RemoveReferenceObject( const int theTag, + const int theIndex ) +{ + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); + if ( aRefs.IsNull() ) + return; + + if ( aRefs->Extent() == 1 && theIndex == 0 ) + { + // remove all if only one + ClearReferenceObjects( theTag ); + return; + } + + int anIndex = 0; + TDF_ListIteratorOfLabelList anIter( aRefs->List() ); + for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex ); + + if ( anIndex != theIndex || !anIter.More() ) + return; + + const TDF_Label& aRefLabel = anIter.Value(); + aRefs->Remove( aRefLabel ); +} + +void HYDROData_Entity::ClearReferenceObjects( const int theTag ) +{ + TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); + aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() ); +} + +Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag, + const bool theIsCreate ) const +{ + TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); + + Handle(TDataStd_ReferenceList) aRefs; + if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate ) + aRefs = TDataStd_ReferenceList::Set( aLabel ); + + return aRefs; +} + +void HYDROData_Entity::SetColor( const QColor& theColor, + const int theTag ) +{ + TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); + + Handle(TDataStd_IntegerArray) aColorArray; + if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) + aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 ); + + aColorArray->SetValue( 1, theColor.red() ); + aColorArray->SetValue( 2, theColor.green() ); + aColorArray->SetValue( 3, theColor.blue() ); + aColorArray->SetValue( 4, theColor.alpha() ); +} + +QColor HYDROData_Entity::GetColor( const QColor& theDefColor, + const int theTag ) const +{ + QColor aResColor = theDefColor; + + TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); + + Handle(TDataStd_IntegerArray) aColorArray; + if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) + { + aResColor.setRed( aColorArray->Value( 1 ) ); + aResColor.setGreen( aColorArray->Value( 2 ) ); + aResColor.setBlue( aColorArray->Value( 3 ) ); + aResColor.setAlpha( aColorArray->Value( 4 ) ); + } + + return aResColor; +} + +void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, + QStringList& theScript, + const Handle(HYDROData_Entity)& theRefObject, + const QString& theMethod ) const +{ + if ( theRefObject.IsNull() ) + return; + + QString aRefObjName = theRefObject->GetName(); + if ( aRefObjName.isEmpty() ) + return; + + bool anIsToSetObject = true; + + // The definition of reference object must be dumped before this + if ( !theTreatedObjects.contains( aRefObjName ) ) + { + // Write definition of reference polyline + QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects ); + if ( ( anIsToSetObject = !aRefObjDump.isEmpty() ) ) + { + QStringList aTmpList = theScript; + theScript = aRefObjDump; + + theScript << QString( "" ); + theScript << aTmpList; + + theTreatedObjects.insert( aRefObjName, theRefObject ); + } + } + + if ( anIsToSetObject ) + { + theScript << QString( "%1.%2( %3 );" ) + .arg( GetName() ).arg( theMethod ).arg( aRefObjName ); + } +} + + diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h new file mode 100644 index 00000000..ca4ac508 --- /dev/null +++ b/src/HYDROData/HYDROData_Entity.h @@ -0,0 +1,295 @@ + +#ifndef HYDROData_Entity_HeaderFile +#define HYDROData_Entity_HeaderFile + +#include "HYDROData.h" + +#include + +#include + +#include + +class QColor; +class QString; +class QVariant; +class QStringList; +class Handle(TDataStd_ReferenceList); +class Handle_HYDROData_Entity; + +///! Kind of an object in a document +typedef int ObjectKind; + +const ObjectKind KIND_UNKNOWN = 0; ///! Unrecognized object +const ObjectKind KIND_IMAGE = 1; +const ObjectKind KIND_POLYLINE = 2; +const ObjectKind KIND_BATHYMETRY = 3; +const ObjectKind KIND_IMMERSIBLE_ZONE = 4; +const ObjectKind KIND_GUIDE_LINE = 5; +const ObjectKind KIND_PROFILE = 6; +const ObjectKind KIND_CALCULATION = 7; +const ObjectKind KIND_ZONE = 8; +const ObjectKind KIND_REGION = 9; +const ObjectKind KIND_VISUAL_STATE = 10; +const ObjectKind KIND_LAST = KIND_VISUAL_STATE; + +DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared) + +typedef QMap MapOfTreatedObjects; + +typedef NCollection_Sequence HYDROData_SequenceOfObjects; + + +/**\class HYDROData_Entity + * \brief Generic class of any object in the data model. + * + * Interface for getting access to the object that belong to the data model. + * Managed by Document. Provides access to the common properties: + * kind of an object, name. + */ +class HYDROData_Entity : public MMgt_TShared +{ + +protected: + + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = 0 ///< first tag, to reserve + // ... + }; + + /** + * Enumeration of tags corresponding to the child sub-objects of object. + */ + enum ChildTag + { + ChildTag_First = 0 ///< first tag, to reserve + // ... + }; + +public: + DEFINE_STANDARD_RTTI(HYDROData_Entity); + + /** + * Returns the kind of this object. Must be redefined in all objects of known type. + */ + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; } + + /** + * Returns the name of this object. + */ + HYDRODATA_EXPORT QString GetName() const; + + /** + * Updates the name of this object. + */ + HYDRODATA_EXPORT void SetName(const QString& theName); + + /** + * Dump object to Python script representation. + * Base implementation returns empty list, + * You should reimplement this function in your derived class if it + * has Python API and can be imported/exported from/to Python script. + */ + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + + /** + * Updates object state. + * Base implementation dose nothing. + * \param theIsForce force reupdating of data object + */ + HYDRODATA_EXPORT virtual void Update( const bool theIsForce = true ); + + /** + * Returns data of object wrapped to QVariant. + * Base implementation returns null value. + */ + HYDRODATA_EXPORT virtual QVariant GetDataVariant(); + + /** + * Checks is object exists in the data structure. + * \returns true is object is not exists in the data model + */ + HYDRODATA_EXPORT bool IsRemoved() const; + + /** + * Removes object and it child sub-objects from the data structure. + */ + HYDRODATA_EXPORT virtual void Remove(); + + /** + * Returns unique integer identifier of the object (may be used for ordering of objects) + */ + HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();} + + /** + * Copies all properties of this to the destinated object. + * Objects must be the same type. + * \param theDestination initialized object (from any document) - target of copying + */ + HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Entity theDestination) const; + + /** + * Returns the label of this object. + */ + HYDRODATA_EXPORT TDF_Label& Label() {return myLab;} + +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_Entity(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual HYDRODATA_EXPORT ~HYDROData_Entity(); + + /** + * Put the object to the label of the document. + * \param theLabel new label of the object + */ + HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel); + + /** + * Internal method that used to store the byte array attribute + * \param theTag tag of a label to store attribute (for 0 this is myLab) + * \param theData pointer to bytes array + * \param theLen number of bytes in byte array that must be stored + */ + void SaveByteArray(const int theTag, const char* theData, const int theLen); + + /** + * Internal method that used to retreive the content of byte array attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theLen number of bytes in byte array + * \returns pointer to the internal data structure wit harray content, + * or NULL if array size is zero + */ + const char* ByteArray(const int theTag, int& theLen) const; + + /** + * Internal method that used to store the reference object label attribute + * \param theObj pointer to reference object + * \param theTag tag of a label to store attribute (for 0 this is myLab) + */ + int NbReferenceObjects( const int theTag = 0 ) const; + + /** + * Internal method that used to store the reference object label attribute + * \param theObj pointer to reference object + * \param theTag tag of a label to store attribute (for 0 this is myLab) + */ + void AddReferenceObject( const Handle_HYDROData_Entity& theObj, + const int theTag = 0 ); + + /** + * Internal method that used to store the reference object label attribute + * \param theObj pointer to reference object + * \param theTag tag of a label to store attribute (for 0 this is myLab) + * \param theIndex index in the list of references + - if more that len then just append it to the end of list + - if less than zero then prepend to the list + - indexing starts from 0 + */ + void SetReferenceObject( const Handle_HYDROData_Entity& theObj, + const int theTag = 0, + const int theIndex = 0 ); + + /** + * Internal method that used to store the reference object label attribute + * \param theObj pointer to reference object + * \param theTag tag of a label to store attribute (for 0 this is myLab) + * \param theBeforeIndex index in the list of references + - if more that len then just append it to the end of list + - if less than zero then prepend to the list + - indexing starts from 0 + */ + void InsertReferenceObject( const Handle_HYDROData_Entity& theObj, + const int theTag = 0, + const int theBeforeIndex = 0 ); + + /** + * Internal method that used to store the reference object label attribute + * \param theObjects sequence with pointers to reference objects + * \param theTag tag of a label to store attribute (for 0 this is myLab) + */ + void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects, + const int theTag = 0 ); + + /** + * Internal method that used to retreive the reference object(s) attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theIndex index in the list of references + * - indexing starts from 0 + * \returns pointer to reference object or NULL if label is not set + */ + Handle_HYDROData_Entity GetReferenceObject( const int theTag = 0, + const int theIndex = 0 ) const; + + HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const; + + /** + * Internal method that used to remove the reference object attribute + * \param theRefLabel reference object label to remove + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + */ + void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 ); + + /** + * Internal method that used to remove the reference object attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theIndex index in the list of references + * - indexing starts from 0 + */ + void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 ); + + /** + * Internal method that used to clear list of the reference objects attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + */ + void ClearReferenceObjects( const int theTag = 0 ); + + /** + * Internal method that used to store the color attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theColor color to save + */ + void SetColor( const QColor& theColor, const int theTag = 0 ); + + /** + * Internal method that used to retreive the color attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theDefColor default color to return if attribute has not been set before + */ + QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const; + + +protected: + + void setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, + QStringList& theScript, + const Handle(HYDROData_Entity)& theRefObject, + const QString& theMethod ) const; +protected: + + Handle(TDataStd_ReferenceList) getReferenceList( const int theTag, + const bool theIsCreate ) const; + + +protected: + /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty. + TDF_Label myLab; ///< label of this object +}; + +///! Is Equal for HYDROData_Entity mapping +HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2); + +#endif diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 8a94d751..ca01c655 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -3,7 +3,7 @@ #include "HYDROData_Document.h" #include "HYDROData_Tool.h" -#include "HYDROOperations_Factory.h" +#include "HYDROData_OperationsFactory.h" #include #include @@ -24,10 +24,11 @@ static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad0 #define PYTHON_IMAGE_ID "KIND_IMAGE" -IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Object) +IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity) HYDROData_Image::HYDROData_Image() +: HYDROData_Entity() { } @@ -126,7 +127,7 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject aResList << QString( "%1.SetOperatorName( \"%2\" );" ) .arg( anImageName ).arg( anOperatorName ); - ImageComposer_Operator* anImageOp = HYDROOperations_Factory::Factory()->Operator( this ); + ImageComposer_Operator* anImageOp = HYDROData_OperationsFactory::Factory()->Operator( this ); if ( anImageOp ) { // Dump operation arguments @@ -166,7 +167,7 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject void HYDROData_Image::Update( const bool theIsForce ) { - HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); + HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); // Update image only if there is an operation ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() ); @@ -179,7 +180,7 @@ void HYDROData_Image::Update( const bool theIsForce ) if ( aNbReferences > 0 ) { // First referenced object - Handle(HYDROData_Object) aRefObj = Reference( 0 ); + Handle(HYDROData_Entity) aRefObj = Reference( 0 ); if ( !aRefObj.IsNull() ) { anObj1 = aRefObj->GetDataVariant(); @@ -195,7 +196,7 @@ void HYDROData_Image::Update( const bool theIsForce ) if ( aNbReferences > 1 ) { // Second referenced object - Handle(HYDROData_Object) aRefObj = Reference( 1 ); + Handle(HYDROData_Entity) aRefObj = Reference( 1 ); if ( !aRefObj.IsNull() ) anObj2 = aRefObj->GetDataVariant(); } @@ -399,7 +400,7 @@ int HYDROData_Image::TrsfMode() const return 0; } -void HYDROData_Image::AppendReference( const Handle(HYDROData_Object)& theReferenced ) +void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced ) { AddReferenceObject( theReferenced, 0 ); } @@ -409,13 +410,13 @@ int HYDROData_Image::NbReferences() const return NbReferenceObjects( 0 ); } -Handle(HYDROData_Object) HYDROData_Image::Reference( const int theIndex ) const +Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const { return GetReferenceObject( 0, theIndex ); } void HYDROData_Image::ChangeReference( - const int theIndex, Handle(HYDROData_Object) theReferenced) + const int theIndex, Handle(HYDROData_Entity) theReferenced) { SetReferenceObject( theReferenced, 0, theIndex ); } diff --git a/src/HYDROData/HYDROData_Image.h b/src/HYDROData/HYDROData_Image.h index ad598412..382cd817 100644 --- a/src/HYDROData/HYDROData_Image.h +++ b/src/HYDROData/HYDROData_Image.h @@ -1,12 +1,13 @@ + #ifndef HYDROData_Image_HeaderFile #define HYDROData_Image_HeaderFile -#include +#include #include #include -DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object) +DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity) /**\class HYDROData_Image * \brief Class that stores/retreives information about the image. @@ -14,7 +15,7 @@ DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object) * Keeps image as binary array, transformation and other properties * of image with correspondent API for forkind wit hthese properties. */ -class HYDROData_Image : public HYDROData_Object +class HYDROData_Image : public HYDROData_Entity { protected: /** @@ -22,7 +23,7 @@ protected: */ enum DataTag { - DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve DataTag_Operator, ///< name of the operator that must be executed for image update DataTag_TrsfMode, ///< transformation mode (0 - Lambert93, 1 - Cartesian) DataTag_TrsfPoints, ///< image transformation points (3 input + 3 output lambert + 3 output cartesian) @@ -156,24 +157,24 @@ public: */ HYDRODATA_EXPORT int TrsfMode() const; - /** - * Appends reference to other object (image or polyline). - * \param theReferenced the object referenced by this - */ - HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Object)& theReferenced ); - /** * Returns the number of referenced objects * \return zero if there is no references */ HYDRODATA_EXPORT int NbReferences() const; + /** + * Appends reference to other object (image or polyline). + * \param theReferenced the object referenced by this + */ + HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced ); + /** * Returns reference by index. * \param theIndex number of reference [0; NbReference) * \returns the referenced object, or Null if index is invalid */ - HYDRODATA_EXPORT Handle(HYDROData_Object) Reference(const int theIndex) const; + HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const; /** * Updates reference by index. If index is one-bigger than \a NbReferences, @@ -182,7 +183,7 @@ public: * \param theReferenced the object referenced by this */ HYDRODATA_EXPORT void ChangeReference( - const int theIndex, Handle(HYDROData_Object) theReferenced); + const int theIndex, Handle(HYDROData_Entity) theReferenced); /** * Removes reference by index diff --git a/src/HYDROData/HYDROData_ImmersibleZone.cxx b/src/HYDROData/HYDROData_ImmersibleZone.cxx new file mode 100644 index 00000000..62e34e52 --- /dev/null +++ b/src/HYDROData/HYDROData_ImmersibleZone.cxx @@ -0,0 +1,159 @@ + +#include "HYDROData_ImmersibleZone.h" + +#include "HYDROData_Bathymetry.h" +#include "HYDROData_Document.h" +#include "HYDROData_Polyline.h" + +#include + +#include +#include +#include + +#include +#include + +#define PYTHON_IMMERSIBLE_ZONE_ID "KIND_IMMERSIBLE_ZONE" + +IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject) + + +HYDROData_ImmersibleZone::HYDROData_ImmersibleZone() +: HYDROData_NaturalObject() +{ +} + +HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone() +{ +} + +QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList; + + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); + if ( aDocument.IsNull() ) + return aResList; + + QString aDocName = aDocument->GetDocPyName(); + QString aZoneName = GetName(); + + aResList << QString( "%1 = %2.CreateObject( %3 );" ) + .arg( aZoneName ).arg( aDocName ).arg( PYTHON_IMMERSIBLE_ZONE_ID ); + aResList << QString( "%1.SetName( \"%2\" );" ) + .arg( aZoneName ).arg( aZoneName ); + aResList << QString( "" ); + + QColor aFillingColor = GetFillingColor(); + aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" ) + .arg( aFillingColor.red() ).arg( aFillingColor.green() ) + .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() ); + aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName ); + aResList << QString( "" ); + + QColor aBorderColor = GetBorderColor(); + aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" ) + .arg( aBorderColor.red() ).arg( aBorderColor.green() ) + .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() ); + aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName ); + aResList << QString( "" ); + + aResList << QString( "" ); + + Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry(); + setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetBathymetry" ); + + Handle(HYDROData_Polyline) aRefPolyline = GetPolyline(); + setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" ); + + return aResList; +} + +TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const +{ + Handle(HYDROData_Polyline) aPolyline = GetPolyline(); + if( !aPolyline.IsNull() ) + { + TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() ); + if( !aPolylineWire.IsNull() ) + { + BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) + return aMakeFace.Face(); + } + } + return TopoDS_Face(); +} + +TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const +{ + // TODO + return getTopShape(); +} + +QColor HYDROData_ImmersibleZone::DefaultFillingColor() +{ + return QColor( Qt::green ); +} + +void HYDROData_ImmersibleZone::SetFillingColor( const QColor& theColor ) +{ + return SetColor( theColor, DataTag_FillingColor ); +} + +QColor HYDROData_ImmersibleZone::GetFillingColor() const +{ + return GetColor( DefaultFillingColor(), DataTag_FillingColor ); +} + +QColor HYDROData_ImmersibleZone::DefaultBorderColor() +{ + return QColor( Qt::transparent ); +} + +void HYDROData_ImmersibleZone::SetBorderColor( const QColor& theColor ) +{ + return SetColor( theColor, DataTag_BorderColor ); +} + +QColor HYDROData_ImmersibleZone::GetBorderColor() const +{ + return GetColor( DefaultBorderColor(), DataTag_BorderColor ); +} + +void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline ) +{ + SetReferenceObject( thePolyline, DataTag_Polyline ); +} + +Handle(HYDROData_Polyline) HYDROData_ImmersibleZone::GetPolyline() const +{ + return Handle(HYDROData_Polyline)::DownCast( + GetReferenceObject( DataTag_Polyline ) ); +} + +void HYDROData_ImmersibleZone::RemovePolyline() +{ + ClearReferenceObjects( DataTag_Polyline ); +} + +void HYDROData_ImmersibleZone::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ) +{ + SetReferenceObject( theBathymetry, DataTag_Bathymetry ); +} + +Handle(HYDROData_Bathymetry) HYDROData_ImmersibleZone::GetBathymetry() const +{ + return Handle(HYDROData_Bathymetry)::DownCast( + GetReferenceObject( DataTag_Bathymetry ) ); +} + +void HYDROData_ImmersibleZone::RemoveBathymetry() +{ + ClearReferenceObjects( DataTag_Bathymetry ); +} + + diff --git a/src/HYDROData/HYDROData_ImmersibleZone.h b/src/HYDROData/HYDROData_ImmersibleZone.h new file mode 100644 index 00000000..883b2fd1 --- /dev/null +++ b/src/HYDROData/HYDROData_ImmersibleZone.h @@ -0,0 +1,134 @@ + +#ifndef HYDROData_ImmersibleZone_HeaderFile +#define HYDROData_ImmersibleZone_HeaderFile + +#include + +DEFINE_STANDARD_HANDLE(HYDROData_ImmersibleZone, HYDROData_NaturalObject) + +class Handle(HYDROData_Bathymetry); +class Handle(HYDROData_Polyline); + +/**\class HYDROData_ImmersibleZone + * \brief + * + */ +class HYDROData_ImmersibleZone : public HYDROData_NaturalObject +{ +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_NaturalObject::DataTag_First + 100, ///< first tag, to reserve + DataTag_FillingColor, ///< filling color of immersible zone + DataTag_BorderColor, ///< border color of immersible zone + DataTag_Polyline, ///< reference polyline + DataTag_Bathymetry, ///< reference bathymetry +}; + +public: + DEFINE_STANDARD_RTTI(HYDROData_ImmersibleZone); + + /** + * Returns the kind of this object. Must be redefined in all objects of known type. + */ + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMMERSIBLE_ZONE;} + + /** + * Dump object to Python script representation. + */ + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + + /** + * Returns the top shape of the object. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape GetTopShape() const; + + /** + * Returns the 3d shape of the object. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const; + + + /** + * Returns default filling color for new zone. + */ + HYDRODATA_EXPORT static QColor DefaultFillingColor(); + + /** + * Sets filling color for zone. + */ + HYDRODATA_EXPORT virtual void SetFillingColor( const QColor& theColor ); + + /** + * Returns filling color of zone. + */ + HYDRODATA_EXPORT virtual QColor GetFillingColor() const; + + + /** + * Returns default border color for new zone. + */ + HYDRODATA_EXPORT static QColor DefaultBorderColor(); + + /** + * Sets border color for zone. + */ + HYDRODATA_EXPORT virtual void SetBorderColor( const QColor& theColor ); + + /** + * Returns border color of zone. + */ + HYDRODATA_EXPORT virtual QColor GetBorderColor() const; + + + /** + * Sets reference polyline object for zone. + */ + HYDRODATA_EXPORT virtual void SetPolyline( const Handle(HYDROData_Polyline)& thePolyline ); + + /** + * Returns reference polyline object of zone. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline) GetPolyline() const; + + /** + * Remove reference polyline object of zone. + */ + HYDRODATA_EXPORT virtual void RemovePolyline(); + + + /** + * Set reference bathymetry object for zone. + */ + HYDRODATA_EXPORT virtual void SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ); + + /** + * Returns reference bathymetry object of zone. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_Bathymetry) GetBathymetry() const; + + /** + * Clear the bathymetry object for zone. + */ + HYDRODATA_EXPORT virtual void RemoveBathymetry(); + +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_ImmersibleZone(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual HYDRODATA_EXPORT ~HYDROData_ImmersibleZone(); +}; + +#endif diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index 254c530a..04ad41dd 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -1,14 +1,18 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include "HYDROData_Iterator.h" + +#include "HYDROData_Bathymetry.h" +#include "HYDROData_Calculation.h" +#include "HYDROData_Image.h" +#include "HYDROData_ImmersibleZone.h" +#include "HYDROData_Polyline.h" +#include "HYDROData_VisualState.h" +#include "HYDROData_Region.h" +#include "HYDROData_Zone.h" #include +#include + #include //! Returns label by root objects kind and the kind of the object @@ -28,7 +32,7 @@ void HYDROData_Iterator::Next() { myIter.Next(); // omit the properties iteration in case of UNKNOWN kind filtering - while(myIter.More() && myIter.Value()->Label().Depth() != 4) + while ( myIter.More() && myIter.Value()->Label().Depth() < 4 ) myIter.Next(); } @@ -37,49 +41,77 @@ bool HYDROData_Iterator::More() const return myIter.More(); } -Handle(HYDROData_Object) HYDROData_Iterator::Current() +Handle(HYDROData_Entity) HYDROData_Iterator::Current() { return Object(myIter.Value()->Label()); } -Handle_HYDROData_Object HYDROData_Iterator::CreateObject( - Handle(HYDROData_Document) theDoc, ObjectKind theKind) +Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( + const Handle(HYDROData_Document)& theDoc, + const ObjectKind& theObjectKind ) +{ + TDF_Label aNewLab = + GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() ); + return CreateObject( aNewLab, theObjectKind ); +} + +Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel, + const ObjectKind& theObjectKind ) { - TDF_Label aNewLab = GetLabelByKind(theDoc->LabelOfObjects(), theKind). - FindChild(theDoc->NewID()); - // object exists if there is name attribute - TDataStd_Name::Set(aNewLab, TCollection_ExtendedString("")); - return Object(aNewLab); + // Object exists if there is a name attribute + TDataStd_Name::Set( theNewLabel, "" ); + + // Store the type of object in data label + TDataStd_NamedData::Set( theNewLabel ); + + Handle(TDataStd_NamedData) aNamedData; + theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ); + aNamedData->SetInteger( "ObjectKind", theObjectKind ); + + return Object( theNewLabel ); } -Handle_HYDROData_Object HYDROData_Iterator::Object( const TDF_Label theLabel ) +Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label theLabel ) { - ObjectKind aKind = theLabel.Father().Tag(); + ObjectKind aKind = KIND_UNKNOWN; + + // Retrieve the type of object from label + Handle(TDataStd_NamedData) aNamedData; + if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) ) + aKind = aNamedData->GetInteger( "ObjectKind" ); + + if ( aKind == KIND_UNKNOWN ) + aKind = theLabel.Father().Tag(); // Try to get type from father label - Handle(HYDROData_Object) aResult; + Handle(HYDROData_Entity) aResult; switch( aKind ) { - case KIND_IMAGE: - aResult = new HYDROData_Image(); - break; - case KIND_POLYLINE: - aResult = new HYDROData_Polyline(); - break; - case KIND_VISUAL_STATE: - aResult = new HYDROData_VisualState(); - break; - case KIND_BATHYMETRY: - aResult = new HYDROData_Bathymetry(); - break; - case KIND_CALCULATION: - aResult = new HYDROData_Calculation(); - break; - case KIND_ZONE: - aResult = new HYDROData_Zone(); - break; - case KIND_REGION: - aResult = new HYDROData_Region(); - break; + case KIND_IMAGE: + aResult = new HYDROData_Image(); + break; + case KIND_POLYLINE: + aResult = new HYDROData_Polyline(); + break; + case KIND_BATHYMETRY: + aResult = new HYDROData_Bathymetry(); + break; + case KIND_IMMERSIBLE_ZONE: + aResult = new HYDROData_ImmersibleZone(); + break; + case KIND_CALCULATION: + aResult = new HYDROData_Calculation(); + 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; + default: + break; } if ( !aResult.IsNull() ) diff --git a/src/HYDROData/HYDROData_Iterator.h b/src/HYDROData/HYDROData_Iterator.h index 746366a6..64728dd2 100644 --- a/src/HYDROData/HYDROData_Iterator.h +++ b/src/HYDROData/HYDROData_Iterator.h @@ -1,8 +1,8 @@ + #ifndef HYDROData_Iterator_HeaderFile #define HYDROData_Iterator_HeaderFile -#include -#include +#include "HYDROData_Document.h" #include @@ -37,12 +37,22 @@ public: /** * Returns the current object of the iterator. */ - HYDRODATA_EXPORT Handle(HYDROData_Object) Current(); + HYDRODATA_EXPORT Handle(HYDROData_Entity) Current(); + +public: + + /** + * Creates object in the document on the given label + * \param theDoc document where object will be located + * \param theKind kind of the new object, can not be UNKNOWN + */ + static Handle(HYDROData_Entity) CreateObject( TDF_Label& theNewLabel, + const ObjectKind& theObjectKind ); protected: friend class HYDROData_Document; - friend class HYDROData_Object; + friend class HYDROData_Entity; /** * Creates object in the document, call HYDROData_Document method to create @@ -50,13 +60,14 @@ protected: * \param theDoc document where object will be located * \param theKind kind of the new object, can not be UNKNOWN */ - static Handle_HYDROData_Object CreateObject( - Handle_HYDROData_Document theDoc, ObjectKind theKind); + static Handle(HYDROData_Entity) CreateObject( + const Handle(HYDROData_Document)& theDoc, + const ObjectKind& theObjectKind ); /** * Returns object associated to the given label. */ - static Handle_HYDROData_Object Object(const TDF_Label theLabel); + static Handle(HYDROData_Entity) Object(const TDF_Label theLabel); TDF_ChildIDIterator myIter; ///< iterator by the objects in the document }; diff --git a/src/HYDROData/HYDROData_NaturalObject.cxx b/src/HYDROData/HYDROData_NaturalObject.cxx new file mode 100644 index 00000000..8b482a73 --- /dev/null +++ b/src/HYDROData/HYDROData_NaturalObject.cxx @@ -0,0 +1,16 @@ + +#include "HYDROData_NaturalObject.h" + +IMPLEMENT_STANDARD_HANDLE(HYDROData_NaturalObject,HYDROData_Object) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_NaturalObject,HYDROData_Object) + +HYDROData_NaturalObject::HYDROData_NaturalObject() +: HYDROData_Object() +{ +} + +HYDROData_NaturalObject::~HYDROData_NaturalObject() +{ +} + + diff --git a/src/HYDROData/HYDROData_NaturalObject.h b/src/HYDROData/HYDROData_NaturalObject.h new file mode 100644 index 00000000..79711800 --- /dev/null +++ b/src/HYDROData/HYDROData_NaturalObject.h @@ -0,0 +1,42 @@ + +#ifndef HYDROData_NaturalObject_HeaderFile +#define HYDROData_NaturalObject_HeaderFile + +#include + +DEFINE_STANDARD_HANDLE(HYDROData_NaturalObject, HYDROData_Object) + + +/**\class HYDROData_NaturalObject + * \brief The natural objects are objects of environment not created by human. + * + */ +class HYDROData_NaturalObject : public HYDROData_Object +{ +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_Object::DataTag_First + 100 ///< first tag, to reserve + }; + +public: + DEFINE_STANDARD_RTTI(HYDROData_NaturalObject); + +protected: + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDRODATA_EXPORT HYDROData_NaturalObject(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual HYDRODATA_EXPORT ~HYDROData_NaturalObject(); +}; + +#endif diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index 2ee9bd7e..ee54ec62 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -1,74 +1,16 @@ #include "HYDROData_Object.h" -#include "HYDROData_Iterator.h" +#include +#include -#include -#include -#include -#include -#include -#include -#include +#include -#include -#include - -#include -#include -#include -#include - -IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared) - -// is equal function for unique object mapping -bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2) -{ - return (theObj1->ID() == theObj2->ID()); -} - -QString HYDROData_Object::GetName() const -{ - Handle(TDataStd_Name) aName; - if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) { - TCollection_AsciiString aStr(aName->Get()); - return QString(aStr.ToCString()); - } - return QString(); -} - -void HYDROData_Object::SetName(const QString& theName) -{ - TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); -} - -QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const -{ - QStringList anEmptyList; - return anEmptyList; -} - -void HYDROData_Object::Update( const bool theIsForce ) -{ -} - -QVariant HYDROData_Object::GetDataVariant() -{ - return QVariant(); -} - -bool HYDROData_Object::IsRemoved() const -{ - return !myLab.HasAttribute(); -} - -void HYDROData_Object::Remove() -{ - return myLab.ForgetAllAttributes(Standard_True); -} +IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity) HYDROData_Object::HYDROData_Object() +: HYDROData_Entity() { } @@ -76,271 +18,31 @@ HYDROData_Object::~HYDROData_Object() { } -void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const -{ - TDF_CopyLabel aCopy(myLab, theDestination->Label()); - aCopy.Perform(); -} - -void HYDROData_Object::SetLabel(TDF_Label theLabel) -{ - myLab = theLabel; -} - -void HYDROData_Object::SaveByteArray(const int theTag, - const char* theData, const int theLen) -{ - TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag); - // array is empty, remove the attribute - if (theLen <= 0) { - aLab.ForgetAttribute(TDataStd_ByteArray::GetID()); - return; - } - // store data of image in byte array - Handle(TDataStd_ByteArray) aData; - if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) { - aData = TDataStd_ByteArray::Set(aLab, 1, theLen); - } - // copy bytes one by one - if (aData->Length() != theLen) { - Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen); - for(int a = 0; a < theLen; a++) - aNewData->SetValue(a + 1, theData[a]); - aData->ChangeArray(aNewData); - } else { - for(int a = 0; a < theLen; a++) - aData->SetValue(a + 1, theData[a]); - } -} - -const char* HYDROData_Object::ByteArray(const int theTag, int& theLen) const -{ - TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag); - Handle(TDataStd_ByteArray) aData; - if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) - return NULL; // return empty image if there is no array - theLen = aData->Length(); - if (theLen) - return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1))); - return NULL; -} - -int HYDROData_Object::NbReferenceObjects( const int theTag ) const +void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape ) { - Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); - return aRefs.IsNull() ? 0 : aRefs->Extent(); + TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) ); + aBuilder.Generated( theShape ); } -void HYDROData_Object::AddReferenceObject( const Handle_HYDROData_Object& theObj, - const int theTag ) +void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape ) { - if ( theObj.IsNull() ) - return; - - Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true ); - aRefs->Append( theObj->Label() ); + TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) ); + aBuilder.Generated( theShape ); } -void HYDROData_Object::SetReferenceObject( const Handle_HYDROData_Object& theObj, - const int theTag, - const int theIndex ) +TopoDS_Shape HYDROData_Object::getTopShape() const { - if ( theObj.IsNull() ) - { - RemoveReferenceObject( theTag, theIndex ); - return; - } - - Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true ); - - if ( theIndex >= aRefs->Extent() ) - { - aRefs->Append( theObj->Label() ); - } - else if ( theIndex < 0 ) - { - aRefs->Prepend( theObj->Label() ); - } - else - { - RemoveReferenceObject( theTag, theIndex ); - - Handle(HYDROData_Object) aBeforeObj = GetReferenceObject( theTag, theIndex ); - - aRefs = getReferenceList( theTag, true ); // because reference list can be removed - if ( !aBeforeObj.IsNull() ) - aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() ); - else - aRefs->Append( theObj->Label() ); - } + Handle(TNaming_NamedShape) aNamedShape; + if( myLab.FindChild( DataTag_TopShape ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) + return aNamedShape->Get(); + return TopoDS_Shape(); } -void HYDROData_Object::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects, - const int theTag ) +TopoDS_Shape HYDROData_Object::getShape3D() const { - ClearReferenceObjects( theTag ); - if ( theObjects.IsEmpty() ) - return; - - HYDROData_SequenceOfObjects::Iterator anIter( theObjects ); - for ( ; anIter.More(); anIter.Next() ) - AddReferenceObject( anIter.Value(), theTag ); + Handle(TNaming_NamedShape) aNamedShape; + if( myLab.FindChild( DataTag_Shape3D ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) + return aNamedShape->Get(); + return TopoDS_Shape(); } -Handle(HYDROData_Object) HYDROData_Object::GetReferenceObject( const int theTag, - const int theIndex ) const -{ - Handle(HYDROData_Object) aRes; - - Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); - if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() ) - return aRes; - - TDF_ListIteratorOfLabelList anIter( aRefs->List() ); - for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex ); - - const TDF_Label& aRefLabel = anIter.Value(); - aRes = HYDROData_Iterator::Object( aRefLabel ); - - return aRes; -} - -HYDROData_SequenceOfObjects HYDROData_Object::GetReferenceObjects( const int theTag ) const -{ - HYDROData_SequenceOfObjects aRes; - - Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); - if ( aRefs.IsNull() ) - return aRes; - - TDF_ListIteratorOfLabelList anIter( aRefs->List() ); - for ( ; anIter.More(); anIter.Next() ) - { - const TDF_Label& aRefLabel = anIter.Value(); - - Handle(HYDROData_Object) aRefObject = HYDROData_Iterator::Object( aRefLabel ); - if ( aRefObject.IsNull() ) - continue; - - aRes.Append( aRefObject ); - } - - return aRes; -} - -void HYDROData_Object::RemoveReferenceObject( const int theTag, - const int theIndex ) -{ - Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); - if ( aRefs.IsNull() ) - return; - - if ( aRefs->Extent() == 1 && theIndex == 0 ) - { - // remove all if only one - ClearReferenceObjects( theTag ); - return; - } - - int anIndex = 0; - TDF_ListIteratorOfLabelList anIter( aRefs->List() ); - for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex ); - - if ( anIndex != theIndex ) - return; - - const TDF_Label& aRefLabel = anIter.Value(); - aRefs->Remove( aRefLabel ); -} - -void HYDROData_Object::ClearReferenceObjects( const int theTag ) -{ - TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); - aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() ); -} - -Handle(TDataStd_ReferenceList) HYDROData_Object::getReferenceList( const int theTag, - const bool theIsCreate ) const -{ - TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); - - Handle(TDataStd_ReferenceList) aRefs; - if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate ) - aRefs = TDataStd_ReferenceList::Set( aLabel ); - - return aRefs; -} - -void HYDROData_Object::SetColor( const QColor& theColor, - const int theTag ) -{ - TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); - - Handle(TDataStd_IntegerArray) aColorArray; - if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) - aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 ); - - aColorArray->SetValue( 1, theColor.red() ); - aColorArray->SetValue( 2, theColor.green() ); - aColorArray->SetValue( 3, theColor.blue() ); - aColorArray->SetValue( 4, theColor.alpha() ); -} - -QColor HYDROData_Object::GetColor( const QColor& theDefColor, - const int theTag ) const -{ - QColor aResColor = theDefColor; - - TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); - - Handle(TDataStd_IntegerArray) aColorArray; - if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) - { - aResColor.setRed( aColorArray->Value( 1 ) ); - aResColor.setGreen( aColorArray->Value( 2 ) ); - aResColor.setBlue( aColorArray->Value( 3 ) ); - aResColor.setAlpha( aColorArray->Value( 4 ) ); - } - - return aResColor; -} - -void HYDROData_Object::setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, - QStringList& theScript, - const Handle(HYDROData_Object)& theRefObject, - const QString& theMethod ) const -{ - if ( theRefObject.IsNull() ) - return; - - QString aRefObjName = theRefObject->GetName(); - if ( aRefObjName.isEmpty() ) - return; - - bool anIsToSetObject = true; - - // The definition of reference polyline must be dumped before this - if ( !theTreatedObjects.contains( aRefObjName ) ) - { - // Write definition of reference polyline - QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects ); - if ( ( anIsToSetObject = !aRefObjDump.isEmpty() ) ) - { - QStringList aTmpList = theScript; - theScript = aRefObjDump; - - theScript << QString( "" ); - theScript << aTmpList; - - theTreatedObjects.insert( aRefObjName, theRefObject ); - } - } - - if ( anIsToSetObject ) - { - theScript << QString( "%1.%2( %3 );" ) - .arg( GetName() ).arg( theMethod ).arg( aRefObjName ); - } -} - - diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index e8669db7..805b593f 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -1,50 +1,19 @@ + #ifndef HYDROData_Object_HeaderFile #define HYDROData_Object_HeaderFile -#include - -#include -#include -#include - -class QColor; -class QString; -class QVariant; -class QStringList; -class Handle(TDataStd_ReferenceList); -class Handle_HYDROData_Object; - -///! Kind of an object in a document -typedef int ObjectKind; -///! Unrecognized object -const ObjectKind KIND_UNKNOWN = 0; -const ObjectKind KIND_IMAGE = 1; -const ObjectKind KIND_POLYLINE = 2; -const ObjectKind KIND_VISUAL_STATE = 3; -const ObjectKind KIND_BATHYMETRY = 4; -const ObjectKind KIND_CALCULATION = 5; -const ObjectKind KIND_PROFILE = 6; -const ObjectKind KIND_PROFILES_GROUP = 7; -const ObjectKind KIND_GUIDE_LINE = 8; -const ObjectKind KIND_ZONE = 9; -const ObjectKind KIND_REGION = 10; -const ObjectKind KIND_LAST = KIND_REGION; - -DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared) +#include -typedef QMap MapOfTreatedObjects; +class TopoDS_Shape; -typedef NCollection_Sequence HYDROData_SequenceOfObjects; +DEFINE_STANDARD_HANDLE(HYDROData_Object, HYDROData_Entity) /**\class HYDROData_Object - * \brief Generic class of any object in the data model. + * \brief The base class for all geometrical objects in the HYDRO module. * - * Interface for getting access to the object that belong to the data model. - * Managed by Document. Provides access to the common properties: - * kind of an object, name. */ -class HYDROData_Object : public MMgt_TShared +class HYDROData_Object : public HYDROData_Entity { protected: /** @@ -52,81 +21,44 @@ protected: */ enum DataTag { - DataTag_First = 0 ///< first tag, to reserve - // ... + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + DataTag_TopShape, + DataTag_Shape3D, }; -public: - DEFINE_STANDARD_RTTI(HYDROData_Object); - - /** - * Returns the kind of this object. Must be redefined in all objects of known type. - */ - HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_UNKNOWN;} - - /** - * Returns the name of this object. - */ - HYDRODATA_EXPORT QString GetName() const; - /** - * Updates the name of this object. + * Enumeration of tags corresponding to the child sub-objects of object. */ - HYDRODATA_EXPORT void SetName(const QString& theName); - - /** - * Dump object to Python script representation. - * Base implementation returns empty list, - * You should reimplement this function in your derived class if it - * has Python API and can be imported/exported from/to Python script. - */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; - - /** - * Updates object state. - * Base implementation dose nothing. - * \param theIsForce force reupdating of data object - */ - HYDRODATA_EXPORT virtual void Update( const bool theIsForce = true ); - - /** - * Returns data of object wrapped to QVariant. - * Base implementation returns null value. - */ - HYDRODATA_EXPORT virtual QVariant GetDataVariant(); + enum ChildTag + { + ChildTag_First = HYDROData_Entity::ChildTag_First + 100, ///< first tag, to reserve + }; - /** - * Checks is object exists in the data structure. - * \returns true is object is not exists in the data model - */ - HYDRODATA_EXPORT bool IsRemoved() const; +public: + DEFINE_STANDARD_RTTI(HYDROData_Object); /** - * Removes object from the data structure. + * Sets the top(2d projection) shape of the object. */ - HYDRODATA_EXPORT void Remove(); + HYDRODATA_EXPORT virtual void SetTopShape( const TopoDS_Shape& theShape ); /** - * Returns unique integer identifier of the object (may be used for ordering of objects) + * Returns the top shape of the object. */ - HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();} + HYDRODATA_EXPORT virtual TopoDS_Shape GetTopShape() const = 0; /** - * Copies all properties of this to the destinated object. - * Objects must be the same type. - * \param theDestination initialized object (from any document) - target of copying + * Sets the 3d shape of the object. */ - HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Object theDestination) const; + HYDRODATA_EXPORT virtual void SetShape3D( const TopoDS_Shape& theShape ); /** - * Returns the label of this object. + * Returns the 3d shape of the object. */ - HYDRODATA_EXPORT TDF_Label& Label() {return myLab;} + HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const = 0; protected: - friend class HYDROData_Iterator; - /** * Creates new object in the internal data structure. Use higher level objects * to create objects with real content. @@ -138,124 +70,18 @@ protected: */ virtual HYDRODATA_EXPORT ~HYDROData_Object(); - /** - * Put the object to the label of the document. - * \param theLabel new label of the object - */ - HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel); - - /** - * Internal method that used to store the byte array attribute - * \param theTag tag of a label to store attribute (for 0 this is myLab) - * \param theData pointer to bytes array - * \param theLen number of bytes in byte array that must be stored - */ - void SaveByteArray(const int theTag, const char* theData, const int theLen); - - /** - * Internal method that used to retreive the content of byte array attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - * \param theLen number of bytes in byte array - * \returns pointer to the internal data structure wit harray content, - * or NULL if array size is zero - */ - const char* ByteArray(const int theTag, int& theLen) const; - - /** - * Internal method that used to store the reference object label attribute - * \param theObj pointer to reference object - * \param theTag tag of a label to store attribute (for 0 this is myLab) - */ - int NbReferenceObjects( const int theTag = 0 ) const; - - /** - * Internal method that used to store the reference object label attribute - * \param theObj pointer to reference object - * \param theTag tag of a label to store attribute (for 0 this is myLab) - */ - void AddReferenceObject( const Handle_HYDROData_Object& theObj, - const int theTag = 0 ); - - /** - * Internal method that used to store the reference object label attribute - * \param theObj pointer to reference object - * \param theTag tag of a label to store attribute (for 0 this is myLab) - * \param theIndex index in the list of references - - if more that len then just append it to the end of list - - if less than zero then prepend to the list - - indexing starts from 0 - */ - void SetReferenceObject( const Handle_HYDROData_Object& theObj, - const int theTag = 0, - const int theIndex = 0 ); - - /** - * Internal method that used to store the reference object label attribute - * \param theObjects sequence with pointers to reference objects - * \param theTag tag of a label to store attribute (for 0 this is myLab) - */ - void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects, - const int theTag = 0 ); - - /** - * Internal method that used to retreive the reference object(s) attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - * \param theIndex index in the list of references - * - indexing starts from 0 - * \returns pointer to reference object or NULL if label is not set - */ - Handle_HYDROData_Object GetReferenceObject( const int theTag = 0, - const int theIndex = 0 ) const; - - HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const; - - /** - * Internal method that used to remove the reference object attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - * \param theIndex index in the list of references - * - indexing starts from 0 - */ - void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 ); - - /** - * Internal method that used to clear list of the reference objects attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - */ - void ClearReferenceObjects( const int theTag = 0 ); +protected: /** - * Internal method that used to store the color attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - * \param theColor color to save + * Retrieve the top shape of the object from data label. */ - void SetColor( const QColor& theColor, const int theTag = 0 ); + HYDRODATA_EXPORT TopoDS_Shape getTopShape() const; /** - * Internal method that used to retreive the color attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - * \param theDefColor default color to return if attribute has not been set before + * Retrieve the 3d shape of the object from data label. */ - QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const; + HYDRODATA_EXPORT TopoDS_Shape getShape3D() const; - -protected: - - void setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, - QStringList& theScript, - const Handle(HYDROData_Object)& theRefObject, - const QString& theMethod ) const; -protected: - - Handle(TDataStd_ReferenceList) getReferenceList( const int theTag, - const bool theIsCreate ) const; - - -protected: - /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty. - TDF_Label myLab; ///< label of this object }; -///! Is Equal for HYDROData_Object mapping -HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2); - #endif diff --git a/src/HYDROData/HYDROData_OperationsFactory.cxx b/src/HYDROData/HYDROData_OperationsFactory.cxx new file mode 100644 index 00000000..cd968557 --- /dev/null +++ b/src/HYDROData/HYDROData_OperationsFactory.cxx @@ -0,0 +1,73 @@ +#include + +#include +#include + +#include +#include +#include +#include + +#include + +// global instance +HYDROData_OperationsFactory* FACTORY = 0; + +HYDROData_OperationsFactory* HYDROData_OperationsFactory::Factory() +{ + if (!FACTORY) { + FACTORY = new HYDROData_OperationsFactory; + // default operations + REGISTER_HYDRO_OPERATION(ImageComposer_ColorMaskOperator) + REGISTER_HYDRO_OPERATION(ImageComposer_CropOperator) + REGISTER_HYDRO_OPERATION(ImageComposer_CutOperator) + REGISTER_HYDRO_OPERATION(ImageComposer_FuseOperator) + } + return FACTORY; +} + +void HYDROData_OperationsFactory::Register( + ImageComposer_Operator* theOperator) +{ + if ( !theOperator ) + return; + + FACTORY->myOps[ theOperator->name() ] = theOperator; +} + +HYDROData_OperationsFactory::HYDROData_OperationsFactory() +{ +} + +ImageComposer_Operator* HYDROData_OperationsFactory::Operator( + Handle(HYDROData_Image) theImage ) const +{ + // retreive operator instance by name + ImageComposer_Operator* anOp = Operator( theImage->OperatorName() ); + if ( !anOp ) + return anOp; + + // fill arguments of the operator from theImage + anOp->setBinArgs( theImage->Args() ); + + return anOp; +} + +ImageComposer_Operator* HYDROData_OperationsFactory::Operator(const QString theName) const +{ + return myOps.contains( theName ) ? myOps[ theName ] : NULL; +} + +Handle(HYDROData_Image) HYDROData_OperationsFactory::CreateImage( + Handle(HYDROData_Document) theDoc, const ImageComposer_Operator* theOperator) +{ + // create an object + Handle(HYDROData_Image) anImage = + Handle(HYDROData_Image)::DownCast(theDoc->CreateObject(KIND_IMAGE)); + // get data from operation + if (theOperator) { + anImage->SetOperatorName( theOperator->name() ); + anImage->SetArgs( theOperator->getBinArgs() ); + } + return anImage; +} diff --git a/src/HYDROData/HYDROData_OperationsFactory.h b/src/HYDROData/HYDROData_OperationsFactory.h new file mode 100644 index 00000000..5eae0362 --- /dev/null +++ b/src/HYDROData/HYDROData_OperationsFactory.h @@ -0,0 +1,83 @@ +#ifndef HYDROData_OperationsFactory_HeaderFile +#define HYDROData_OperationsFactory_HeaderFile + +#include +#include +#include + +class ImageComposer_Operator; +class Handle_HYDROData_Document; + +/**\class HYDROData_OperationsFactory + * + * \brief This class provides the unified management of operations on images. + * + * Object is created as one global instance and allows to register and launch + * all registered operations in general way. To register a new operation just + * call REGISTER_HYDRO_OPERATION(operation_name) in some method implementation. + * This macro will call constructor of this operation (it must inherit + * ImageComposer_Operator) and factory will set up arguments and call this + * operator by demand. + */ + +class HYDROData_OperationsFactory +{ +public: + + //! Returns the global factory + HYDRODATA_EXPORT static HYDROData_OperationsFactory* Factory(); + + /** + * Registers the operator by the name, used by REGISTER_HYDRO_OPERATION macro + * \param theOperator new instance of the operator that will be used for + * processing of operation with such kind + */ + HYDRODATA_EXPORT static void Register( + ImageComposer_Operator* theOperator); + + /** + * Creates a new Image object in the data structure by the operator data. + * \param theDoc document where it must be created + * \param theOperator base operator for this Image: will be used in "Update" to recompute the image + * \returns created object related to the data structure + */ + HYDRODATA_EXPORT Handle(HYDROData_Image) CreateImage( + Handle_HYDROData_Document theDoc, const ImageComposer_Operator* theOperator); + + /** + * Returns the operator, initialized by the properties of theImage + * \param theImage data structures object, that contains all arguments + * required for creation of operation + * \returns NULL if operator type is unknown + */ + HYDRODATA_EXPORT ImageComposer_Operator* Operator( + Handle(HYDROData_Image) theImage) const; + + + /** + * Returns the appropriate operator by the name + * \param theName name of the operator, equals to the operation_name constructor + * \returns NULL if operator with such name is not registered yet + */ + HYDRODATA_EXPORT ImageComposer_Operator* Operator(const QString theName) const; + +protected: + + //! Not public constructor that creates only one, global instance of this factory. + HYDROData_OperationsFactory(); + +private: + //! Map that stores all operators, isentified by strings + typedef QMap FactoryOperators; + + FactoryOperators myOps; ///< all operators stored by a factory +}; + +/** + * Macro that is used for registered operators, see C++ of this class to see + * example of hte registration. + */ +#define REGISTER_HYDRO_OPERATION(operation_name) \ + HYDROData_OperationsFactory::Factory()->Register(new operation_name); + +#endif diff --git a/src/HYDROData/HYDROData_Polyline.cxx b/src/HYDROData/HYDROData_Polyline.cxx index e133ee3e..abac653b 100755 --- a/src/HYDROData/HYDROData_Polyline.cxx +++ b/src/HYDROData/HYDROData_Polyline.cxx @@ -1,7 +1,7 @@ #include #include -#include +#include #include @@ -35,6 +35,7 @@ IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline, HYDROData_Object) HYDROData_Polyline::HYDROData_Polyline() +: HYDROData_Object() { } @@ -42,6 +43,18 @@ HYDROData_Polyline::~HYDROData_Polyline() { } +TopoDS_Shape HYDROData_Polyline::GetTopShape() const +{ + // TODO + return getTopShape(); +} + +TopoDS_Shape HYDROData_Polyline::GetShape3D() const +{ + // TODO + return getTopShape(); +} + /** * Dump object to Python script representation. */ @@ -64,13 +77,13 @@ QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObj aResList << QString( "" ); - int aDim = getDimension(); + int aDim = GetDimension(); aResList << QString( "%1.setDimension( %2 );" ) .arg( aPolylineName ).arg( aDim ); // Set polilyne data - PolylineData aPolylineData = getPolylineData(); + PolylineData aPolylineData = GetPolylineData(); if ( !aPolylineData.isEmpty() ) { QString aPolylineDataName = "polyline_data"; @@ -118,7 +131,7 @@ QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObj QVariant HYDROData_Polyline::GetDataVariant() { - QPainterPath aPath = painterPath(); + QPainterPath aPath = GetPainterPath(); QVariant aVarData; aVarData.setValue( aPath ); @@ -126,44 +139,18 @@ QVariant HYDROData_Polyline::GetDataVariant() return aVarData; } -/** - * Return polyline dimension - * \return polyline dimension. 2 or 3 is valid. 0 is invalid. - */ -int HYDROData_Polyline::getDimension() const -{ - Handle(TDataStd_Integer) aDim; - if(!myLab.FindAttribute(TDataStd_Integer::GetID(), aDim)) - return 0; - return aDim->Get(); -} - -/** - * Set polyline dimension. Should be 2 or 3. - * \param theDimension the polyline dimension - */ -void HYDROData_Polyline::setDimension( int theDimension ) -{ - removeAll(); - int aDim=0; - if( theDimension == 2 || theDimension == 3){ - aDim = theDimension; - } - TDataStd_Integer::Set(myLab, aDim); -} - /** * Replace current polyline data by new sections list * \param theSections the sections list */ -void HYDROData_Polyline::setPolylineData( const PolylineData& theSections ) +void HYDROData_Polyline::SetPolylineData( const PolylineData& theSections ) { //Keep dimension - int aDim = getDimension(); + int aDim = GetDimension(); if( aDim == 0 ) return; - removeAll(); - setDimension(aDim); + RemoveAll(); + SetDimension(aDim); if( theSections.size() == 0 ) return; @@ -218,7 +205,7 @@ void HYDROData_Polyline::setPolylineData( const PolylineData& theSections ) * Return polyline data * \return polyline section list */ -HYDROData_Polyline::PolylineData HYDROData_Polyline::getPolylineData() const +HYDROData_Polyline::PolylineData HYDROData_Polyline::GetPolylineData() const { int aSectCnt; PolylineData aRes; @@ -278,10 +265,10 @@ HYDROData_Polyline::PolylineData HYDROData_Polyline::getPolylineData() const /** * Returns true if polyline is closed */ -bool HYDROData_Polyline::isClosed() const +bool HYDROData_Polyline::IsClosed() const { - int aDim = getDimension(); - PolylineData aPolylineData = getPolylineData(); + int aDim = GetDimension(); + PolylineData aPolylineData = GetPolylineData(); if ( aDim == 0 || aPolylineData.isEmpty() ) return false; @@ -297,10 +284,36 @@ bool HYDROData_Polyline::isClosed() const return true; } +/** + * Return polyline dimension + * \return polyline dimension. 2 or 3 is valid. 0 is invalid. + */ +int HYDROData_Polyline::GetDimension() const +{ + Handle(TDataStd_Integer) aDim; + if(!myLab.FindAttribute(TDataStd_Integer::GetID(), aDim)) + return 0; + return aDim->Get(); +} + +/** + * Set polyline dimension. Should be 2 or 3. + * \param theDimension the polyline dimension + */ +void HYDROData_Polyline::SetDimension( int theDimension ) +{ + RemoveAll(); + int aDim=0; + if( theDimension == 2 || theDimension == 3){ + aDim = theDimension; + } + TDataStd_Integer::Set(myLab, aDim); +} + /** * Remove all polyline attributes except dimension. */ -void HYDROData_Polyline::removeAll() +void HYDROData_Polyline::RemoveAll() { //Remove only section data TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize ); @@ -321,14 +334,14 @@ void HYDROData_Polyline::removeAll() * Note: currently only the first section of the polyline data is taken into account. * \return polyline painter path. */ -QPainterPath HYDROData_Polyline::painterPath() const +QPainterPath HYDROData_Polyline::GetPainterPath() const { QPainterPath aPath; - int aDim = getDimension(); + int aDim = GetDimension(); if( aDim != 2 && aDim != 3 ) return aPath; - PolylineData aSects = getPolylineData(); + PolylineData aSects = GetPolylineData(); if( aSects.isEmpty() ) return aPath; @@ -356,7 +369,7 @@ QPainterPath HYDROData_Polyline::painterPath() const int anIndex = i * aDim; aPoints << aSection.myCoords[ anIndex ] << aSection.myCoords[ anIndex + 1 ]; } - HYDROOperations_BSpline aBSpline( aPoints, 0, anIsSectionClosed ); + HYDROData_BSplineOperation aBSpline( aPoints, 0, anIsSectionClosed ); aPath = aBSpline.ComputePath(); } return aPath; @@ -375,25 +388,11 @@ double HYDROData_Polyline::ZValue() const return 0; } -void HYDROData_Polyline::SetWire( const TopoDS_Wire& theWire ) -{ - TNaming_Builder aBuilder( myLab ); - aBuilder.Generated( theWire ); -} - -TopoDS_Wire HYDROData_Polyline::Wire() const -{ - Handle(TNaming_NamedShape) aNamedShape; - if( myLab.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) - return TopoDS::Wire( aNamedShape->Get() ); - return TopoDS_Wire(); -} - void HYDROData_Polyline::UpdateWire( const PolylineData& theSections ) { BRepBuilderAPI_MakeWire aMakeWire; - int aDim = getDimension(); + int aDim = GetDimension(); double aZValue = ZValue(); @@ -439,7 +438,7 @@ void HYDROData_Polyline::UpdateWire( const PolylineData& theSections ) aPoints << x << y; } - HYDROOperations_BSpline aBSpline( aPoints, aZValue, anIsSectionClosed ); + HYDROData_BSplineOperation aBSpline( aPoints, aZValue, anIsSectionClosed ); TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge(); aMakeSectionWire.Add( anEdge ); } @@ -449,5 +448,5 @@ void HYDROData_Polyline::UpdateWire( const PolylineData& theSections ) } TopoDS_Wire aWire = aMakeWire.Wire(); - SetWire( aWire ); + SetTopShape( aWire ); } diff --git a/src/HYDROData/HYDROData_Polyline.h b/src/HYDROData/HYDROData_Polyline.h index b5ce157e..78f8736e 100755 --- a/src/HYDROData/HYDROData_Polyline.h +++ b/src/HYDROData/HYDROData_Polyline.h @@ -48,7 +48,6 @@ protected: DataTag_SectionsClosed, DataTag_SectionsSize, DataTag_SectionsType, - DataTag_Wire, DataTag_ZValue }; @@ -60,6 +59,16 @@ public: */ HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_POLYLINE;} + /** + * Returns the top shape of the object. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape GetTopShape() const; + + /** + * Returns the 3d shape of the object. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const; + /** * Dump object to Python script representation. */ @@ -75,56 +84,47 @@ public: * Replace current polyline data by new sections list * \param theSections the sections list */ - HYDRODATA_EXPORT void setPolylineData( const PolylineData& theSections ); + HYDRODATA_EXPORT void SetPolylineData( const PolylineData& theSections ); /** * Return polyline data * \return polyline section list */ - HYDRODATA_EXPORT PolylineData getPolylineData() const; + HYDRODATA_EXPORT PolylineData GetPolylineData() const; /** * Returns true if polyline is closed */ - HYDRODATA_EXPORT bool isClosed() const; + HYDRODATA_EXPORT bool IsClosed() const; /** * Return polyline dimension * \return polyline dimension (2 or 3) */ - HYDRODATA_EXPORT int getDimension() const; + HYDRODATA_EXPORT int GetDimension() const; /** * Set polyline dimension (2 or 3) * \param theDimension the polyline dimension */ - HYDRODATA_EXPORT void setDimension( int theDimension ); + HYDRODATA_EXPORT void SetDimension( int theDimension ); /** * Remove all sections from polyline */ - HYDRODATA_EXPORT void removeAll(); + HYDRODATA_EXPORT void RemoveAll(); /** * Returns the painter path. * Note: currently only the first section of the polyline data is taken into account. */ - HYDRODATA_EXPORT QPainterPath painterPath() const; + HYDRODATA_EXPORT QPainterPath GetPainterPath() const; - HYDRODATA_EXPORT void SetZValue( const double theZValue ); + HYDRODATA_EXPORT void SetZValue( const double theZValue ); HYDRODATA_EXPORT double ZValue() const; - /** - * Sets the wire contour of the object. - */ - HYDRODATA_EXPORT void SetWire( const TopoDS_Wire& theWire ); - - /** - * Returns the wire contour of the object. - */ - HYDRODATA_EXPORT TopoDS_Wire Wire() const; - protected: + /** * Update the wire contour on the basis of the polyline data. */ diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 16680653..3a1c59ac 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -1,17 +1,16 @@ #include "HYDROData_Region.h" -#include -#include -#include +#include "HYDROData_Document.h" +#include "HYDROData_Iterator.h" +#include "HYDROData_Zone.h" -#include +#include #define PYTHON_REGION_ID "KIND_REGION" - -IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Domain) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Domain) +IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity) HYDROData_Region::HYDROData_Region() @@ -22,24 +21,104 @@ HYDROData_Region::~HYDROData_Region() { } -void HYDROData_Region::SetFace( const TopoDS_Face& theFace ) +QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList; + + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); + if ( aDocument.IsNull() ) + return aResList; + + QString aDocName = aDocument->GetDocPyName(); + QString aRegionName = GetName(); + + aResList << QString( "%1 = %2.CreateObject( %3 );" ) + .arg( aRegionName ).arg( aDocName ).arg( PYTHON_REGION_ID ); + aResList << QString( "%1.SetName( \"%2\" );" ) + .arg( aRegionName ).arg( aRegionName ); + aResList << QString( "" ); + + HYDROData_SequenceOfObjects aZones = GetZones(); + HYDROData_SequenceOfObjects::Iterator anIter( aZones ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Zone) aRefZone = + Handle(HYDROData_Zone)::DownCast( anIter.Value() ); + if ( !aRefZone.IsNull() ) + setPythonReferenceObject( theTreatedObjects, aResList, aRefZone, "AddZone" ); + } + aResList << QString( "" ); + + return aResList; +} + +Handle(HYDROData_Zone) HYDROData_Region::AddNewZone() +{ + TDF_Label aNewLab = myLab.FindChild( ChildTag_Zone ).NewChild(); + + return Handle(HYDROData_Zone)::DownCast( + HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) ); +} + +void HYDROData_Region::RemoveChildZones() +{ + myLab.FindChild( ChildTag_Zone ).ForgetAllAttributes( true ); +} + +int HYDROData_Region::NbZones() const +{ + return NbReferenceObjects( DataTag_Zone ); +} + +void HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone ) { - TNaming_Builder aBuilder( myLab ); - aBuilder.Generated( theFace ); + AddReferenceObject( theZone, DataTag_Zone ); } -TopoDS_Face HYDROData_Region::Face() const +void HYDROData_Region::SetZone( const int theIndex, + const Handle(HYDROData_Zone)& theZone ) { - Handle(TNaming_NamedShape) aNamedShape; - if( myLab.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) - return TopoDS::Face( aNamedShape->Get() ); - return TopoDS_Face(); + SetReferenceObject( theZone, DataTag_Zone, theIndex ); } -QString HYDROData_Region::getPythonKindId() const +void HYDROData_Region::InsertZone( const int theBeforeIndex, + const Handle(HYDROData_Zone)& theZone ) { - return QString( PYTHON_REGION_ID ); + InsertReferenceObject( theZone, DataTag_Zone, theBeforeIndex ); } +void HYDROData_Region::SetZones( const HYDROData_SequenceOfObjects& theZones ) +{ + SetReferenceObjects( theZones, DataTag_Zone ); +} + +Handle(HYDROData_Zone) HYDROData_Region::GetZone( const int theIndex ) const +{ + return Handle(HYDROData_Zone)::DownCast( + GetReferenceObject( DataTag_Zone, theIndex ) ); +} + +HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const +{ + return GetReferenceObjects( DataTag_Zone ); +} + +void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone ) +{ + if ( theZone.IsNull() ) + return; + + RemoveReferenceObject( theZone->Label(), DataTag_Zone ); +} + +void HYDROData_Region::RemoveZone( const int theIndex ) +{ + RemoveReferenceObject( DataTag_Zone, theIndex ); +} + +void HYDROData_Region::RemoveZones() +{ + ClearReferenceObjects( DataTag_Zone ); +} diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index 23cd0d62..1579be6c 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -2,26 +2,37 @@ #ifndef HYDROData_Region_HeaderFile #define HYDROData_Region_HeaderFile -#include +#include "HYDROData_Entity.h" -DEFINE_STANDARD_HANDLE(HYDROData_Region, HYDROData_Domain) +DEFINE_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity) +class Handle(HYDROData_Zone); -/**\class HYDROData_Domain - * \brief Class that stores/retreives information about the 2d surface. +/**\class HYDROData_Region + * \brief Regions are groups (lists) of zones, they can include one or several zones. */ -class HYDROData_Region : public HYDROData_Domain +class HYDROData_Region : public HYDROData_Entity { protected: + /** * Enumeration of tags corresponding to the persistent object parameters. */ enum DataTag { - DataTag_First = HYDROData_Domain::DataTag_First + 100, ///< first tag, to reserve - DataTag_Face + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + DataTag_Zone ///< reference zones + }; + + /** + * Enumeration of tags corresponding to the child sub-objects of object. + */ + enum ChildTag + { + ChildTag_First = HYDROData_Entity::ChildTag_First + 100, ///< first tag, to reserve + ChildTag_Zone ///< child zones }; public: @@ -33,17 +44,79 @@ public: HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_REGION; } /** - * Sets the shape of the object. + * Dump object to Python script representation. + */ + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + + + /** + * Create new one reference zone for region on child label. + * The new zone is not added into the list of reference zones. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) AddNewZone(); + + /** + * Removes all child zones from region. + */ + HYDRODATA_EXPORT virtual void RemoveChildZones(); + + + /** + * Returns number of reference zones of region. + */ + int NbZones() const; + + /** + * Add new one reference zone for region. + */ + HYDRODATA_EXPORT virtual void AddZone( const Handle(HYDROData_Zone)& theZone ); + + /** + * Replace the reference zone for region. */ - HYDRODATA_EXPORT void SetFace( const TopoDS_Face& theFace ); + HYDRODATA_EXPORT virtual void SetZone( const int theIndex, + const Handle(HYDROData_Zone)& theZone ); /** - * Returns the shape of the the object (redefined method). + * Inserts the reference zone for region before given index. */ - HYDRODATA_EXPORT virtual TopoDS_Face Face() const; + HYDRODATA_EXPORT virtual void InsertZone( const int theBeforeIndex, + const Handle(HYDROData_Zone)& theZone ); + + /** + * Sets reference zones for calculation region. + */ + HYDRODATA_EXPORT virtual void SetZones( const HYDROData_SequenceOfObjects& theZones ); + + /** + * Returns reference zone of region by index. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZone( const int theIndex ) const; + + /** + * Returns all reference zone of region. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetZones() const; + + /** + * Removes reference zone from region. + */ + HYDRODATA_EXPORT virtual void RemoveZone( const Handle(HYDROData_Zone)& theZone ); + + /** + * Removes reference zone from region by it index. + */ + HYDRODATA_EXPORT virtual void RemoveZone( const int theIndex ); + + /** + * Removes all reference zones from region. + */ + HYDRODATA_EXPORT virtual void RemoveZones(); + protected: + friend class HYDROData_Calculation; friend class HYDROData_Iterator; /** @@ -56,11 +129,6 @@ protected: * Destructs properties of the object and object itself, removes it from the document. */ ~HYDROData_Region(); - - /** - * Returns id for creation of object in python scripting. - */ - virtual QString getPythonKindId() const; }; #endif diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx new file mode 100644 index 00000000..dfd60b75 --- /dev/null +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -0,0 +1,187 @@ + +#include "HYDROData_SplitToZonesTool.h" + +#include "HYDROData_Object.h" + +#include +#include +#include + +#include +#include +#include +#include + +TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const +{ + TopoDS_Face aResFace; + + if( !Shape.IsNull() ) + { + if ( Shape.ShapeType() == TopAbs_FACE ) + { + aResFace = TopoDS::Face( Shape ); + } + else if ( Shape.ShapeType() == TopAbs_WIRE ) + { + BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( Shape ), Standard_True ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) + aResFace = aMakeFace.Face(); + } + } + + return aResFace; +} + +HYDROData_SplitToZonesTool::SplitDataList +HYDROData_SplitToZonesTool::SplitToZones( const HYDROData_SequenceOfObjects& theObjectList ) +{ + SplitDataList anOutputSplitDataList; + + // Preparation. Collect the object shapes to split. + SplitDataList anInputSplitDataList; + for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Object) aGeomObj = + Handle(HYDROData_Object)::DownCast( theObjectList.Value( anIndex ) ); + if( !aGeomObj.IsNull() ) + { + SplitData aSplitData( aGeomObj->GetTopShape(), aGeomObj->GetName() ); + anInputSplitDataList.append( aSplitData ); + } + } + + // Step 1. Split the paths. + SplitDataListIterator anInputIter( anInputSplitDataList ); + while( anInputIter.hasNext() ) + { + const SplitData& anInputSplitData = anInputIter.next(); + if( anOutputSplitDataList.isEmpty() ) + anOutputSplitDataList.append( anInputSplitData ); + else + { + SplitDataList aSplitDataList; + + SplitDataList aSrcSplitDataList; + aSrcSplitDataList.append( anInputSplitData ); + + SplitDataList aDestSplitDataList = anOutputSplitDataList; + anOutputSplitDataList.clear(); + + while( !aDestSplitDataList.isEmpty() ) + { + SplitData aSrcSplitData = aSrcSplitDataList.last(); + + SplitData aDestSplitData = aDestSplitDataList.first(); + aDestSplitDataList.pop_front(); + + SplitData aData1Subtracted, aData2Subtracted, aDataIntersected; + if( SplitTwoData( aSrcSplitData, aDestSplitData, + aData1Subtracted, aData2Subtracted, aDataIntersected ) ) + anOutputSplitDataList.append( aDataIntersected ); + anOutputSplitDataList.append( aData2Subtracted ); + aSrcSplitDataList.append( aData1Subtracted ); + } + + if( !aSrcSplitDataList.isEmpty() ) + anOutputSplitDataList.append( aSrcSplitDataList.last() ); + } + } + + // Step 2. Take into account the boundary polyline. + /* + if( !thePolyline.IsNull() ) + { + TopoDS_Wire aWire = TopoDS::Wire( thePolyline->GetTopShape() ); + if( !aWire.IsNull() ) + { + BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) + { + SplitData aBoundarySplitData( aMakeFace.Face(), "" ); + + SplitDataList aCutSplitDataList; + SplitDataListIterator anOutputIter( anOutputSplitDataList ); + while( anOutputIter.hasNext() ) + { + const SplitData& anOutputSplitData = anOutputIter.next(); + + SplitData aData1Subtracted, aData2Subtracted, aDataIntersected; + if( SplitTwoData( anOutputSplitData, aBoundarySplitData, + aData1Subtracted, aData2Subtracted, aDataIntersected ) ) + aCutSplitDataList.append( aDataIntersected ); + } + anOutputSplitDataList = aCutSplitDataList; + } + } + } + */ + + // Step 3. Extract the separate regions. + SplitDataList anExtractedSplitDataList; + SplitDataListIterator anOutputIter( anOutputSplitDataList ); + while( anOutputIter.hasNext() ) + { + const SplitData& anOutputSplitData = anOutputIter.next(); + anExtractedSplitDataList.append( ExtractSeparateData( anOutputSplitData ) ); + } + + return anExtractedSplitDataList; +} + +bool HYDROData_SplitToZonesTool::SplitTwoData( const SplitData& theData1, + const SplitData& theData2, + SplitData& theData1Subtracted, + SplitData& theData2Subtracted, + SplitData& theDataIntersected ) +{ + const TopoDS_Shape& aShape1 = theData1.Shape; + const TopoDS_Shape& aShape2 = theData2.Shape; + + const QStringList& anObjectNames1 = theData1.ObjectNames; + const QStringList& anObjectNames2 = theData2.ObjectNames; + + BRepAlgoAPI_Common aCommon( aShape1, aShape2 ); + TopoDS_Shape aCommonShape = aCommon.Shape(); + if( aCommonShape.IsNull() ) + { + theData1Subtracted = theData1; + theData2Subtracted = theData2; + return false; + } + + BRepAlgoAPI_Cut aCut1( aShape1, aShape2 ); + TopoDS_Shape aCut1Shape = aCut1.Shape(); + + BRepAlgoAPI_Cut aCut2( aShape2, aShape1 ); + TopoDS_Shape aCut2Shape = aCut2.Shape(); + + theData1Subtracted = SplitData( aCut1Shape, anObjectNames1 ); + theData2Subtracted = SplitData( aCut2Shape, anObjectNames2 ); + theDataIntersected = SplitData( aCommonShape, anObjectNames1 + anObjectNames2 ); + + return true; +} + +HYDROData_SplitToZonesTool::SplitDataList +HYDROData_SplitToZonesTool::ExtractSeparateData( const SplitData& theData ) +{ + SplitDataList aSplitDataList; + TopExp_Explorer anExp( theData.Shape, TopAbs_FACE ); + for( ; anExp.More(); anExp.Next() ) + { + TopoDS_Shape aShape = anExp.Current(); + if( aShape.ShapeType() == TopAbs_FACE ) + { + TopoDS_Face aFace = TopoDS::Face( aShape ); + if( !aFace.IsNull() ) + { + SplitData aSplitData( aFace, theData.ObjectNames ); + aSplitDataList.append( aSplitData ); + } + } + } + return aSplitDataList; +} diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.h b/src/HYDROData/HYDROData_SplitToZonesTool.h new file mode 100644 index 00000000..dd70ed42 --- /dev/null +++ b/src/HYDROData/HYDROData_SplitToZonesTool.h @@ -0,0 +1,58 @@ + +#ifndef HYDROData_SplitToZonesTool_H +#define HYDROData_SplitToZonesTool_H + +#include + +#include + +#include + +class Handle(HYDROData_Polyline); + +/** + * \class HYDROData_SplitToZonesTool + * \brief This class contains methods used for splitting geometry objects + * into non-intersected regions. + */ +class HYDRODATA_EXPORT HYDROData_SplitToZonesTool +{ +public: + struct HYDRODATA_EXPORT SplitData + { + TopoDS_Shape Shape; + QStringList ObjectNames; + + SplitData() {} + + SplitData( const TopoDS_Shape& theShape, + const QStringList& theObjectNames ) : + Shape( theShape ), ObjectNames( theObjectNames ) {} + + SplitData( const TopoDS_Shape& theShape, + const QString& theObjectNames ) : + Shape( theShape ), ObjectNames( theObjectNames ) {} + + TopoDS_Face Face() const; + }; + + typedef QList SplitDataList; + typedef QListIterator SplitDataListIterator; + +public: + + static SplitDataList SplitToZones( const HYDROData_SequenceOfObjects& theObjectList ); + +private: + + static bool SplitTwoData( const SplitData& theData1, + const SplitData& theData2, + SplitData& theData1Subtracted, + SplitData& theData2Subtracted, + SplitData& theDataIntersected ); + + static SplitDataList ExtractSeparateData( const SplitData& theData ); + +}; + +#endif diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index 58511d16..fda98c61 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -24,7 +24,7 @@ void HYDROData_Tool::WriteStringsToFile( QFile& theFile, } void HYDROData_Tool::SetMustBeUpdatedImages( - Handle_HYDROData_Document theDoc) + const Handle(HYDROData_Document)& theDoc ) { bool aChanged = true; @@ -55,3 +55,90 @@ void HYDROData_Tool::SetMustBeUpdatedImages( } } } + +QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc, + const QString& thePrefix, + const QStringList& theUsedNames ) +{ + QStringList aNamesList( theUsedNames ); + + // Collect all used names in the document + HYDROData_Iterator anIter( theDoc ); + for( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Entity) anObject = anIter.Current(); + if( anObject.IsNull() ) + continue; + + QString anObjName = anObject->GetName(); + if ( anObjName.isEmpty() ) + continue; + + aNamesList.append( anObjName ); + } + + QString aName; + + int anId = 1; + while( anId < 1000 ) + { + aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) ); + + // check that there are no other objects with the same name in the document + if ( !aNamesList.contains( aName ) ) + break; + } + + return aName; +} + +Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc, + const QString& theName, + const ObjectKind theObjectKind ) +{ + Handle(HYDROData_Entity) anObject; + if ( theName.isEmpty() || theDoc.IsNull() ) + return anObject; + + QStringList aNamesList; + aNamesList << theName; + + HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind ); + if( aSeqOfObjs.IsEmpty() ) + return anObject; + + anObject = aSeqOfObjs.First(); + return anObject; +} + +HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc, + const QStringList& theNames, + const ObjectKind theObjectKind ) +{ + HYDROData_SequenceOfObjects aResSeq; + if( theDoc.IsNull() ) + return aResSeq; + + QStringList aNamesList = theNames; + + HYDROData_Iterator anIter( theDoc, theObjectKind ); + for( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Entity) anObject = anIter.Current(); + if( anObject.IsNull() ) + continue; + + QString anObjName = anObject->GetName(); + if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) ) + continue; + + aResSeq.Append( anObject ); + + aNamesList.removeAll( anObjName ); + if ( aNamesList.isEmpty() ) + break; + } + + return aResSeq; +} + diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index 85824d6e..04835c87 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -2,15 +2,18 @@ #ifndef HYDROData_Tool_HeaderFile #define HYDROData_Tool_HeaderFile +#include "HYDROData.h" +#include "HYDROData_Entity.h" + #include #include +#include class QFile; -class QStringList; -class Handle_HYDROData_Document; +class Handle(HYDROData_Document); -class HYDROData_Tool { +class HYDRODATA_EXPORT HYDROData_Tool { public: @@ -22,8 +25,40 @@ public: * Enables "MustBeUpdated" flag for Images that are depended on "MustBeUpdated" images. * \param theDoc document where this operation is performed */ - static void SetMustBeUpdatedImages( Handle_HYDROData_Document theDoc ); + static void SetMustBeUpdatedImages( const Handle(HYDROData_Document)& theDoc ); + /** + * \brief Generate name for new object. + * \param theModule module + * \param thePrefix name prefix + * \param theUsedNames list of already used names + * \return generated name + */ + static QString GenerateObjectName( const Handle(HYDROData_Document)& theDoc, + const QString& thePrefix, + const QStringList& theUsedNames = QStringList() ); + + /** + * \brief Find the data object with the specified name. + * \param theModule module + * \param theName name + * \param theObjectKind kind of object + * \return data object + */ + static Handle(HYDROData_Entity) FindObjectByName( const Handle(HYDROData_Document)& theDoc, + const QString& theName, + const ObjectKind theObjectKind = KIND_UNKNOWN ); + + /** + * \brief Find the data objects with the specified names. + * \param theModule module + * \param theNames list of names + * \param theObjectKind kind of object + * \return list of data objects + */ + static HYDROData_SequenceOfObjects FindObjectsByNames( const Handle(HYDROData_Document)& theDoc, + const QStringList& theNames, + const ObjectKind theObjectKind = KIND_UNKNOWN ); }; inline bool ValuesEquals( const double& theFirst, const double& theSecond ) diff --git a/src/HYDROData/HYDROData_VisualState.cxx b/src/HYDROData/HYDROData_VisualState.cxx index e3e06413..6c081bcf 100644 --- a/src/HYDROData/HYDROData_VisualState.cxx +++ b/src/HYDROData/HYDROData_VisualState.cxx @@ -1,11 +1,13 @@ + #include #include -IMPLEMENT_STANDARD_HANDLE(HYDROData_VisualState, HYDROData_Object) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_VisualState, HYDROData_Object) +IMPLEMENT_STANDARD_HANDLE(HYDROData_VisualState, HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_VisualState, HYDROData_Entity) HYDROData_VisualState::HYDROData_VisualState() +: HYDROData_Entity() { } diff --git a/src/HYDROData/HYDROData_VisualState.h b/src/HYDROData/HYDROData_VisualState.h index 6a53c44c..72b8f2c7 100644 --- a/src/HYDROData/HYDROData_VisualState.h +++ b/src/HYDROData/HYDROData_VisualState.h @@ -1,18 +1,19 @@ + #ifndef HYDROData_VisualState_HeaderFile #define HYDROData_VisualState_HeaderFile -#include +#include #include -DEFINE_STANDARD_HANDLE(HYDROData_VisualState, HYDROData_Object) +DEFINE_STANDARD_HANDLE(HYDROData_VisualState, HYDROData_Entity) /**\class HYDROData_VisualState * \brief Class that stores/retreives information about the visual state. * * Keeps the visual state as encoded text string. */ -class HYDROData_VisualState : public HYDROData_Object +class HYDROData_VisualState : public HYDROData_Entity { protected: /** @@ -20,7 +21,7 @@ protected: */ enum DataTag { - DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve DataTag_State ///< encoded visual state }; diff --git a/src/HYDROData/HYDROData_Zone.cxx b/src/HYDROData/HYDROData_Zone.cxx index 3af90622..36b13d65 100644 --- a/src/HYDROData/HYDROData_Zone.cxx +++ b/src/HYDROData/HYDROData_Zone.cxx @@ -1,24 +1,24 @@ #include "HYDROData_Zone.h" -#include "HYDROData_Bathymetry.h" #include "HYDROData_Document.h" -#include "HYDROData_Polyline.h" -#include "HYDROData_Iterator.h" +#include "HYDROData_Object.h" -#include -#include -#include +#include +#include + +#include -#include #include #define PYTHON_ZONE_ID "KIND_ZONE" -IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Domain) -IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Domain) +IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity) + HYDROData_Zone::HYDROData_Zone() +: HYDROData_Entity() { } @@ -28,55 +28,88 @@ HYDROData_Zone::~HYDROData_Zone() QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const { - QStringList aResList = HYDROData_Domain::DumpToPython( theTreatedObjects ); - if ( aResList.isEmpty() ) + QStringList aResList; + + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); + if ( aDocument.IsNull() ) return aResList; + QString aDocName = aDocument->GetDocPyName(); + QString aZoneName = GetName(); + + aResList << QString( "%1 = %2.CreateObject( %3 );" ) + .arg( aZoneName ).arg( aDocName ).arg( PYTHON_ZONE_ID ); + aResList << QString( "%1.SetName( \"%2\" );" ) + .arg( aZoneName ).arg( aZoneName ); aResList << QString( "" ); - Handle(HYDROData_Polyline) aRefPolyline = GetPolyline(); - setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" ); + HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects ); + for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() ) + { + Handle(HYDROData_Object) aRefGeomObj = + Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() ); + if ( !aRefGeomObj.IsNull() ) + setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" ); + } + + // How can we get the shape? Mb Update() method to intersect the shapes of reference objects? + // TODO: TopoDS_Shape aRefShape = GetShape(); return aResList; } -void HYDROData_Zone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline ) +void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape ) { - SetReferenceObject( thePolyline, DataTag_Polyline ); + TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) ); + aBuilder.Generated( theShape ); } -Handle(HYDROData_Polyline) HYDROData_Zone::GetPolyline() const +TopoDS_Shape HYDROData_Zone::GetShape() const { - return Handle(HYDROData_Polyline)::DownCast( - GetReferenceObject( DataTag_Polyline ) ); + Handle(TNaming_NamedShape) aNamedShape; + if( myLab.FindChild( DataTag_Shape ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) + return aNamedShape->Get(); + return TopoDS_Shape(); } -void HYDROData_Zone::RemovePolyline() +int HYDROData_Zone::NbGeometryObjects() const { - ClearReferenceObjects( DataTag_Polyline ); + return NbReferenceObjects( DataTag_GeometryObject ); } -TopoDS_Face HYDROData_Zone::Face() const +void HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject ) { - Handle(HYDROData_Polyline) aPolyline = GetPolyline(); - if( !aPolyline.IsNull() ) - { - TopoDS_Wire aWire = aPolyline->Wire(); - if( !aWire.IsNull() ) - { - BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True ); - aMakeFace.Build(); - if( aMakeFace.IsDone() ) - return aMakeFace.Face(); - } - } - return TopoDS_Face(); + AddReferenceObject( theObject, DataTag_GeometryObject ); +} + +void HYDROData_Zone::SetGeometryObject( const int theIndex, + const Handle(HYDROData_Object)& theObject ) +{ + SetReferenceObject( theObject, DataTag_GeometryObject, theIndex ); +} + +void HYDROData_Zone::SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ) +{ + SetReferenceObjects( theObjects, DataTag_GeometryObject ); } -QString HYDROData_Zone::getPythonKindId() const +Handle(HYDROData_Object) HYDROData_Zone::GetGeometryObject( const int theIndex ) const { - return QString( PYTHON_ZONE_ID ); + return Handle(HYDROData_Object)::DownCast( + GetReferenceObject( DataTag_GeometryObject, theIndex ) ); } +HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const +{ + return GetReferenceObjects( DataTag_GeometryObject ); +} + +void HYDROData_Zone::RemoveGeometryObjects() +{ + ClearReferenceObjects( DataTag_GeometryObject ); +} + + diff --git a/src/HYDROData/HYDROData_Zone.h b/src/HYDROData/HYDROData_Zone.h index b9a86cbf..4ef2dd9c 100644 --- a/src/HYDROData/HYDROData_Zone.h +++ b/src/HYDROData/HYDROData_Zone.h @@ -2,17 +2,18 @@ #ifndef HYDROData_Zone_HeaderFile #define HYDROData_Zone_HeaderFile -#include +#include -class Handle(HYDROData_Polyline); +class Handle(HYDROData_Object); +class TopoDS_Shape; -DEFINE_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Domain) +DEFINE_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity) /**\class HYDROData_Zone * \brief Class that stores/retreives information about the 2d face. */ -class HYDROData_Zone : public HYDROData_Domain +class HYDROData_Zone : public HYDROData_Entity { protected: @@ -21,8 +22,9 @@ protected: */ enum DataTag { - DataTag_First = HYDROData_Domain::DataTag_First + 100, ///< first tag, to reserve - DataTag_Polyline, ///< reference polyline + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + DataTag_Shape, ///< reference shape + DataTag_GeometryObject, ///< reference geometry objects }; public: @@ -40,34 +42,56 @@ public: /** - * Sets reference polyline object for zone. + * Sets the shape of the zone. */ - HYDRODATA_EXPORT virtual void SetPolyline( const Handle(HYDROData_Polyline)& thePolyline ); + HYDRODATA_EXPORT virtual void SetShape( const TopoDS_Shape& theShape ); /** - * Returns reference polyline object of zone. + * Returns the shape of the zone. */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline) GetPolyline() const; + HYDRODATA_EXPORT virtual TopoDS_Shape GetShape() const; + + + /** + * Returns number of geometry objects for zone. + */ + HYDRODATA_EXPORT virtual int NbGeometryObjects() const; /** - * Remove reference polyline object of zone. + * Add new one geometry object for zone. */ - HYDRODATA_EXPORT virtual void RemovePolyline(); + HYDRODATA_EXPORT virtual void AddGeometryObject( const Handle(HYDROData_Object)& theObject ); + /** + * Replace the geometry object for zone. + */ + HYDRODATA_EXPORT virtual void SetGeometryObject( const int theIndex, + const Handle(HYDROData_Object)& theObject ); /** - * Returns data of object wrapped to QVariant. - * Reimplemented to wrap and return saved 2d polyline. + * Sets the geometry object for zone. */ - //HYDRODATA_EXPORT virtual QVariant GetDataVariant(); + HYDRODATA_EXPORT virtual void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); /** - * Returns the shape of the the object (redefined method). + * Returns geometry object of zone by index. */ - HYDRODATA_EXPORT TopoDS_Face Face() const; + HYDRODATA_EXPORT virtual Handle(HYDROData_Object) GetGeometryObject( const int theIndex ) const; + + /** + * Returns all geometry objects of zone. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryObjects() const; + + /** + * Removes all geometry objects from zone. + */ + HYDRODATA_EXPORT virtual void RemoveGeometryObjects(); + protected: + friend class HYDROData_Region; friend class HYDROData_Iterator; /** @@ -81,10 +105,6 @@ protected: */ ~HYDROData_Zone(); - /** - * Returns id for creation of object in python scripting. - */ - virtual QString getPythonKindId() const; }; #endif diff --git a/src/HYDROData/HYDROOperations_BSpline.cxx b/src/HYDROData/HYDROOperations_BSpline.cxx deleted file mode 100644 index 419788ef..00000000 --- a/src/HYDROData/HYDROOperations_BSpline.cxx +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#include -#include -#include -#include - -HYDROOperations_BSpline::HYDROOperations_BSpline( - const QList& thePoints, - const double theZValue, - const bool theIsClosed) -{ - // fill array for algorithm by the received coordinates - int aLen = thePoints.size() / 2; - Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen); - QList::const_iterator aListIter = thePoints.begin(); - for (int ind = 1; ind <= aLen; ind++) { - gp_Pnt aPnt(gp::Origin()); - aPnt.SetX(*aListIter); - aListIter++; - aPnt.SetY(*aListIter); - aListIter++; - aPnt.SetZ(theZValue); - aHCurvePoints->SetValue(ind, aPnt); - } - // compute BSpline - GeomAPI_Interpolate aGBC(aHCurvePoints, theIsClosed, gp::Resolution()); - aGBC.Perform(); - if (aGBC.IsDone()) { - myCurve = aGBC.Curve(); - } -} - -QPainterPath HYDROOperations_BSpline::ComputePath() const -{ - QPainterPath aResult; - if (myCurve.IsNull()) // returns an empty Path if original curve is invalid - return aResult; - GeomConvert_BSplineCurveToBezierCurve aConverter(myCurve); - int a, aNumArcs = aConverter.NbArcs(); - for(a = 1; a <= aNumArcs; a++) { - Handle(Geom_BezierCurve) anArc = aConverter.Arc(a); - if (a == 1) { // set a start point - gp_Pnt aStart = anArc->StartPoint(); - aResult.moveTo(aStart.X(), aStart.Y()); - } - gp_Pnt anEnd = anArc->EndPoint(); - if (anArc->NbPoles() == 3) { // quadric segment in the path (pole 1 is start, pole 3 is end) - gp_Pnt aPole = anArc->Pole(2); - aResult.quadTo(aPole.X(), aPole.Y(), anEnd.X(), anEnd.Y()); - } else if (anArc->NbPoles() == 4) { // cubic segment (usually this is used) - gp_Pnt aPole1 = anArc->Pole(2); - gp_Pnt aPole2 = anArc->Pole(3); - aResult.cubicTo( - aPole1.X(), aPole1.Y(), aPole2.X(), aPole2.Y(), anEnd.X(), anEnd.Y()); - } else { // error, another number of poles is not supported - return QPainterPath(); - } - } - return aResult; -} diff --git a/src/HYDROData/HYDROOperations_BSpline.h b/src/HYDROData/HYDROOperations_BSpline.h deleted file mode 100644 index 01df6026..00000000 --- a/src/HYDROData/HYDROOperations_BSpline.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef HYDROOperations_BSpline_HeaderFile -#define HYDROOperations_BSpline_HeaderFile - -#include -#include -#include -#include - -/**\class HYDROOperations_BSpline - * - * \brief Allows to work with splines: create, convert to Qt ToolPath. - * - * Uses GEOM module for creation of BSplines, OCCT algorithms for - * manipulation and conversion. - */ - -class HYDRODATA_EXPORT HYDROOperations_BSpline -{ -public: - - //! Creates a spline by list of coordinates: pairs X and Y - //! \param thePoints coordinates in format X1, Y1, X2, Y2, etc. must be even number of elements - //! \param theZValue constant value of the spline Z coordinate - //! \param theIsClosed flag indicating that the result spline should be closed - HYDROOperations_BSpline(const QList& thePoints, - const double theZValue, - const bool theIsClosed); - - //! Returns the BSpline curve passing through the points - //! \returns Null if Computation of BSpline was failed - Handle(Geom_BSplineCurve) Curve() const {return myCurve;} - - //! Performs conversion from BSpline curve to QPainterPath made from Bezier curves - //! \returns computed PainterPath, not stored in this class, so calling of this method is not fast - QPainterPath ComputePath() const; -private: - Handle(Geom_BSplineCurve) myCurve; ///< resulting BSpline, null if something is wrong -}; - -#endif diff --git a/src/HYDROData/HYDROOperations_Factory.cxx b/src/HYDROData/HYDROOperations_Factory.cxx deleted file mode 100644 index ffe38aa0..00000000 --- a/src/HYDROData/HYDROOperations_Factory.cxx +++ /dev/null @@ -1,73 +0,0 @@ -#include - -#include -#include - -#include -#include -#include -#include - -#include - -// global instance -HYDROOperations_Factory* FACTORY = 0; - -HYDROOperations_Factory* HYDROOperations_Factory::Factory() -{ - if (!FACTORY) { - FACTORY = new HYDROOperations_Factory; - // default operations - REGISTER_HYDRO_OPERATION(ImageComposer_ColorMaskOperator) - REGISTER_HYDRO_OPERATION(ImageComposer_CropOperator) - REGISTER_HYDRO_OPERATION(ImageComposer_CutOperator) - REGISTER_HYDRO_OPERATION(ImageComposer_FuseOperator) - } - return FACTORY; -} - -void HYDROOperations_Factory::Register( - ImageComposer_Operator* theOperator) -{ - if ( !theOperator ) - return; - - FACTORY->myOps[ theOperator->name() ] = theOperator; -} - -HYDROOperations_Factory::HYDROOperations_Factory() -{ -} - -ImageComposer_Operator* HYDROOperations_Factory::Operator( - Handle(HYDROData_Image) theImage ) const -{ - // retreive operator instance by name - ImageComposer_Operator* anOp = Operator( theImage->OperatorName() ); - if ( !anOp ) - return anOp; - - // fill arguments of the operator from theImage - anOp->setBinArgs( theImage->Args() ); - - return anOp; -} - -ImageComposer_Operator* HYDROOperations_Factory::Operator(const QString theName) const -{ - return myOps.contains( theName ) ? myOps[ theName ] : NULL; -} - -Handle(HYDROData_Image) HYDROOperations_Factory::CreateImage( - Handle(HYDROData_Document) theDoc, const ImageComposer_Operator* theOperator) -{ - // create an object - Handle(HYDROData_Image) anImage = - Handle(HYDROData_Image)::DownCast(theDoc->CreateObject(KIND_IMAGE)); - // get data from operation - if (theOperator) { - anImage->SetOperatorName( theOperator->name() ); - anImage->SetArgs( theOperator->getBinArgs() ); - } - return anImage; -} diff --git a/src/HYDROData/HYDROOperations_Factory.h b/src/HYDROData/HYDROOperations_Factory.h deleted file mode 100644 index 310280a7..00000000 --- a/src/HYDROData/HYDROOperations_Factory.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef HYDROOperations_Factory_HeaderFile -#define HYDROOperations_Factory_HeaderFile - -#include -#include -#include - -class ImageComposer_Operator; -class Handle_HYDROData_Document; - -/**\class HYDROOperations_Factory - * - * \brief This class provides the unified management of operations on images. - * - * Object is created as one global instance and allows to register and launch - * all registered operations in general way. To register a new operation just - * call REGISTER_HYDRO_OPERATION(operation_name) in some method implementation. - * This macro will call constructor of this operation (it must inherit - * ImageComposer_Operator) and factory will set up arguments and call this - * operator by demand. - */ - -class HYDROOperations_Factory -{ -public: - - //! Returns the global factory - HYDRODATA_EXPORT static HYDROOperations_Factory* Factory(); - - /** - * Registers the operator by the name, used by REGISTER_HYDRO_OPERATION macro - * \param theOperator new instance of the operator that will be used for - * processing of operation with such kind - */ - HYDRODATA_EXPORT static void Register( - ImageComposer_Operator* theOperator); - - /** - * Creates a new Image object in the data structure by the operator data. - * \param theDoc document where it must be created - * \param theOperator base operator for this Image: will be used in "Update" to recompute the image - * \returns created object related to the data structure - */ - HYDRODATA_EXPORT Handle(HYDROData_Image) CreateImage( - Handle_HYDROData_Document theDoc, const ImageComposer_Operator* theOperator); - - /** - * Returns the operator, initialized by the properties of theImage - * \param theImage data structures object, that contains all arguments - * required for creation of operation - * \returns NULL if operator type is unknown - */ - HYDRODATA_EXPORT ImageComposer_Operator* Operator( - Handle(HYDROData_Image) theImage) const; - - - /** - * Returns the appropriate operator by the name - * \param theName name of the operator, equals to the operation_name constructor - * \returns NULL if operator with such name is not registered yet - */ - HYDRODATA_EXPORT ImageComposer_Operator* Operator(const QString theName) const; - -protected: - - //! Not public constructor that creates only one, global instance of this factory. - HYDROOperations_Factory(); - -private: - //! Map that stores all operators, isentified by strings - typedef QMap FactoryOperators; - - FactoryOperators myOps; ///< all operators stored by a factory -}; - -/** - * Macro that is used for registered operators, see C++ of this class to see - * example of hte registration. - */ -#define REGISTER_HYDRO_OPERATION(operation_name) \ - HYDROOperations_Factory::Factory()->Register(new operation_name); - -#endif diff --git a/src/HYDROData/test_HYDROData_BSplineOperation.cxx b/src/HYDROData/test_HYDROData_BSplineOperation.cxx new file mode 100644 index 00000000..33658760 --- /dev/null +++ b/src/HYDROData/test_HYDROData_BSplineOperation.cxx @@ -0,0 +1,64 @@ +#include + +#include +#include +#include + +void test_HYDROData_BSplineOperation::testCurve() +{ + // prepare points: function of sin(x) + QList aPoints; + double x; + for(x = 0; x < 6.28; x += 0.1) + aPoints<IsClosed()); + CPPUNIT_ASSERT_EQUAL(aBS->Continuity(), GeomAbs_C2); + // check that values of BSpline are not far from original "sin" function + // in all points of the curve + for(x = 0; x < 6.29; x += 0.001) { + double aDiff = aBS->Value(x).Y() - sin(aBS->Value(x).X()); + if (aDiff < 0) aDiff = -aDiff; + CPPUNIT_ASSERT(aDiff < 3.e-6); // this number is found manually + } +} + +void test_HYDROData_BSplineOperation::testPath() +{ + // prepare points: function of sin(x) + static const double aScale = 10000000.; + QList aPoints; + double x; + for(x = 0; x < 6.28; x += 0.1) + aPoints< aPolyF = aPath.toSubpathPolygons(QTransform()); + QList::iterator aFIter = aPolyF.begin(); + for(; aFIter != aPolyF.end();aFIter++) { + QPolygon aPoly = aFIter->toPolygon(); + QPolygon::iterator aPoints = aPoly.begin(); + for(; aPoints != aPoly.end(); aPoints++) { + double aDiff = aPoints->y() / aScale - sin(aPoints->x() / aScale); + if (aDiff < 0) aDiff = -aDiff; + CPPUNIT_ASSERT(aDiff < 4.e-6); // this number is found manually + } + } +} diff --git a/src/HYDROData/test_HYDROData_BSplineOperation.h b/src/HYDROData/test_HYDROData_BSplineOperation.h new file mode 100644 index 00000000..c7d8aa81 --- /dev/null +++ b/src/HYDROData/test_HYDROData_BSplineOperation.h @@ -0,0 +1,26 @@ +#include + +class test_HYDROData_BSplineOperation : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_BSplineOperation); + CPPUNIT_TEST(testCurve); + CPPUNIT_TEST(testPath); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks generation of BSpline curve by points + void testCurve(); + + // checks generation of QPainterPath + void testPath(); + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_BSplineOperation); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_BSplineOperation, "HYDROData_BSplineOperation"); diff --git a/src/HYDROData/test_HYDROData_OperationsFactory.cxx b/src/HYDROData/test_HYDROData_OperationsFactory.cxx new file mode 100644 index 00000000..bea1c987 --- /dev/null +++ b/src/HYDROData/test_HYDROData_OperationsFactory.cxx @@ -0,0 +1,86 @@ +#include + +#include +#include +#include +#include + +#include + +#include + +void test_HYDROData_OperationsFactory::testCreate() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); + CPPUNIT_ASSERT(aFactory); + Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL); + CPPUNIT_ASSERT(!anImage.IsNull()); + CPPUNIT_ASSERT(anImage->Image().isNull()); + + aDoc->Close(); +} + +static QImage TestImage() { + QImage aPic(50, 40, QImage::Format_RGB32); + aPic.fill(Qt::white); + QPainter aPainter(&aPic); + aPainter.drawEllipse(6, 7, 38, 30); + aPainter.drawLine(0, 40, 10, 0); + aPainter.drawLine(10, 0, 25, 35); + aPainter.drawLine(25, 35, 40, 0); + aPainter.drawLine(40, 0, 50, 40); + return aPic; +} + +void test_HYDROData_OperationsFactory::testCrop() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); + + // prepare the original image and crop-path + Handle(HYDROData_Image) anOriImage = + Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) ); + + QImage aTestImage = TestImage(); + anOriImage->SetImage( aTestImage ); + + Handle(HYDROData_Polyline) aCropPolyline = + Handle(HYDROData_Polyline)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) ); + + HYDROData_Polyline::PolylineData aPolylineData; + + PolylineSection aPolylineSect; + + aPolylineSect.myCoords << 25 << 0 << 0; + aPolylineSect.myCoords << 0 << 20 << 0; + aPolylineSect.myCoords << 25 << 40 << 0; + aPolylineSect.myCoords << 50 << 20 << 0; + + aPolylineData << aPolylineSect; + + aCropPolyline->setPolylineData( aPolylineData ); + + // prepare Composer Operation + ImageComposer_Operator* aCropOp = + aFactory->Operator( ImageComposer_CropOperator::Type() ); + + CPPUNIT_ASSERT( aCropOp ); + + aCropOp->setArgs( Qt::red ); + + // create crop - image + Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp ); + CPPUNIT_ASSERT( !aCropImage.IsNull() ); + + aCropImage->AppendReference( anOriImage ); + aCropImage->AppendReference( aCropPolyline ); + aCropImage->Update(); + + // check crop operation was performed + CPPUNIT_ASSERT( !aCropImage->Image().isNull() ); + CPPUNIT_ASSERT( aCropImage->Image() != aTestImage ); + + aDoc->Close(); +} diff --git a/src/HYDROData/test_HYDROData_OperationsFactory.h b/src/HYDROData/test_HYDROData_OperationsFactory.h new file mode 100644 index 00000000..7c033a95 --- /dev/null +++ b/src/HYDROData/test_HYDROData_OperationsFactory.h @@ -0,0 +1,25 @@ +#include + +class test_HYDROData_OperationsFactory : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_OperationsFactory); + CPPUNIT_TEST(testCreate); + CPPUNIT_TEST(testCrop); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks creation of images using null operators + void testCreate(); + + // checks creation of images using crop operator + void testCrop(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_OperationsFactory); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_OperationsFactory, "HYDROData_OperationsFactory"); diff --git a/src/HYDROData/test_HYDROOperations_BSpline.cxx b/src/HYDROData/test_HYDROOperations_BSpline.cxx deleted file mode 100644 index d889abb0..00000000 --- a/src/HYDROData/test_HYDROOperations_BSpline.cxx +++ /dev/null @@ -1,64 +0,0 @@ -#include - -#include -#include -#include - -void test_HYDROOperations_BSpline::testCurve() -{ - // prepare points: function of sin(x) - QList aPoints; - double x; - for(x = 0; x < 6.28; x += 0.1) - aPoints<IsClosed()); - CPPUNIT_ASSERT_EQUAL(aBS->Continuity(), GeomAbs_C2); - // check that values of BSpline are not far from original "sin" function - // in all points of the curve - for(x = 0; x < 6.29; x += 0.001) { - double aDiff = aBS->Value(x).Y() - sin(aBS->Value(x).X()); - if (aDiff < 0) aDiff = -aDiff; - CPPUNIT_ASSERT(aDiff < 3.e-6); // this number is found manually - } -} - -void test_HYDROOperations_BSpline::testPath() -{ - // prepare points: function of sin(x) - static const double aScale = 10000000.; - QList aPoints; - double x; - for(x = 0; x < 6.28; x += 0.1) - aPoints< aPolyF = aPath.toSubpathPolygons(QTransform()); - QList::iterator aFIter = aPolyF.begin(); - for(; aFIter != aPolyF.end();aFIter++) { - QPolygon aPoly = aFIter->toPolygon(); - QPolygon::iterator aPoints = aPoly.begin(); - for(; aPoints != aPoly.end(); aPoints++) { - double aDiff = aPoints->y() / aScale - sin(aPoints->x() / aScale); - if (aDiff < 0) aDiff = -aDiff; - CPPUNIT_ASSERT(aDiff < 4.e-6); // this number is found manually - } - } -} diff --git a/src/HYDROData/test_HYDROOperations_BSpline.h b/src/HYDROData/test_HYDROOperations_BSpline.h deleted file mode 100644 index 6eb11056..00000000 --- a/src/HYDROData/test_HYDROOperations_BSpline.h +++ /dev/null @@ -1,26 +0,0 @@ -#include - -class test_HYDROOperations_BSpline : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROOperations_BSpline); - CPPUNIT_TEST(testCurve); - CPPUNIT_TEST(testPath); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks generation of BSpline curve by points - void testCurve(); - - // checks generation of QPainterPath - void testPath(); - -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROOperations_BSpline); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROOperations_BSpline, "HYDROOperations_BSpline"); diff --git a/src/HYDROData/test_HYDROOperations_Factory.cxx b/src/HYDROData/test_HYDROOperations_Factory.cxx deleted file mode 100644 index f09794d4..00000000 --- a/src/HYDROData/test_HYDROOperations_Factory.cxx +++ /dev/null @@ -1,86 +0,0 @@ -#include - -#include -#include -#include -#include - -#include - -#include - -void test_HYDROOperations_Factory::testCreate() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); - CPPUNIT_ASSERT(aFactory); - Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL); - CPPUNIT_ASSERT(!anImage.IsNull()); - CPPUNIT_ASSERT(anImage->Image().isNull()); - - aDoc->Close(); -} - -static QImage TestImage() { - QImage aPic(50, 40, QImage::Format_RGB32); - aPic.fill(Qt::white); - QPainter aPainter(&aPic); - aPainter.drawEllipse(6, 7, 38, 30); - aPainter.drawLine(0, 40, 10, 0); - aPainter.drawLine(10, 0, 25, 35); - aPainter.drawLine(25, 35, 40, 0); - aPainter.drawLine(40, 0, 50, 40); - return aPic; -} - -void test_HYDROOperations_Factory::testCrop() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); - HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); - - // prepare the original image and crop-path - Handle(HYDROData_Image) anOriImage = - Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) ); - - QImage aTestImage = TestImage(); - anOriImage->SetImage( aTestImage ); - - Handle(HYDROData_Polyline) aCropPolyline = - Handle(HYDROData_Polyline)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) ); - - HYDROData_Polyline::PolylineData aPolylineData; - - PolylineSection aPolylineSect; - - aPolylineSect.myCoords << 25 << 0 << 0; - aPolylineSect.myCoords << 0 << 20 << 0; - aPolylineSect.myCoords << 25 << 40 << 0; - aPolylineSect.myCoords << 50 << 20 << 0; - - aPolylineData << aPolylineSect; - - aCropPolyline->setPolylineData( aPolylineData ); - - // prepare Composer Operation - ImageComposer_Operator* aCropOp = - aFactory->Operator( ImageComposer_CropOperator::Type() ); - - CPPUNIT_ASSERT( aCropOp ); - - aCropOp->setArgs( Qt::red ); - - // create crop - image - Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp ); - CPPUNIT_ASSERT( !aCropImage.IsNull() ); - - aCropImage->AppendReference( anOriImage ); - aCropImage->AppendReference( aCropPolyline ); - aCropImage->Update(); - - // check crop operation was performed - CPPUNIT_ASSERT( !aCropImage->Image().isNull() ); - CPPUNIT_ASSERT( aCropImage->Image() != aTestImage ); - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROOperations_Factory.h b/src/HYDROData/test_HYDROOperations_Factory.h deleted file mode 100644 index fa7e9172..00000000 --- a/src/HYDROData/test_HYDROOperations_Factory.h +++ /dev/null @@ -1,25 +0,0 @@ -#include - -class test_HYDROOperations_Factory : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROOperations_Factory); - CPPUNIT_TEST(testCreate); - CPPUNIT_TEST(testCrop); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks creation of images using null operators - void testCreate(); - - // checks creation of images using crop operator - void testCrop(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROOperations_Factory); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROOperations_Factory, "HYDROOperations_Factory"); diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 0a8e21c8..7db85c37 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -14,6 +14,8 @@ set(PROJECT_HEADERS HYDROGUI_Displayer.h HYDROGUI_ExportImageOp.h HYDROGUI_GVSelector.h + HYDROGUI_ImmersibleZoneDlg.h + HYDROGUI_ImmersibleZoneOp.h HYDROGUI_ImportBathymetryDlg.h HYDROGUI_ImportBathymetryOp.h HYDROGUI_ImportImageDlg.h @@ -46,8 +48,6 @@ set(PROJECT_HEADERS HYDROGUI_UpdateFlags.h HYDROGUI_UpdateImageOp.h HYDROGUI_VisualStateOp.h - HYDROGUI_ZoneDlg.h - HYDROGUI_ZoneOp.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -64,6 +64,8 @@ set(PROJECT_SOURCES HYDROGUI_Displayer.cxx HYDROGUI_ExportImageOp.cxx HYDROGUI_GVSelector.cxx + HYDROGUI_ImmersibleZoneDlg.cxx + HYDROGUI_ImmersibleZoneOp.cxx HYDROGUI_ImportBathymetryDlg.cxx HYDROGUI_ImportBathymetryOp.cxx HYDROGUI_ImportImageDlg.cxx @@ -95,8 +97,6 @@ set(PROJECT_SOURCES HYDROGUI_TwoImagesOp.cxx HYDROGUI_UpdateImageOp.cxx HYDROGUI_VisualStateOp.cxx - HYDROGUI_ZoneDlg.cxx - HYDROGUI_ZoneOp.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI.vcproj b/src/HYDROGUI/HYDROGUI.vcproj index c5cbe2e5..6e037af8 100644 --- a/src/HYDROGUI/HYDROGUI.vcproj +++ b/src/HYDROGUI/HYDROGUI.vcproj @@ -170,6 +170,14 @@ RelativePath=".\HYDROGUI_GVSelector.cxx" > + + + + @@ -270,10 +278,6 @@ RelativePath=".\HYDROGUI_ShowHideOp.cxx" > - - @@ -294,14 +298,6 @@ RelativePath=".\HYDROGUI_VisualStateOp.cxx" > - - - - @@ -455,6 +451,34 @@ /> + + + + + + + + + + @@ -580,7 +604,7 @@ @@ -685,10 +709,6 @@ /> - - @@ -753,34 +773,6 @@ /> - - - - - - - - - - + + + + @@ -1011,14 +1011,6 @@ RelativePath=".\moc\moc_HYDROGUI_VisualStateOp.cxx" > - - - - diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.cxx b/src/HYDROGUI/HYDROGUI_AISCurve.cxx index 75d90586..16364e6f 100755 --- a/src/HYDROGUI/HYDROGUI_AISCurve.cxx +++ b/src/HYDROGUI/HYDROGUI_AISCurve.cxx @@ -1,6 +1,6 @@ #include "HYDROGUI_AISCurve.h" -#include +#include #include @@ -106,7 +106,7 @@ void HYDROGUI_AISCurveSection::buildSection() if( aSectSize > 1 ) { - HYDROOperations_BSpline aBSpline( aPoints, 0, aSectIsClosed ); + HYDROData_BSplineOperation aBSpline( aPoints, 0, aSectIsClosed ); TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge(); TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 57e38659..1fc70566 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -52,56 +52,24 @@ HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, co aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) ); aNameLayout->addWidget( myObjectName ); - - // Calculation boundary line - QGroupBox* aBndGroup = new QGroupBox( tr( "CALCULATION_BOUNDARY" ), mainFrame() ); - - myBndPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINE, aBndGroup ); - - QBoxLayout* aBndLayout = new QHBoxLayout( aBndGroup ); - aBndLayout->setMargin( 5 ); - aBndLayout->setSpacing( 5 ); - aBndLayout->addWidget( new QLabel( tr( "BOUNDARY_POLYLINE" ), aBndGroup ) ); - aBndLayout->addWidget( myBndPolyline ); - - // Calculation zones - QGroupBox* aZonesGroup = new QGroupBox( tr( "CALCULATION_ZONES" ), mainFrame() ); - - myZones = new QListWidget( aZonesGroup ); - myZones->setSelectionMode( QListWidget::SingleSelection ); - myZones->setEditTriggers( QListWidget::NoEditTriggers ); - myZones->setViewMode( QListWidget::ListMode ); - - myRegions = new QListWidget( aZonesGroup ); - myRegions->setSelectionMode( QListWidget::SingleSelection ); - myRegions->setEditTriggers( QListWidget::NoEditTriggers ); - myRegions->setViewMode( QListWidget::ListMode ); + QFrame* anObjectsFrame = new QFrame( mainFrame() ); - mySplittedZonesPrefix = new QLineEdit( aZonesGroup ); + myGeomObjects = new QListWidget( anObjectsFrame ); + myGeomObjects->setSelectionMode( QListWidget::SingleSelection ); + myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers ); + myGeomObjects->setViewMode( QListWidget::ListMode ); - QPushButton* aSplitBtn = new QPushButton( tr( "SPLIT_REFERENCE_ZONES" ), aZonesGroup ); - - QGridLayout* aZonesLayout = new QGridLayout( aZonesGroup ); + QGridLayout* aZonesLayout = new QGridLayout( anObjectsFrame ); aZonesLayout->setMargin( 5 ); aZonesLayout->setSpacing( 5 ); - aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_REFERENCE_ZONES" ), aZonesGroup ), 0, 0, 1, 2 ); - aZonesLayout->addWidget( myZones, 1, 0, 1, 2 ); - aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_REGIONS" ), aZonesGroup ), 2, 0, 1, 2 ); - aZonesLayout->addWidget( myRegions, 3, 0, 1, 2 ); - aZonesLayout->addWidget( new QLabel( tr( "PREFIX_REGIONS" ), aZonesGroup ), 4, 0 ); - aZonesLayout->addWidget( mySplittedZonesPrefix, 4, 1 ); - aZonesLayout->addWidget( aSplitBtn, 5, 0, 1, 2 ); + aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), myGeomObjects ), 0, 0 ); + aZonesLayout->addWidget( myGeomObjects, 0, 1 ); // Common addWidget( myObjectNameGroup ); - addWidget( aBndGroup ); - addWidget( aZonesGroup ); + addWidget( anObjectsFrame ); addStretch(); - - - // Connect signals and slots - connect( aSplitBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( SplitZones() ) ); } HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg() @@ -112,12 +80,7 @@ void HYDROGUI_CalculationDlg::reset() { myObjectName->clear(); - myBndPolyline->Clear(); - - myZones->clear(); - myRegions->clear(); - - setSplitZonesPrefix( tr( "DEFAULT_PREFIX_REGIONS" ) ); + myGeomObjects->clear(); } void HYDROGUI_CalculationDlg::setObjectName( const QString& theName ) @@ -130,106 +93,38 @@ QString HYDROGUI_CalculationDlg::getObjectName() const return myObjectName->text(); } -void HYDROGUI_CalculationDlg::setPolylineName( const QString& theName ) -{ - myBndPolyline->SetName( theName ); -} - -QString HYDROGUI_CalculationDlg::getPolylineName() const -{ - return myBndPolyline->GetName(); -} - -void HYDROGUI_CalculationDlg::setZones( const QStringList& theZones ) -{ - myZones->clear(); - - for ( int i = 0, n = theZones.length(); i < n; ++i ) - { - QString aZoneName = theZones.at( i ); - - QListWidgetItem* aListItem = new QListWidgetItem( aZoneName, myZones ); - aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable ); - aListItem->setCheckState( Qt::Unchecked ); - } -} - -void HYDROGUI_CalculationDlg::setSelectedZones( const QStringList& theZones ) +void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects ) { - for ( int i = 0, n = theZones.length(); i < n; ++i ) - { - QString aZoneName = theZones.at( i ); - - QList anItems = - myZones->findItems( aZoneName, Qt::MatchFixedString | Qt::MatchCaseSensitive ); - if ( anItems.isEmpty() ) - continue; - - QListWidgetItem* aListItem = anItems.first(); - if ( !aListItem ) - continue; - - aListItem->setCheckState( Qt::Checked ); - } -} - -QStringList HYDROGUI_CalculationDlg::getSelectedZones() const -{ - QStringList aResList; - - for ( int i = 0, n = myZones->count(); i < n; ++i ) - { - QListWidgetItem* aListItem = myZones->item( i ); - if ( !aListItem || aListItem->checkState() != Qt::Checked ) - continue; - - QString aSelZoneName = aListItem->text(); - aResList.append( aSelZoneName ); - } - - return aResList; } -void HYDROGUI_CalculationDlg::setRegions( const QStringList& theRegions ) +void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects ) { - myRegions->clear(); + myGeomObjects->clear(); - for ( int i = 0, n = theRegions.length(); i < n; ++i ) + for ( int i = 0, n = theObjects.length(); i < n; ++i ) { - QString aRegionName = theRegions.at( i ); + QString anObjName = theObjects.at( i ); - QListWidgetItem* aListItem = new QListWidgetItem( aRegionName, myRegions ); + QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects ); aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); } } -QStringList HYDROGUI_CalculationDlg::getRegions() const +QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const { QStringList aResList; - for ( int i = 0, n = myRegions->count(); i < n; ++i ) + for ( int i = 0, n = myGeomObjects->count(); i < n; ++i ) { - QListWidgetItem* aListItem = myRegions->item( i ); + QListWidgetItem* aListItem = myGeomObjects->item( i ); if ( !aListItem ) continue; - QString aRegionName = aListItem->text(); - aResList.append( aRegionName ); + QString aSelObjName = aListItem->text(); + aResList.append( aSelObjName ); } return aResList; } -void HYDROGUI_CalculationDlg::setSplitZonesPrefix( const QString& theName ) -{ - mySplittedZonesPrefix->setText( theName ); -} - -QString HYDROGUI_CalculationDlg::getSplitZonesPrefix() const -{ - QString aPrefix = mySplittedZonesPrefix->text(); - if ( aPrefix.isEmpty() ) - aPrefix = tr( "DEFAULT_PREFIX_REGIONS" ); - return aPrefix; -} diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index c63fffa5..8ab1c410 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -43,31 +43,15 @@ public: void setObjectName( const QString& theName ); QString getObjectName() const; - void setPolylineName( const QString& theName ); - QString getPolylineName() const; - - void setZones( const QStringList& theZones ); - void setSelectedZones( const QStringList& theZones ); - QStringList getSelectedZones() const; - - void setRegions( const QStringList& theRegions ); - QStringList getRegions() const; - - void setSplitZonesPrefix( const QString& theName ); - QString getSplitZonesPrefix() const; - -signals: - void SplitZones(); + void setGeomObjects( const QStringList& theObjects ); + void setSelectedGeomObjects( const QStringList& theObjects ); + QStringList getSelectedGeomObjects() const; private: QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; - HYDROGUI_ObjSelector* myBndPolyline; - - QListWidget* myZones; - QListWidget* myRegions; - QLineEdit* mySplittedZonesPrefix; + QListWidget* myGeomObjects; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index fd48bc16..ff036a4f 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include @@ -69,7 +69,7 @@ void HYDROGUI_CalculationOp::startOperation() QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" ); - QStringList aSelectedZones, aRegions; + QStringList aSelectedObjects; myEditedObject.Nullify(); if ( myIsEdit ) @@ -79,82 +79,26 @@ void HYDROGUI_CalculationOp::startOperation() { anObjectName = myEditedObject->GetName(); - Handle(HYDROData_Polyline) aBoundaryPolyline = myEditedObject->GetBoundaryPolyline(); - if ( !aBoundaryPolyline.IsNull() ) - { - QString aPolylineName = aBoundaryPolyline->GetName(); - aPanel->setPolylineName( aPolylineName ); - } - - HYDROData_SequenceOfObjects aRefZones = myEditedObject->GetZones(); - HYDROData_SequenceOfObjects::Iterator anIter( aRefZones ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Zone) aRefZone = - Handle(HYDROData_Zone)::DownCast( anIter.Value() ); - if ( aRefZone.IsNull() ) - continue; - - QString aRefZoneName = aRefZone->GetName(); - if ( aRefZoneName.isEmpty() ) - continue; - - aSelectedZones.append( aRefZoneName ); - } - - HYDROData_SequenceOfObjects aDataRegions = myEditedObject->GetRegions(); - anIter.Init( aDataRegions ); + HYDROData_SequenceOfObjects aRefObjects = myEditedObject->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects ); for ( ; anIter.More(); anIter.Next() ) { - Handle(HYDROData_Region) aDataRegion = - Handle(HYDROData_Region)::DownCast( anIter.Value() ); - if ( aDataRegion.IsNull() ) + Handle(HYDROData_Object) aRefbject = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( aRefbject.IsNull() ) continue; - QString aRegionName = aDataRegion->GetName(); - if ( aRegionName.isEmpty() ) + QString aRefObjectName = aRefbject->GetName(); + if ( aRefObjectName.isEmpty() ) continue; - Region aRegion; - aRegion.SplitData.Shape = aDataRegion->Face(); - - aRegion.FillingColor = aDataRegion->GetFillingColor(); - aRegion.BorderColor = aDataRegion->GetBorderColor(); - - aRegion.RegionName = aRegionName; - - aRegion.DataRegion = aDataRegion; - - myRegionsList.append( aRegion ); - - aRegions.append( aRegionName ); + aSelectedObjects.append( aRefObjectName ); } } } - // collect information about existing zones - QStringList aZones; - - HYDROData_Iterator anIter( doc(), KIND_ZONE ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Zone) aZoneObj = - Handle(HYDROData_Zone)::DownCast( anIter.Current() ); - if ( aZoneObj.IsNull() ) - continue; - - QString aZoneName = aZoneObj->GetName(); - if ( aZoneName.isEmpty() ) - continue; - - aZones.append( aZoneName ); - } - aPanel->setObjectName( anObjectName ); - - aPanel->setZones( aZones ); - aPanel->setSelectedZones( aSelectedZones ); - aPanel->setRegions( aRegions ); + aPanel->setSelectedGeomObjects( aSelectedObjects ); createPreview(); } @@ -178,7 +122,6 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() ); // Connect signals and slots - connect( aPanel, SIGNAL( SplitZones() ), this, SLOT( onSplitZones() ) ); return aPanel; } @@ -201,7 +144,7 @@ bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags, // check that there are no other objects with the same name in the document if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) { - Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); if ( !anObject.IsNull() ) { theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName ); @@ -218,48 +161,11 @@ bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags, aCalculObj->SetName( anObjectName ); - QString aPolylineName = aPanel->getPolylineName(); - Handle(HYDROData_Polyline) aBndPolyline = Handle(HYDROData_Polyline)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) ); - - aCalculObj->SetBoundaryPolyline( aBndPolyline ); - - QStringList aRefZoneNames = aPanel->getSelectedZones(); - HYDROData_SequenceOfObjects aRefZones = - HYDROGUI_Tool::FindObjectsByNames( module(), aRefZoneNames, KIND_ZONE ); - - aCalculObj->SetZones( aRefZones ); - - HYDROData_SequenceOfObjects aRegions; - - RegionsList::iterator anIter = myRegionsList.begin(); - for ( ; anIter != myRegionsList.end(); ++anIter ) - { - const Region& aRegion = *anIter; - - if ( !aRegion.DataRegion.IsNull() ) - { - //No need to create new but use old zone - aRegions.Append( aRegion.DataRegion ); - continue; - } - - Handle(HYDROData_Region) aDataRegion = - Handle(HYDROData_Region)::DownCast( aDocument->CreateObject( KIND_REGION ) ); - if( aDataRegion.IsNull() ) - continue; - - // Fill the zone data - aDataRegion->SetFace( aRegion.SplitData.Face() ); + QStringList aRefObjectNames = aPanel->getSelectedGeomObjects(); + HYDROData_SequenceOfObjects aGeomObjects = + HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames ); - aDataRegion->SetName( aRegion.RegionName ); - aDataRegion->SetBorderColor( aRegion.BorderColor ); - aDataRegion->SetFillingColor( aRegion.FillingColor ); - - aRegions.Append( aDataRegion ); - } - - aCalculObj->SetRegions( aRegions ); + aCalculObj->SetGeometryObjects( aGeomObjects ); theUpdateFlags = UF_Model; @@ -277,32 +183,27 @@ void HYDROGUI_CalculationOp::onSplitZones() QApplication::setOverrideCursor( Qt::WaitCursor ); - QString aPolylineName = aPanel->getPolylineName(); - Handle(HYDROData_Polyline) aBndPolyline = Handle(HYDROData_Polyline)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) ); - - QStringList aZoneNames = aPanel->getSelectedZones(); - HYDROData_SequenceOfObjects aZones = - HYDROGUI_Tool::FindObjectsByNames( module(), aZoneNames, KIND_ZONE ); + QStringList aGeomObjectNames = aPanel->getSelectedGeomObjects(); + HYDROData_SequenceOfObjects aGeomObjects = + HYDROGUI_Tool::FindObjectsByNames( module(), aGeomObjectNames ); QStringList aResSplittedZones; - HYDROGUI_SplitZonesTool::SplitDataList aSplittedZones = - HYDROGUI_SplitZonesTool::SplitZones( aZones, aBndPolyline ); + HYDROData_SplitToZonesTool::SplitDataList aSplittedZones = + HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects ); - QString aSplitZonesPrefix = aPanel->getSplitZonesPrefix(); QStringList aUsedNames; - HYDROGUI_SplitZonesTool::SplitDataListIterator anIter( aSplittedZones ); + HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplittedZones ); while( anIter.hasNext() ) { Region aRegion; aRegion.SplitData = anIter.next(); - aRegion.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aRegion.SplitData.ZoneNames ); - aRegion.BorderColor = QColor( HYDROData_Zone::DefaultBorderColor() ); + aRegion.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aRegion.SplitData.ObjectNames ); + aRegion.BorderColor = QColor( HYDROData_ImmersibleZone::DefaultBorderColor() ); - aRegion.RegionName = HYDROGUI_Tool::GenerateObjectName( module(), aSplitZonesPrefix, aUsedNames ); + aRegion.RegionName = HYDROGUI_Tool::GenerateObjectName( module(), "Region", aUsedNames ); aUsedNames.append( aRegion.RegionName ); @@ -310,8 +211,6 @@ void HYDROGUI_CalculationOp::onSplitZones() myRegionsList.append( aRegion ); } - - aPanel->setRegions( aResSplittedZones ); createPreview(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 17cebaff..394afcd9 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -25,7 +25,7 @@ #include "HYDROGUI_Operation.h" -#include "HYDROGUI_SplitZonesTool.h" +#include "HYDROData_SplitToZonesTool.h" #include "HYDROGUI_Shape.h" #include @@ -43,7 +43,7 @@ class HYDROGUI_CalculationOp : public HYDROGUI_Operation QString RegionName; QColor FillingColor; QColor BorderColor; - HYDROGUI_SplitZonesTool::SplitData SplitData; + HYDROData_SplitToZonesTool::SplitData SplitData; HYDROGUI_Shape* Shape; Handle(HYDROData_Region) DataRegion; diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index ba159238..180b2dd8 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -243,17 +244,6 @@ void HYDROGUI_DataModel::update( const int theStudyId ) createObject( aBathymetryRootObj, aBathymetryObj ); } - LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) ); - - anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION ); - for( ; anIterator.More(); anIterator.Next() ) - { - Handle(HYDROData_Calculation) aCalculObj = - Handle(HYDROData_Calculation)::DownCast( anIterator.Current() ); - if( !aCalculObj.IsNull() ) - createObject( aCalculRootObj, aCalculObj ); - } - LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, partitionName( KIND_POLYLINE ) ); anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE ); @@ -265,17 +255,28 @@ void HYDROGUI_DataModel::update( const int theStudyId ) createObject( aPolylineRootObj, aPolylineObj ); } - LightApp_DataObject* aZonesRootObj = createObject( aRootObj, partitionName( KIND_ZONE ) ); + LightApp_DataObject* aZonesRootObj = createObject( aRootObj, partitionName( KIND_IMMERSIBLE_ZONE ) ); - anIterator = HYDROData_Iterator( aDocument, KIND_ZONE ); + anIterator = HYDROData_Iterator( aDocument, KIND_IMMERSIBLE_ZONE ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Zone) aZoneObj = - Handle(HYDROData_Zone)::DownCast( anIterator.Current() ); + Handle(HYDROData_ImmersibleZone) aZoneObj = + Handle(HYDROData_ImmersibleZone)::DownCast( anIterator.Current() ); if( !aZoneObj.IsNull() ) createObject( aZonesRootObj, aZoneObj ); } + LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) ); + + anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION ); + for( ; anIterator.More(); anIterator.Next() ) + { + Handle(HYDROData_Calculation) aCalculObj = + Handle(HYDROData_Calculation)::DownCast( anIterator.Current() ); + if( !aCalculObj.IsNull() ) + createObject( aCalculRootObj, aCalculObj ); + } + LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) ); anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE ); @@ -294,7 +295,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) } } -HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Object)& theModelObject ) +HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject ) { return NULL; // to do if necessary } @@ -333,7 +334,7 @@ void HYDROGUI_DataModel::updateModel() update( aModule->getStudyId() ); } -Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry, +Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry, const ObjectKind theObjectKind ) { QString anEntry = theEntry; @@ -346,7 +347,7 @@ Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEn HYDROData_Iterator anIterator( aDocument, theObjectKind ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Object) anObject = anIterator.Current(); + Handle(HYDROData_Entity) anObject = anIterator.Current(); if( !anObject.IsNull() ) { QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject ); @@ -426,7 +427,7 @@ bool HYDROGUI_DataModel::canCopy() if( aSeq.Length() != 1 ) return false; - Handle(HYDROData_Object) anObject = aSeq.First(); + Handle(HYDROData_Entity) anObject = aSeq.First(); if( anObject.IsNull() ) return false; @@ -443,7 +444,7 @@ bool HYDROGUI_DataModel::canPaste() { for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex ); + Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex ); if( !anObject.IsNull() && !anObject->IsRemoved() ) return true; } @@ -462,11 +463,11 @@ bool HYDROGUI_DataModel::paste() bool anIsChanged = false; for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex ); + Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex ); if( !anObject.IsNull() && !anObject->IsRemoved() ) { ObjectKind aKind = anObject->GetKind(); - Handle(HYDROData_Object) aClone = getDocument()->CreateObject( aKind ); + Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind ); if( !aClone.IsNull() ) { anObject->CopyTo( aClone ); @@ -504,12 +505,12 @@ QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind ) { switch( theObjectKind ) { - case KIND_IMAGE: return "IMAGES"; - case KIND_POLYLINE: return "POLYLINES"; - case KIND_VISUAL_STATE: return "VISUAL_STATES"; - case KIND_BATHYMETRY: return "BATHYMETRIES"; - case KIND_CALCULATION: return "CALCULATION_CASES"; - case KIND_ZONE: return "ZONES"; + case KIND_IMAGE: return "IMAGES"; + case KIND_POLYLINE: return "POLYLINES"; + case KIND_VISUAL_STATE: return "VISUAL_STATES"; + case KIND_BATHYMETRY: return "BATHYMETRIES"; + case KIND_CALCULATION: return "CALCULATION_CASES"; + case KIND_IMMERSIBLE_ZONE: return "IMMERSIBLE_ZONES"; default: break; } return QString(); @@ -522,7 +523,7 @@ Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const } LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, - Handle(HYDROData_Object) theModelObject, + Handle(HYDROData_Entity) theModelObject, const QString& theParentEntry, const bool theIsBuildTree ) { @@ -552,7 +553,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, if ( !aGuiObj ) return; - Handle(HYDROData_Object) aDataObj = aGuiObj->modelObject(); + Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject(); if ( aDataObj.IsNull() ) return; @@ -564,15 +565,15 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, Handle(HYDROData_Image)::DownCast( aDataObj ); for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ ) { - Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex ); + Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex ); if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) createObject( aGuiObj, aRefObj, aGuiObj->entry(), false ); } } - else if ( anObjectKind == KIND_ZONE ) + else if ( anObjectKind == KIND_IMMERSIBLE_ZONE ) { - Handle(HYDROData_Zone) aZoneObj = - Handle(HYDROData_Zone)::DownCast( aDataObj ); + Handle(HYDROData_ImmersibleZone) aZoneObj = + Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj ); LightApp_DataObject* aPolylineSect = createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() ); @@ -581,55 +582,44 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() ) createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false ); - LightApp_DataObject* aBathsSect = - createObject( aGuiObj, tr( "ZONE_BATHYMETRIES" ), aGuiObj->entry() ); + LightApp_DataObject* aBathSect = + createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() ); - HYDROData_SequenceOfObjects aZoneBaths = aZoneObj->GetBathymetries(); - HYDROData_SequenceOfObjects::Iterator aBathsIter( aZoneBaths ); - for ( ; aBathsIter.More(); aBathsIter.Next() ) - { - Handle(HYDROData_Bathymetry) aRefBath = - Handle(HYDROData_Bathymetry)::DownCast( aBathsIter.Value() ); - if( !aRefBath.IsNull() && !aRefBath->IsRemoved() ) - createObject( aBathsSect, aRefBath, aGuiObj->entry(), false ); - } + Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry(); + if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() ) + createObject( aBathSect, aBathymetry, aGuiObj->entry(), false ); } else if ( anObjectKind == KIND_CALCULATION ) { Handle(HYDROData_Calculation) aCaseObj = Handle(HYDROData_Calculation)::DownCast( aDataObj ); - LightApp_DataObject* aPolylineSect = - createObject( aGuiObj, tr( "CASE_BND_POLYLINE" ), aGuiObj->entry() ); - - Handle(HYDROData_Polyline) aPolyline = aCaseObj->GetBoundaryPolyline(); - if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() ) - createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false ); - - LightApp_DataObject* aRefZonesSect = - createObject( aGuiObj, tr( "CASE_REFERENCE_ZONES" ), aGuiObj->entry() ); - - HYDROData_SequenceOfObjects aRefZones = aCaseObj->GetZones(); - HYDROData_SequenceOfObjects::Iterator anIter( aRefZones ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Zone) aRefZone = - Handle(HYDROData_Zone)::DownCast( anIter.Value() ); - if( !aRefZone.IsNull() && !aRefZone->IsRemoved() ) - createObject( aRefZonesSect, aRefZone, aGuiObj->entry(), false ); - } - LightApp_DataObject* aCaseRegionsSect = createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() ); HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions(); - anIter.Init( aCaseRegions ); + HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions ); for ( ; anIter.More(); anIter.Next() ) { Handle(HYDROData_Region) aCaseRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() ); if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() ) - createObject( aCaseRegionsSect, aCaseRegion, aGuiObj->entry(), false ); + createObject( aCaseRegionsSect, aCaseRegion, aGuiObj->entry(), true ); + } + } + else if ( anObjectKind == KIND_REGION ) + { + Handle(HYDROData_Region) aRegionObj = + Handle(HYDROData_Region)::DownCast( aDataObj ); + + HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones(); + HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Zone) aRegionZone = + Handle(HYDROData_Zone)::DownCast( anIter.Value() ); + if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() ) + createObject( aGuiObj, aRegionZone, aGuiObj->entry(), true ); } } } diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 1f2f3fb2..1a3b12da 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -24,7 +24,7 @@ #define HYDROGUI_DATAMODEL_H #include -#include +#include #include #include @@ -111,7 +111,7 @@ public: * \param the data model object * \return the only one object referenced to the given data model object, or null if not found */ - virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Object)& theModelObject ); + virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject ); /** * Returns a data object referenced to the given data object. @@ -147,7 +147,7 @@ public: /** * Find a data object by the specified entry and kind */ - Handle(HYDROData_Object) objectByEntry( const QString& theEntry, + Handle(HYDROData_Entity) objectByEntry( const QString& theEntry, const ObjectKind theObjectKind = KIND_UNKNOWN ); /** @@ -235,7 +235,7 @@ protected: * \param theParentEntry entry of parent object */ LightApp_DataObject* createObject( SUIT_DataObject* theParent, - Handle(HYDROData_Object) theModelObject, + Handle(HYDROData_Entity) theModelObject, const QString& theParentEntry = QString(), const bool theIsBuildTree = true ); diff --git a/src/HYDROGUI/HYDROGUI_DataObject.cxx b/src/HYDROGUI/HYDROGUI_DataObject.cxx index b2b4d05e..0b293cd2 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.cxx +++ b/src/HYDROGUI/HYDROGUI_DataObject.cxx @@ -29,7 +29,7 @@ #include HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, - Handle(HYDROData_Object) theData, + Handle(HYDROData_Entity) theData, const QString& theParentEntry ) : CAM_DataObject( theParent ), LightApp_DataObject( theParent ), @@ -72,7 +72,7 @@ QFont HYDROGUI_DataObject::font( const int theId ) const return aFont; } -QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& theObject, +QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject, const bool theWithPrefix ) { QString aEntryStr = QString::null; diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index 69693349..e8814367 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -23,7 +23,7 @@ #ifndef HYDROGUI_DATAOBJECT_H #define HYDROGUI_DATAOBJECT_H -#include +#include #include @@ -50,7 +50,7 @@ public: * \param theParentEntry entry of the parent data object (for reference objects) */ HYDROGUI_DataObject( SUIT_DataObject* theParent, - Handle(HYDROData_Object) theData, + Handle(HYDROData_Entity) theData, const QString& theParentEntry ); /** @@ -76,12 +76,12 @@ public: /** * Returns the model data object. */ - const Handle(HYDROData_Object)& modelObject() const { return myData; } + const Handle(HYDROData_Entity)& modelObject() const { return myData; } /** * Redefines the object. */ - void setObject( Handle(HYDROData_Object) theObject ) { myData = theObject; } + void setObject( const Handle(HYDROData_Entity)& theObject ) { myData = theObject; } /** * Returns the entry prefix for all HYDRO data objects. @@ -91,11 +91,11 @@ public: /** * Returns the full entry for the specified data object. */ - static QString dataObjectEntry( const Handle(HYDROData_Object)& theObject, + static QString dataObjectEntry( const Handle(HYDROData_Entity)& theObject, const bool theWithPrefix = true ); protected: - Handle(HYDROData_Object) myData; ///< object from data model + Handle(HYDROData_Entity) myData; ///< object from data model QString myParentEntry; }; diff --git a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx index 8df9ef26..704fa4e3 100644 --- a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx @@ -55,7 +55,7 @@ void HYDROGUI_DeleteOp::startOperation() { for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Object) anObject = aSeq.Value( anIndex ); + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); if( !anObject.IsNull() ) { aFullSeq.Append( anObject ); @@ -93,7 +93,7 @@ void HYDROGUI_DeleteOp::startOperation() startDocOperation(); for( Standard_Integer anIndex = 1, aLength = aFullSeq.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Object) anObject = aFullSeq.Value( anIndex ); + Handle(HYDROData_Entity) anObject = aFullSeq.Value( anIndex ); if( !anObject.IsNull() && !anObject->IsRemoved() ) anObject->Remove(); } diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index 7f91a6a9..c28de63f 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -56,7 +56,7 @@ void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs GraphicsView_ObjectList anObjectList = aViewPort->getObjects(); for( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if( anObj.IsNull() ) continue; @@ -115,7 +115,7 @@ void HYDROGUI_Displayer::Update( const HYDROData_SequenceOfObjects& theObjs, for( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - const Handle(HYDROData_Object)& anObj = theObjs.Value( i ); + const Handle(HYDROData_Entity)& anObj = theObjs.Value( i ); if( anObj.IsNull() ) anObjectsToErase.Append( anObj ); else @@ -146,7 +146,7 @@ void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs, for( int i = 1, n = theObjs.Length(); i <= n; i++ ) { // the object may be null or dead - const Handle(HYDROData_Object)& anObj = theObjs.Value( i ); + const Handle(HYDROData_Entity)& anObj = theObjs.Value( i ); if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) ) { aViewPort->removeItem( aPrs ); @@ -172,7 +172,7 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs, GraphicsView_ObjectList anObjectList = aViewPort->getObjects(); for( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if( anObj.IsNull() ) continue; @@ -214,7 +214,7 @@ void HYDROGUI_Displayer::purgeObjects( const int theViewerId ) { if( HYDROGUI_Prs* aPrs = dynamic_cast( anIter.next() ) ) { - Handle(HYDROData_Object) anObject = aPrs->getObject(); + Handle(HYDROData_Entity) anObject = aPrs->getObject(); if( !anObject.IsNull() && anObject->IsRemoved() ) { aViewPort->removeItem( aPrs ); @@ -224,7 +224,7 @@ void HYDROGUI_Displayer::purgeObjects( const int theViewerId ) } } -HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object)& theObj ) +HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Entity)& theObj ) { HYDROGUI_PrsDriver* aDriver = NULL; ObjectKind aKind = theObj->GetKind(); diff --git a/src/HYDROGUI/HYDROGUI_Displayer.h b/src/HYDROGUI/HYDROGUI_Displayer.h index f39d9c2f..bc01eb90 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.h +++ b/src/HYDROGUI/HYDROGUI_Displayer.h @@ -23,7 +23,7 @@ #ifndef HYDROGUI_DISPLAYER_H #define HYDROGUI_DISPLAYER_H -#include +#include #include @@ -123,7 +123,7 @@ private: * \brief Get the presentation driver for the specified data object. * \param theObj data object */ - HYDROGUI_PrsDriver* getDriver( const Handle(HYDROData_Object)& theObj ); + HYDROGUI_PrsDriver* getDriver( const Handle(HYDROData_Entity)& theObj ); private: HYDROGUI_Module* myModule; diff --git a/src/HYDROGUI/HYDROGUI_GVSelector.cxx b/src/HYDROGUI/HYDROGUI_GVSelector.cxx index 95f72cdc..b1ac06cf 100644 --- a/src/HYDROGUI/HYDROGUI_GVSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_GVSelector.cxx @@ -76,7 +76,7 @@ void HYDROGUI_GVSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) if ( anOwner ) { QString anEntry = anOwner->entry(); - Handle(HYDROData_Object) aModelObject = aModel->objectByEntry( anEntry ); + Handle(HYDROData_Entity) aModelObject = aModel->objectByEntry( anEntry ); if( !aModelObject.IsNull() ) { if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( aModelObject, anObjectList ) ) diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneDlg.cxx b/src/HYDROGUI/HYDROGUI_ImmersibleZoneDlg.cxx new file mode 100644 index 00000000..b5f8a05e --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneDlg.cxx @@ -0,0 +1,274 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_ImmersibleZoneDlg.h" + +#include "HYDROGUI_ColorWidget.h" +#include "HYDROGUI_Tool.h" + +#include +#include +#include +#include +#include +#include +#include + +HYDROGUI_ImmersibleZoneDlg::HYDROGUI_ImmersibleZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ) +{ + // Zone name + myObjectNameGroup = new QGroupBox( tr( "ZONE_NAME" ), mainFrame() ); + + myObjectName = new QLineEdit( myObjectNameGroup ); + + QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup ); + aNameLayout->setMargin( 5 ); + aNameLayout->setSpacing( 5 ); + aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) ); + aNameLayout->addWidget( myObjectName ); + + + QGroupBox* aParamGroup = new QGroupBox( tr( "ZONE_PARAMETERS" ), mainFrame() ); + + QFrame* aPolylineFrame = new QFrame( aParamGroup ); + + myPolylines = new QComboBox( aPolylineFrame ); + myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + QBoxLayout* aPolyLayout = new QHBoxLayout( aPolylineFrame ); + aPolyLayout->setMargin( 0 ); + aPolyLayout->setSpacing( 5 ); + aPolyLayout->addWidget( new QLabel( tr( "ZONE_POLYLINE" ), aPolylineFrame ) ); + aPolyLayout->addWidget( myPolylines ); + + + QFrame* aFillingFrame = new QFrame( aParamGroup ); + QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame ); + myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame ); + myFillingTransparent->setChecked( true ); + myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame ); + myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame ); + + QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame ); + aFillingLayout->setMargin( 0 ); + aFillingLayout->setSpacing( 5 ); + aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 ); + aFillingLayout->addWidget( myFillingTransparent, 0, 1 ); + aFillingLayout->addWidget( myFillingColor, 1, 1 ); + aFillingLayout->addWidget( myFillingColorBox, 1, 2 ); + + + myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), mainFrame() ); + myBorderColorGroup->setCheckable( true ); + + myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup ); + + QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup ); + aBorderColorLayout->setMargin( 5 ); + aBorderColorLayout->setSpacing( 5 ); + aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) ); + aBorderColorLayout->addWidget( myBorderColorBox ); + + + QBoxLayout* aParamLayout = new QVBoxLayout( aParamGroup ); + aParamLayout->setMargin( 5 ); + aParamLayout->setSpacing( 5 ); + aParamLayout->addWidget( aPolylineFrame ); + aParamLayout->addWidget( aFillingFrame ); + aParamLayout->addWidget( myBorderColorGroup ); + + + QGroupBox* aBathGroup = new QGroupBox( tr( "ZONE_BATHYMETRY" ), mainFrame() ); + + myBathymetries = new QComboBox( aPolylineFrame ); + myBathymetries->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + QBoxLayout* aBathLayout = new QHBoxLayout( aBathGroup ); + aBathLayout->setMargin( 5 ); + aBathLayout->setSpacing( 5 ); + aBathLayout->addWidget( myBathymetries ); + + + // Common + addWidget( myObjectNameGroup ); + addWidget( aParamGroup ); + addWidget( aBathGroup ); + + addStretch(); + + + // Connect signals and slots + connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myFillingTransparent, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myFillingColor, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myFillingColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onFillingColorChanged() ) ); + connect( myBorderColorGroup, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myBorderColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onZoneDefChanged() ) ); +} + +HYDROGUI_ImmersibleZoneDlg::~HYDROGUI_ImmersibleZoneDlg() +{ +} + +void HYDROGUI_ImmersibleZoneDlg::reset() +{ + bool isBlocked = blockSignals( true ); + + myObjectName->clear(); + + myPolylines->clear(); + myBathymetries->clear(); + + myFillingTransparent->setChecked( true ); + myFillingColorBox->resetColor(); + + myBorderColorGroup->setChecked( false ); + myBorderColorBox->resetColor(); + + blockSignals( isBlocked ); + + onZoneDefChanged(); +} + +void HYDROGUI_ImmersibleZoneDlg::setObjectName( const QString& theName ) +{ + myObjectName->setText( theName ); +} + +QString HYDROGUI_ImmersibleZoneDlg::getObjectName() const +{ + return myObjectName->text(); +} + +void HYDROGUI_ImmersibleZoneDlg::setPolylineNames( const QStringList& thePolylines ) +{ + bool isBlocked = blockSignals( true ); + + myPolylines->clear(); + myPolylines->addItems( thePolylines ); + + blockSignals( isBlocked ); +} + +void HYDROGUI_ImmersibleZoneDlg::setPolylineName( const QString& theName ) +{ + int aNewIdx = myPolylines->findText( theName ); + if ( aNewIdx != myPolylines->currentIndex() ) + { + myPolylines->setCurrentIndex( aNewIdx ); + } + else + { + onZoneDefChanged(); + } +} + +QString HYDROGUI_ImmersibleZoneDlg::getPolylineName() const +{ + return myPolylines->currentText(); +} + +void HYDROGUI_ImmersibleZoneDlg::setBathymetryNames( const QStringList& theBathymetries ) +{ + bool isBlocked = blockSignals( true ); + + myBathymetries->clear(); + myBathymetries->addItems( theBathymetries ); + + blockSignals( isBlocked ); +} + +void HYDROGUI_ImmersibleZoneDlg::setBathymetryName( const QString& theName ) +{ + int aNewIdx = myBathymetries->findText( theName ); + myBathymetries->setCurrentIndex( aNewIdx ); +} + +QString HYDROGUI_ImmersibleZoneDlg::getBathymetryName() const +{ + return myBathymetries->currentText(); +} + +void HYDROGUI_ImmersibleZoneDlg::setFillingColor( const QColor& theColor ) +{ + bool isBlocked = blockSignals( true ); + + if( theColor.alpha() == 0 ) // transparent + myFillingTransparent->setChecked( true ); + else + myFillingColor->setChecked( true ); + + myFillingColorBox->setColor( theColor ); + + blockSignals( isBlocked ); + + onZoneDefChanged(); +} + +QColor HYDROGUI_ImmersibleZoneDlg::getFillingColor() const +{ + QColor aColor( 255, 255, 255, 0 ); // transparent + if( myFillingColor->isChecked() ) + aColor = myFillingColorBox->color(); + return aColor; +} + +void HYDROGUI_ImmersibleZoneDlg::setBorderColor( const QColor& theColor ) +{ + bool isBlocked = blockSignals( true ); + + bool isTransparent = theColor.alpha() == 0; + myBorderColorGroup->setChecked( !isTransparent ); + myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) ); + + blockSignals( isBlocked ); + + onZoneDefChanged(); +} + +QColor HYDROGUI_ImmersibleZoneDlg::getBorderColor() const +{ + QColor aColor( Qt::transparent ); // transparent + if( myBorderColorGroup->isChecked() ) + aColor = myBorderColorBox->color(); + return aColor; +} + +void HYDROGUI_ImmersibleZoneDlg::onFillingColorChanged() +{ + if ( !myFillingColor->isChecked() ) + return; + + onZoneDefChanged(); +} + +void HYDROGUI_ImmersibleZoneDlg::onZoneDefChanged() +{ + if ( signalsBlocked() ) + return; + + QString aPolylineName = getPolylineName(); + emit CreatePreview( aPolylineName ); +} + + diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneDlg.h b/src/HYDROGUI/HYDROGUI_ImmersibleZoneDlg.h new file mode 100644 index 00000000..548580e8 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneDlg.h @@ -0,0 +1,85 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_ImmersibleZoneDlg_H +#define HYDROGUI_ImmersibleZoneDlg_H + +#include "HYDROGUI_InputPanel.h" + +class HYDROGUI_ColorWidget; +class QComboBox; +class QGroupBox; +class QLineEdit; +class QListWidget; +class QRadioButton; + +class HYDROGUI_ImmersibleZoneDlg : public HYDROGUI_InputPanel +{ + Q_OBJECT + +public: + HYDROGUI_ImmersibleZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle ); + virtual ~HYDROGUI_ImmersibleZoneDlg(); + + void reset(); + + void setObjectName( const QString& theName ); + QString getObjectName() const; + + void setPolylineNames( const QStringList& thePolylines ); + void setPolylineName( const QString& thePolyline ); + QString getPolylineName() const; + + void setBathymetryNames( const QStringList& theBathymetries ); + void setBathymetryName( const QString& theBathymetry ); + QString getBathymetryName() const; + + void setFillingColor( const QColor& theColor ); + QColor getFillingColor() const; + + void setBorderColor( const QColor& theColor ); + QColor getBorderColor() const; + +signals: + void CreatePreview( const QString& thePolylineName ); + +private slots: + void onZoneDefChanged(); + void onFillingColorChanged(); + +private: + + QGroupBox* myObjectNameGroup; + QLineEdit* myObjectName; + + QComboBox* myPolylines; + QComboBox* myBathymetries; + + QRadioButton* myFillingTransparent; + QRadioButton* myFillingColor; + HYDROGUI_ColorWidget* myFillingColorBox; + + QGroupBox* myBorderColorGroup; + HYDROGUI_ColorWidget* myBorderColorBox; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx new file mode 100644 index 00000000..56ef1cd3 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx @@ -0,0 +1,281 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_ImmersibleZoneOp.h" + +#include "HYDROGUI_DataModel.h" +#include "HYDROGUI_ImmersibleZoneDlg.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Shape.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +HYDROGUI_ImmersibleZoneOp::HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule, + const bool theIsEdit ) +: HYDROGUI_Operation( theModule ), + myIsEdit( theIsEdit ), + myViewManager( 0 ), + myPreviewPrs( 0 ) +{ + setName( theIsEdit ? tr( "EDIT_IMMERSIBLE_ZONE" ) : tr( "CREATE_IMMERSIBLE_ZONE" ) ); +} + +HYDROGUI_ImmersibleZoneOp::~HYDROGUI_ImmersibleZoneOp() +{ + closePreview(); +} + +void HYDROGUI_ImmersibleZoneOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + aPanel->blockSignals( true ); + + aPanel->reset(); + + QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Zone" ); + + QColor aFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() ); + QColor aBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() ); + QString aSelectedPolyline, aSelectedBathymetry; + QStringList aSelectedBathymetries; + + if ( myIsEdit ) + { + myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if( !myEditedObject.IsNull() ) + { + anObjectName = myEditedObject->GetName(); + + aFillingColor = myEditedObject->GetFillingColor(); + aBorderColor = myEditedObject->GetBorderColor(); + + Handle(HYDROData_Polyline) aRefPolyline = myEditedObject->GetPolyline(); + if ( !aRefPolyline.IsNull() ) + aSelectedPolyline = aRefPolyline->GetName(); + + Handle(HYDROData_Bathymetry) aRefBathymetry = myEditedObject->GetBathymetry(); + if ( !aRefBathymetry.IsNull() ) + aSelectedBathymetry = aRefBathymetry->GetName(); + } + } + + // collect information about existing closed polylines + QStringList aPolylines; + + HYDROData_Iterator anIter( doc(), KIND_POLYLINE ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Polyline) aPolylineObj = + Handle(HYDROData_Polyline)::DownCast( anIter.Current() ); + if ( aPolylineObj.IsNull() || !aPolylineObj->IsClosed() ) + continue; + + QString aPolylineName = aPolylineObj->GetName(); + if ( aPolylineName.isEmpty() ) + continue; + + aPolylines.append( aPolylineName ); + } + + // collect information about existing bathymetries + QStringList aBathymetries; + + anIter = HYDROData_Iterator( doc(), KIND_BATHYMETRY ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Bathymetry) aBathymetryObj = + Handle(HYDROData_Bathymetry)::DownCast( anIter.Current() ); + if ( aBathymetryObj.IsNull() ) + continue; + + QString aBathymetryName = aBathymetryObj->GetName(); + if ( aBathymetryName.isEmpty() ) + continue; + + aBathymetries.append( aBathymetryName ); + } + + aPanel->setObjectName( anObjectName ); + + aPanel->setFillingColor( aFillingColor ); + aPanel->setBorderColor( aBorderColor ); + + aPanel->setPolylineNames( aPolylines ); + aPanel->setBathymetryNames( aBathymetries ); + + aPanel->blockSignals( false ); + + aPanel->setPolylineName( aSelectedPolyline ); + aPanel->setBathymetryName( aSelectedBathymetry ); +} + +void HYDROGUI_ImmersibleZoneOp::abortOperation() +{ + closePreview(); + + HYDROGUI_Operation::abortOperation(); +} + +void HYDROGUI_ImmersibleZoneOp::commitOperation() +{ + closePreview(); + + HYDROGUI_Operation::commitOperation(); +} + +HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const +{ + HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() ); + connect( aPanel, SIGNAL( CreatePreview( const QString& ) ), + this, SLOT( onCreatePreview( const QString& ) ) ); + return aPanel; +} + +bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags, + QString& theErrorMsg ) +{ + HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return false; + + QString anObjectName = aPanel->getObjectName().simplified(); + if ( anObjectName.isEmpty() ) + { + theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); + return false; + } + + if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) + { + // check that there are no other objects with the same name in the document + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); + if( !anObject.IsNull() ) + { + theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName ); + return false; + } + } + + Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject : + Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) ); + if ( aZoneObj.IsNull() ) + return false; + + Handle(HYDROData_Polyline) aZonePolyline; + Handle(HYDROData_Bathymetry) aZoneBathymetry; + + QString aPolylineName = aPanel->getPolylineName(); + if ( !aPolylineName.isEmpty() ) + { + aZonePolyline = Handle(HYDROData_Polyline)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) ); + } + + QString aBathymetryName = aPanel->getBathymetryName(); + if ( !aBathymetryName.isEmpty() ) + { + aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) ); + } + + aZoneObj->SetName( anObjectName ); + + aZoneObj->SetFillingColor( aPanel->getFillingColor() ); + aZoneObj->SetBorderColor( aPanel->getBorderColor() ); + + aZoneObj->SetPolyline( aZonePolyline ); + aZoneObj->SetBathymetry( aZoneBathymetry ); + + closePreview(); + + if( !myIsEdit ) + module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true ); + + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + + return true; +} + +void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName ) +{ + HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + TopoDS_Wire aWire; + + Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINE ) ); + if ( !aPolyline.IsNull() ) + { + aWire = TopoDS::Wire( aPolyline->GetTopShape() ); + } + + LightApp_Application* anApp = module()->getApp(); + if ( !myViewManager ) + myViewManager = ::qobject_cast( + anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ); + + if ( myViewManager && !myPreviewPrs ) + { + if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) + myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL ); + } + } + + if ( !myViewManager || !myPreviewPrs ) + return; + + myPreviewPrs->setFillingColor( aPanel->getFillingColor(), false, false ); + myPreviewPrs->setBorderColor( aPanel->getBorderColor(), false, false ); + myPreviewPrs->setFace( aWire ); +} + +void HYDROGUI_ImmersibleZoneOp::closePreview() +{ + if( myPreviewPrs ) + { + delete myPreviewPrs; + myPreviewPrs = 0; + } +} diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.h b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.h new file mode 100644 index 00000000..ba4410bd --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.h @@ -0,0 +1,66 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_ImmersibleZoneOp_H +#define HYDROGUI_ImmersibleZoneOp_H + +#include "HYDROGUI_Operation.h" + +#include + +class OCCViewer_ViewManager; + +class HYDROGUI_Shape; + +class HYDROGUI_ImmersibleZoneOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule, const bool theIsEdit ); + virtual ~HYDROGUI_ImmersibleZoneOp(); + +protected: + virtual void startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); + + virtual HYDROGUI_InputPanel* createInputPanel() const; + + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); + +protected slots: + void onCreatePreview( const QString& thePolylineName ); + +private: + void closePreview(); + +private: + bool myIsEdit; + Handle(HYDROData_ImmersibleZone) myEditedObject; + + OCCViewer_ViewManager* myViewManager; + + HYDROGUI_Shape* myPreviewPrs; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx index d902c7d3..2654523a 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx @@ -106,7 +106,7 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, } // check that there are no other objects with the same name in the document - Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); if ( !anObject.IsNull() ) { theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName ); diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 8e6cc231..6db63021 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -126,7 +126,7 @@ void HYDROGUI_ImportImageOp::startOperation() Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() ); if( !anImageObj.IsNull() ) { - if( myIsEdit && HYDROGUI_Tool::IsEqual( anImageObj, myEditedObject ) ) + if( myIsEdit && IsEqual( anImageObj, myEditedObject ) ) continue; QPoint aPointA1, aPointB1, aPointC1; @@ -193,7 +193,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) { // check that there are no other objects with the same name in the document - Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName ); + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName ); if( !anObject.IsNull() ) { theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName ); diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index cb2cd1c7..986dce2d 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include @@ -206,14 +206,14 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsMustBeUpdatedImage = false; bool anIsPolyline = false; bool anIsCalculation = false; - bool anIsZone = false; + bool anIsImmersibleZone = false; bool anIsVisualState = false; // check the selected data model objects HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this ); for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Object) anObject = aSeq.Value( anIndex ); + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); if( !anObject.IsNull() ) { anIsSelectedDataObjects = true; @@ -230,7 +230,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { anIsImportedImage = anImage->HasTrsfPoints() && !anImage->IsSelfSplitted(); anIsCompositeImage = anImage->NbReferences() > 0; - if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() ) + if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() ) { if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) ) { @@ -250,8 +250,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, anIsPolyline = true; else if( anObject->GetKind() == KIND_CALCULATION ) anIsCalculation = true; - else if( anObject->GetKind() == KIND_ZONE ) - anIsZone = true; + else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE ) + anIsImmersibleZone = true; else if( anObject->GetKind() == KIND_VISUAL_STATE ) anIsVisualState = true; } @@ -280,8 +280,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, case KIND_CALCULATION: theMenu->addAction( action( CreateCalculationId ) ); break; - case KIND_ZONE: - theMenu->addAction( action( CreateZoneId ) ); + case KIND_IMMERSIBLE_ZONE: + theMenu->addAction( action( CreateImmersibleZoneId ) ); break; } theMenu->addSeparator(); @@ -329,9 +329,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( EditCalculationId ) ); theMenu->addSeparator(); } - else if( anIsZone ) + else if( anIsImmersibleZone ) { - theMenu->addAction( action( EditZoneId ) ); + theMenu->addAction( action( EditImmersibleZoneId ) ); theMenu->addSeparator(); } else if( anIsVisualState && anIsObjectBrowser ) @@ -348,7 +348,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addSeparator(); } - if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsZone ) ) + if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsImmersibleZone ) ) { if( anIsHiddenInSelection ) theMenu->addAction( action( ShowId ) ); @@ -508,7 +508,7 @@ void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager, } bool HYDROGUI_Module::isObjectVisible( const int theViewId, - const Handle(HYDROData_Object)& theObject ) const + const Handle(HYDROData_Entity)& theObject ) const { if( theObject.IsNull() ) return false; @@ -528,7 +528,7 @@ bool HYDROGUI_Module::isObjectVisible( const int theViewId, } void HYDROGUI_Module::setObjectVisible( const int theViewId, - const Handle(HYDROData_Object)& theObject, + const Handle(HYDROData_Entity)& theObject, const bool theState ) { if( !theObject.IsNull() ) @@ -540,7 +540,7 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId, } HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId, - const Handle(HYDROData_Object)& theObject ) const + const Handle(HYDROData_Entity)& theObject ) const { HYDROGUI_Shape* aResShape = NULL; if( theObject.IsNull() ) @@ -563,7 +563,7 @@ HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int } void HYDROGUI_Module::setObjectShape( const int theViewId, - const Handle(HYDROData_Object)& theObject, + const Handle(HYDROData_Entity)& theObject, HYDROGUI_Shape* theShape ) { if( theObject.IsNull() ) @@ -574,7 +574,7 @@ void HYDROGUI_Module::setObjectShape( const int theViewId, } void HYDROGUI_Module::removeObjectShape( const int theViewId, - const Handle(HYDROData_Object)& theObject ) + const Handle(HYDROData_Entity)& theObject ) { if ( !myShapesMap.contains( theViewId ) ) return; diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index c4c1317e..3561ed1c 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -23,7 +23,7 @@ #ifndef HYDROGUI_MODULE_H #define HYDROGUI_MODULE_H -#include +#include #include @@ -111,19 +111,19 @@ public: const ViewManagerRole theRole ); bool isObjectVisible( const int theViewId, - const Handle(HYDROData_Object)& theObject ) const; + const Handle(HYDROData_Entity)& theObject ) const; void setObjectVisible( const int theViewId, - const Handle(HYDROData_Object)& theObject, + const Handle(HYDROData_Entity)& theObject, const bool theState ); HYDROGUI_Shape* getObjectShape( const int theViewId, - const Handle(HYDROData_Object)& theObject ) const; + const Handle(HYDROData_Entity)& theObject ) const; void setObjectShape( const int theViewId, - const Handle(HYDROData_Object)& theObject, + const Handle(HYDROData_Entity)& theObject, HYDROGUI_Shape* theShape ); void removeViewShapes( const int theViewId ); void removeObjectShape( const int theViewId, - const Handle(HYDROData_Object)& theObject ); + const Handle(HYDROData_Entity)& theObject ); protected: CAM_DataModel* createDataModel(); diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 8be446e4..0ab14c6b 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -55,7 +55,7 @@ void HYDROGUI_OCCDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theO for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if( anObj.IsNull() ) continue; @@ -106,7 +106,7 @@ void HYDROGUI_OCCDisplayer::Update( const HYDROData_SequenceOfObjects& theObjs, for( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - const Handle(HYDROData_Object)& anObj = theObjs.Value( i ); + const Handle(HYDROData_Entity)& anObj = theObjs.Value( i ); if( anObj.IsNull() ) anObjectsToErase.Append( anObj ); else @@ -128,7 +128,7 @@ void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if( anObj.IsNull() ) continue; @@ -138,7 +138,7 @@ void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int theViewerId, const Handle(AIS_InteractiveContext)& theContext, - const Handle(HYDROData_Object)& theObject ) + const Handle(HYDROData_Entity)& theObject ) { HYDROGUI_Shape* aResShape = NULL; if ( theContext.IsNull() || theObject.IsNull() ) @@ -147,6 +147,8 @@ HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int ObjectKind anObjectKind = theObject->GetKind(); if ( anObjectKind != KIND_IMAGE && anObjectKind != KIND_POLYLINE && + anObjectKind != KIND_IMMERSIBLE_ZONE && + anObjectKind != KIND_REGION && anObjectKind != KIND_ZONE ) return aResShape; @@ -170,7 +172,7 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if ( anObj.IsNull() || anObj->IsRemoved() ) continue; @@ -226,8 +228,8 @@ void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId ) if ( aPrsObj.IsNull() ) continue; - Handle(HYDROData_Object) anOwnerObj = - Handle(HYDROData_Object)::DownCast( aPrsObj->GetOwner() ); + Handle(HYDROData_Entity) anOwnerObj = + Handle(HYDROData_Entity)::DownCast( aPrsObj->GetOwner() ); if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() ) myModule->removeObjectShape( (size_t)aViewer, anOwnerObj ); } diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h index f4c013bb..f8d1ea13 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h @@ -23,7 +23,7 @@ #ifndef HYDROGUI_OCCDISPLAYER_H #define HYDROGUI_OCCDISPLAYER_H -#include +#include class HYDROGUI_Module; class HYDROGUI_Shape; @@ -125,7 +125,7 @@ private: */ HYDROGUI_Shape* createShape( const int theViewerId, const Handle(AIS_InteractiveContext)& theContext, - const Handle(HYDROData_Object)& theObject ); + const Handle(HYDROData_Entity)& theObject ); private: HYDROGUI_Module* myModule; diff --git a/src/HYDROGUI/HYDROGUI_OCCSelector.cxx b/src/HYDROGUI/HYDROGUI_OCCSelector.cxx index 24d8975b..3abc6754 100644 --- a/src/HYDROGUI/HYDROGUI_OCCSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCSelector.cxx @@ -70,8 +70,8 @@ QString HYDROGUI_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS if ( anAIS.IsNull() || !anAIS->HasOwner() ) return aRes; - Handle(HYDROData_Object) anObj = - Handle(HYDROData_Object)::DownCast( anAIS->GetOwner() ); + Handle(HYDROData_Entity) anObj = + Handle(HYDROData_Entity)::DownCast( anAIS->GetOwner() ); if ( !anObj.IsNull() ) aRes = HYDROGUI_DataObject::dataObjectEntry( anObj ); diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx index a79c1f6b..19ddb76e 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx @@ -99,7 +99,7 @@ void HYDROGUI_ObjSelector::OnSelectionChanged() return; QString anObjName; - Handle(HYDROData_Object) anObject = HYDROGUI_Tool::GetSelectedObject( myModule ); + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( myModule ); if( !anObject.IsNull() ) if( myObjectKind == KIND_UNKNOWN || myObjectKind == anObject->GetKind() ) anObjName = anObject->GetName(); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 706d9b75..31a9f34a 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -33,12 +33,12 @@ #include "HYDROGUI_ObserveImageOp.h" #include "HYDROGUI_PolylineOp.h" #include "HYDROGUI_ShowHideOp.h" -#include "HYDROGUI_SplitZonesTool.h" +#include "HYDROData_SplitToZonesTool.h" #include "HYDROGUI_TwoImagesOp.h" #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_UpdateImageOp.h" #include "HYDROGUI_VisualStateOp.h" -#include "HYDROGUI_ZoneOp.h" +#include "HYDROGUI_ImmersibleZoneOp.h" #include @@ -88,8 +88,8 @@ void HYDROGUI_Module::createActions() createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B ); - createAction( CreateZoneId, "CREATE_ZONE" ); - createAction( EditZoneId, "EDIT_ZONE" ); + createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" ); + createAction( EditImmersibleZoneId, "EDIT_ZONE" ); createAction( CreateCalculationId, "CREATE_CALCULATION" ); createAction( EditCalculationId, "EDIT_CALCULATION" ); @@ -131,7 +131,7 @@ void HYDROGUI_Module::createMenus() createMenu( ImportImageId, aHydroId, -1, -1 ); createMenu( ImportBathymetryId, aHydroId, -1, -1 ); createMenu( CreatePolylineId, aHydroId, -1, -1 ); - createMenu( CreateZoneId, aHydroId, -1, -1 ); + createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 ); createMenu( CreateCalculationId, aHydroId, -1, -1 ); createMenu( separator(), aHydroId ); createMenu( FuseImagesId, aHydroId, -1, -1 ); @@ -277,9 +277,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case ImportBathymetryId: anOp = new HYDROGUI_ImportBathymetryOp( aModule ); break; - case CreateZoneId: - case EditZoneId: - anOp = new HYDROGUI_ZoneOp( aModule, theId == EditZoneId ); + case CreateImmersibleZoneId: + case EditImmersibleZoneId: + anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId ); break; case CreateCalculationId: case EditCalculationId: diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index c8b8309f..959286e8 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -48,8 +48,8 @@ enum OperationId ImportBathymetryId, EditImportedBathymetryId, - CreateZoneId, - EditZoneId, + CreateImmersibleZoneId, + EditImmersibleZoneId, CreateCalculationId, EditCalculationId, diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index b1fc1e85..66a3ca9f 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -75,12 +75,12 @@ void HYDROGUI_PolylineOp::startOperation() myEditedObject = Handle(HYDROData_Polyline)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); if( !myEditedObject.IsNull() ) { - int anIntDim = myEditedObject->getDimension(); + int anIntDim = myEditedObject->GetDimension(); CurveCreator::Dimension aDim = CurveCreator::Dim3d; if( anIntDim == 2 ) aDim = CurveCreator::Dim2d; myCurve = new CurveCreator_Curve(aDim); - QList aPolylineData = myEditedObject->getPolylineData(); + QList aPolylineData = myEditedObject->GetPolylineData(); CurveCreator_CurveEditor* anEdit = new CurveCreator_CurveEditor(myCurve); for( int i = 0 ; i < aPolylineData.size() ; i++ ){ @@ -165,7 +165,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, int aDimInt = 3; if( myCurve->getDimension() == CurveCreator::Dim2d ) aDimInt = 2; - aPolylineObj->setDimension(aDimInt); + aPolylineObj->SetDimension(aDimInt); QList aPolylineData; for( int i=0 ; i < myCurve->getNbSections() ; i++ ){ PolylineSection aSect; @@ -181,7 +181,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, } aPolylineData << aSect; } - aPolylineObj->setPolylineData(aPolylineData); + aPolylineObj->SetPolylineData(aPolylineData); theUpdateFlags = UF_Model; module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true ); diff --git a/src/HYDROGUI/HYDROGUI_Prs.cxx b/src/HYDROGUI/HYDROGUI_Prs.cxx index 1ed451e3..d2f43b78 100644 --- a/src/HYDROGUI/HYDROGUI_Prs.cxx +++ b/src/HYDROGUI/HYDROGUI_Prs.cxx @@ -30,7 +30,7 @@ // name : HYDROGUI_Prs // Purpose : Constructor //======================================================================= -HYDROGUI_Prs::HYDROGUI_Prs( const Handle(HYDROData_Object)& theObject ) +HYDROGUI_Prs::HYDROGUI_Prs( const Handle(HYDROData_Entity)& theObject ) : GraphicsView_Object(), myObject( theObject ), myIsToUpdate( false ) diff --git a/src/HYDROGUI/HYDROGUI_Prs.h b/src/HYDROGUI/HYDROGUI_Prs.h index 6219f48b..871e30fa 100644 --- a/src/HYDROGUI/HYDROGUI_Prs.h +++ b/src/HYDROGUI/HYDROGUI_Prs.h @@ -23,7 +23,7 @@ #ifndef HYDROGUI_PRS_H #define HYDROGUI_PRS_H -#include +#include #include @@ -34,11 +34,11 @@ class HYDROGUI_Prs : public GraphicsView_Object { public: - HYDROGUI_Prs( const Handle(HYDROData_Object)& theObject ); + HYDROGUI_Prs( const Handle(HYDROData_Entity)& theObject ); virtual ~HYDROGUI_Prs(); public: - Handle(HYDROData_Object) getObject() const { return myObject; } + Handle(HYDROData_Entity) getObject() const { return myObject; } bool getIsToUpdate() const { return myIsToUpdate; } void setIsToUpdate( bool theState ) { myIsToUpdate = theState; } @@ -51,7 +51,7 @@ protected: QCursor* getHighlightCursor() const { return myHighlightCursor; } private: - Handle(HYDROData_Object) myObject; + Handle(HYDROData_Entity) myObject; bool myIsToUpdate; private: diff --git a/src/HYDROGUI/HYDROGUI_PrsDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsDriver.cxx index 4e13c1c5..38d8908d 100644 --- a/src/HYDROGUI/HYDROGUI_PrsDriver.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsDriver.cxx @@ -32,7 +32,7 @@ HYDROGUI_PrsDriver::~HYDROGUI_PrsDriver() { } -bool HYDROGUI_PrsDriver::Update( const Handle(HYDROData_Object)& theObj, +bool HYDROGUI_PrsDriver::Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ) { if ( thePrs ) diff --git a/src/HYDROGUI/HYDROGUI_PrsDriver.h b/src/HYDROGUI/HYDROGUI_PrsDriver.h index f73c0081..5356e464 100644 --- a/src/HYDROGUI/HYDROGUI_PrsDriver.h +++ b/src/HYDROGUI/HYDROGUI_PrsDriver.h @@ -23,7 +23,7 @@ #ifndef HYDROGUI_PRSDRIVER_H #define HYDROGUI_PRSDRIVER_H -#include +#include class HYDROGUI_Prs; @@ -53,7 +53,7 @@ public: * \param thePrs presentation * \return status of the operation */ - virtual bool Update( const Handle(HYDROData_Object)& theObj, + virtual bool Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ); }; diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.cxx b/src/HYDROGUI/HYDROGUI_PrsImage.cxx index 4a4ee5bb..9e7be142 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImage.cxx @@ -32,7 +32,7 @@ // name : HYDROGUI_PrsImage // Purpose : Constructor //======================================================================= -HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject ) +HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject ) : HYDROGUI_Prs( theObject ), myPixmapItem( 0 ), myCaptionItem( 0 ), diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.h b/src/HYDROGUI/HYDROGUI_PrsImage.h index c59218ff..c5d57981 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.h +++ b/src/HYDROGUI/HYDROGUI_PrsImage.h @@ -46,7 +46,7 @@ public: typedef QMapIterator< int, TransformationPoint > TransformationPointMapIterator; public: - HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject ); + HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject ); virtual ~HYDROGUI_PrsImage(); public: diff --git a/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx index cac25c91..ace70550 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx @@ -35,7 +35,7 @@ HYDROGUI_PrsImageDriver::~HYDROGUI_PrsImageDriver() { } -bool HYDROGUI_PrsImageDriver::Update( const Handle(HYDROData_Object)& theObj, +bool HYDROGUI_PrsImageDriver::Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ) { HYDROGUI_PrsDriver::Update( theObj, thePrs ); diff --git a/src/HYDROGUI/HYDROGUI_PrsImageDriver.h b/src/HYDROGUI/HYDROGUI_PrsImageDriver.h index 5da63d5b..4b369ed2 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImageDriver.h +++ b/src/HYDROGUI/HYDROGUI_PrsImageDriver.h @@ -49,7 +49,7 @@ public: * \param thePrs presentation * \return status of the operation */ - virtual bool Update( const Handle(HYDROData_Object)& theObj, + virtual bool Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ); }; diff --git a/src/HYDROGUI/HYDROGUI_PrsPolyline.cxx b/src/HYDROGUI/HYDROGUI_PrsPolyline.cxx index 57748202..19fa5330 100644 --- a/src/HYDROGUI/HYDROGUI_PrsPolyline.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsPolyline.cxx @@ -28,7 +28,7 @@ // name : HYDROGUI_PrsPolyline // Purpose : Constructor //======================================================================= -HYDROGUI_PrsPolyline::HYDROGUI_PrsPolyline( const Handle(HYDROData_Object)& theObject ) +HYDROGUI_PrsPolyline::HYDROGUI_PrsPolyline( const Handle(HYDROData_Entity)& theObject ) : HYDROGUI_Prs( theObject ), myPolylineItem( 0 ) { diff --git a/src/HYDROGUI/HYDROGUI_PrsPolyline.h b/src/HYDROGUI/HYDROGUI_PrsPolyline.h index 47dc3b23..a01359ec 100644 --- a/src/HYDROGUI/HYDROGUI_PrsPolyline.h +++ b/src/HYDROGUI/HYDROGUI_PrsPolyline.h @@ -32,7 +32,7 @@ class HYDROGUI_PrsPolyline : public HYDROGUI_Prs { public: - HYDROGUI_PrsPolyline( const Handle(HYDROData_Object)& theObject ); + HYDROGUI_PrsPolyline( const Handle(HYDROData_Entity)& theObject ); virtual ~HYDROGUI_PrsPolyline(); public: diff --git a/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx index 54a75540..5bb2ba29 100644 --- a/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx @@ -35,7 +35,7 @@ HYDROGUI_PrsPolylineDriver::~HYDROGUI_PrsPolylineDriver() { } -bool HYDROGUI_PrsPolylineDriver::Update( const Handle(HYDROData_Object)& theObj, +bool HYDROGUI_PrsPolylineDriver::Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ) { HYDROGUI_PrsDriver::Update( theObj, thePrs ); @@ -53,7 +53,7 @@ bool HYDROGUI_PrsPolylineDriver::Update( const Handle(HYDROData_Object)& theObj, HYDROGUI_PrsPolyline* aPrsPolyline = (HYDROGUI_PrsPolyline*)thePrs; aPrsPolyline->setName( aPolyline->GetName() ); - aPrsPolyline->setPath( aPolyline->painterPath() ); + aPrsPolyline->setPath( aPolyline->GetPainterPath() ); aPrsPolyline->compute(); diff --git a/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h index de6dde19..9160ff5c 100644 --- a/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h +++ b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h @@ -49,7 +49,7 @@ public: * \param thePrs presentation * \return status of the operation */ - virtual bool Update( const Handle(HYDROData_Object)& theObj, + virtual bool Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ); }; diff --git a/src/HYDROGUI/HYDROGUI_PrsZone.cxx b/src/HYDROGUI/HYDROGUI_PrsZone.cxx index fc857245..61661a73 100644 --- a/src/HYDROGUI/HYDROGUI_PrsZone.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsZone.cxx @@ -29,7 +29,7 @@ // name : HYDROGUI_PrsZone // Purpose : Constructor //======================================================================= -HYDROGUI_PrsZone::HYDROGUI_PrsZone( const Handle(HYDROData_Object)& theObject ) +HYDROGUI_PrsZone::HYDROGUI_PrsZone( const Handle(HYDROData_Entity)& theObject ) : HYDROGUI_Prs( theObject ), myZoneItem( 0 ), myFillingColor( Qt::transparent ), diff --git a/src/HYDROGUI/HYDROGUI_PrsZone.h b/src/HYDROGUI/HYDROGUI_PrsZone.h index 3c21dc39..586eb6f3 100644 --- a/src/HYDROGUI/HYDROGUI_PrsZone.h +++ b/src/HYDROGUI/HYDROGUI_PrsZone.h @@ -32,7 +32,7 @@ class HYDROGUI_PrsZone : public HYDROGUI_Prs { public: - HYDROGUI_PrsZone( const Handle(HYDROData_Object)& theObject ); + HYDROGUI_PrsZone( const Handle(HYDROData_Entity)& theObject ); virtual ~HYDROGUI_PrsZone(); public: diff --git a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx index 6d6aca2e..ef2e4e26 100644 --- a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx @@ -24,7 +24,7 @@ #include "HYDROGUI_PrsZone.h" -#include +#include HYDROGUI_PrsZoneDriver::HYDROGUI_PrsZoneDriver() :HYDROGUI_PrsDriver() @@ -35,7 +35,7 @@ HYDROGUI_PrsZoneDriver::~HYDROGUI_PrsZoneDriver() { } -bool HYDROGUI_PrsZoneDriver::Update( const Handle(HYDROData_Object)& theObj, +bool HYDROGUI_PrsZoneDriver::Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ) { HYDROGUI_PrsDriver::Update( theObj, thePrs ); @@ -43,7 +43,8 @@ bool HYDROGUI_PrsZoneDriver::Update( const Handle(HYDROData_Object)& theObj, if ( theObj.IsNull() ) return false; - Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( theObj ); + Handle(HYDROData_ImmersibleZone) aZone = + Handle(HYDROData_ImmersibleZone)::DownCast( theObj ); if ( aZone.IsNull() ) return false; diff --git a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.h b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.h index 0eb5dbc3..ef4b559e 100644 --- a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.h +++ b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.h @@ -49,7 +49,7 @@ public: * \param thePrs presentation * \return status of the operation */ - virtual bool Update( const Handle(HYDROData_Object)& theObj, + virtual bool Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_Prs*& thePrs ); }; diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 9d7ca4da..4eaecc51 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -36,10 +36,14 @@ #include #include -#include +#include #include +#include #include +#include +#include +#include #include #include @@ -53,7 +57,7 @@ #include HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext, - const Handle(HYDROData_Object)& theObject ) + const Handle(HYDROData_Entity)& theObject ) : myContext( theContext ), myObject( theObject ), myIsHighlight( false ), @@ -102,28 +106,64 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) // Try to retrieve information from object if ( !myObject.IsNull() ) { - if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Domain) ) ) + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject ); + + if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) ) { - Handle(HYDROData_Domain) aDomainObj = - Handle(HYDROData_Domain)::DownCast( myObject ); + Handle(HYDROData_ImmersibleZone) aZoneObj = + Handle(HYDROData_ImmersibleZone)::DownCast( myObject ); - QColor aFillingColor = aDomainObj->GetFillingColor(); - QColor aBorderColor = aDomainObj->GetBorderColor(); - TopoDS_Face aDomainFace = aDomainObj->Face(); + QColor aFillingColor = aZoneObj->GetFillingColor(); + QColor aBorderColor = aZoneObj->GetBorderColor(); + TopoDS_Face aZoneFace = TopoDS::Face( aZoneObj->GetTopShape() ); setFillingColor( aFillingColor, false, false ); setBorderColor( aBorderColor, false, false ); - setFace( aDomainFace, false, false ); + setFace( aZoneFace, false, false ); } else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline) ) ) { Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( myObject ); - TopoDS_Wire aPolylineWire = aPolyline->Wire(); + TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() ); setWire( aPolylineWire, false, false ); } + else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Region) ) ) + { + Handle(HYDROData_Region) aRegion = + Handle(HYDROData_Region)::DownCast( myObject ); + } + else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) ) + { + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( myObject ); + + TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() ); + + // Generate the filling color for zone + QStringList aGeomObjectsNames; + + HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Object) aRefbject = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( aRefbject.IsNull() ) + continue; + + QString aRefObjectName = aRefbject->GetName(); + if ( aRefObjectName.isEmpty() ) + continue; + + aGeomObjectsNames.append( aRefObjectName ); + } + + setFace( aZoneFace, false, false ); + setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) ); + } else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) ) { Handle(HYDROData_Image) anImageObj = @@ -441,7 +481,7 @@ void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor ) } } -QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Object)& theImageObj ) +QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ) { QString aResult; if( !theImageObj.IsNull() ) diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 6757079e..007c3e52 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include @@ -38,7 +38,7 @@ class HYDROGUI_Shape { public: HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext, - const Handle(HYDROData_Object)& theObject ); + const Handle(HYDROData_Entity)& theObject ); ~HYDROGUI_Shape(); public: @@ -48,7 +48,7 @@ public: virtual void highlight( bool theIsHighlight ); virtual bool isHighlighted() const; - Handle(HYDROData_Object) getObject() const { return myObject; } + Handle(HYDROData_Entity) getObject() const { return myObject; } virtual void update( const bool theIsUpdateViewer = true ); @@ -99,14 +99,14 @@ private: static double getQuantityColorVal( const int theColorVal ); void colorShapeBorder( const QColor& theColor ); - static QString generateTextureFileName( const Handle(HYDROData_Object)& theImageObj ); + static QString generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ); void removeTextureFile() const; static QImage reduceTexture( const QImage& theImage, const int theSizeLimit ); private: Handle(AIS_InteractiveContext) myContext; - Handle(HYDROData_Object) myObject; + Handle(HYDROData_Entity) myObject; Handle(AIS_TexturedShape) myShape; bool myIsToUpdate; diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index 064d7785..0fefdfae 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -30,7 +30,7 @@ #include "HYDROGUI_UpdateFlags.h" #include -#include +#include #include @@ -72,7 +72,7 @@ void HYDROGUI_ShowHideOp::startOperation() HYDROData_Iterator anIterator( doc() ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Object) anObject = anIterator.Current(); + Handle(HYDROData_Entity) anObject = anIterator.Current(); if( !anObject.IsNull() ) module()->setObjectVisible( aViewId, anObject, aVisibility ); } @@ -86,7 +86,7 @@ void HYDROGUI_ShowHideOp::startOperation() bool aVisibility = myId == ShowId || myId == ShowOnlyId; for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Object) anObject = aSeq.Value( anIndex ); + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); if( !anObject.IsNull() ) module()->setObjectVisible( aViewId, anObject, aVisibility ); } diff --git a/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx b/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx deleted file mode 100644 index 1a20f39d..00000000 --- a/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "HYDROGUI_SplitZonesTool.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -TopoDS_Face HYDROGUI_SplitZonesTool::SplitData::Face() const -{ - if( !Shape.IsNull() && Shape.ShapeType() == TopAbs_FACE ) - return TopoDS::Face( Shape ); - return TopoDS_Face(); -} - -HYDROGUI_SplitZonesTool::SplitDataList -HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneList, - const Handle(HYDROData_Polyline)& thePolyline ) -{ - SplitDataList anOutputSplitDataList; - - // Preparation. Collect the zone paths to split. - SplitDataList anInputSplitDataList; - for( int anIndex = 1, aLength = theZoneList.Length(); anIndex <= aLength; anIndex++ ) - { - Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( anIndex ) ); - if( !aZone.IsNull() ) - { - SplitData aSplitData( aZone->Face(), aZone->GetName() ); - anInputSplitDataList.append( aSplitData ); - } - } - - // Step 1. Split the paths. - SplitDataListIterator anInputIter( anInputSplitDataList ); - while( anInputIter.hasNext() ) - { - const SplitData& anInputSplitData = anInputIter.next(); - if( anOutputSplitDataList.isEmpty() ) - anOutputSplitDataList.append( anInputSplitData ); - else - { - SplitDataList aSplitDataList; - - SplitDataList aSrcSplitDataList; - aSrcSplitDataList.append( anInputSplitData ); - - SplitDataList aDestSplitDataList = anOutputSplitDataList; - anOutputSplitDataList.clear(); - - while( !aDestSplitDataList.isEmpty() ) - { - SplitData aSrcSplitData = aSrcSplitDataList.last(); - - SplitData aDestSplitData = aDestSplitDataList.first(); - aDestSplitDataList.pop_front(); - - SplitData aData1Subtracted, aData2Subtracted, aDataIntersected; - if( SplitTwoData( aSrcSplitData, aDestSplitData, - aData1Subtracted, aData2Subtracted, aDataIntersected ) ) - anOutputSplitDataList.append( aDataIntersected ); - anOutputSplitDataList.append( aData2Subtracted ); - aSrcSplitDataList.append( aData1Subtracted ); - } - - if( !aSrcSplitDataList.isEmpty() ) - anOutputSplitDataList.append( aSrcSplitDataList.last() ); - } - } - - // Step 2. Take into account the boundary polyline. - if( !thePolyline.IsNull() ) - { - const TopoDS_Wire& aWire = thePolyline->Wire(); - if( !aWire.IsNull() ) - { - BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True ); - aMakeFace.Build(); - if( aMakeFace.IsDone() ) - { - SplitData aBoundarySplitData( aMakeFace.Face(), "" ); - - SplitDataList aCutSplitDataList; - SplitDataListIterator anOutputIter( anOutputSplitDataList ); - while( anOutputIter.hasNext() ) - { - const SplitData& anOutputSplitData = anOutputIter.next(); - - SplitData aData1Subtracted, aData2Subtracted, aDataIntersected; - if( SplitTwoData( anOutputSplitData, aBoundarySplitData, - aData1Subtracted, aData2Subtracted, aDataIntersected ) ) - aCutSplitDataList.append( aDataIntersected ); - } - anOutputSplitDataList = aCutSplitDataList; - } - } - } - - // Step 3. Extract the separate regions. - SplitDataList anExtractedSplitDataList; - SplitDataListIterator anOutputIter( anOutputSplitDataList ); - while( anOutputIter.hasNext() ) - { - const SplitData& anOutputSplitData = anOutputIter.next(); - anExtractedSplitDataList.append( ExtractSeparateData( anOutputSplitData ) ); - } - return anExtractedSplitDataList; -} - -bool HYDROGUI_SplitZonesTool::SplitTwoData( const SplitData& theData1, - const SplitData& theData2, - SplitData& theData1Subtracted, - SplitData& theData2Subtracted, - SplitData& theDataIntersected ) -{ - const TopoDS_Shape& aShape1 = theData1.Shape; - const TopoDS_Shape& aShape2 = theData2.Shape; - - const QStringList& aZoneNames1 = theData1.ZoneNames; - const QStringList& aZoneNames2 = theData2.ZoneNames; - - BRepAlgoAPI_Common aCommon( aShape1, aShape2 ); - TopoDS_Shape aCommonShape = aCommon.Shape(); - if( aCommonShape.IsNull() ) - { - theData1Subtracted = theData1; - theData2Subtracted = theData2; - return false; - } - - BRepAlgoAPI_Cut aCut1( aShape1, aShape2 ); - TopoDS_Shape aCut1Shape = aCut1.Shape(); - - BRepAlgoAPI_Cut aCut2( aShape2, aShape1 ); - TopoDS_Shape aCut2Shape = aCut2.Shape(); - - theData1Subtracted = SplitData( aCut1Shape, aZoneNames1 ); - theData2Subtracted = SplitData( aCut2Shape, aZoneNames2 ); - theDataIntersected = SplitData( aCommonShape, aZoneNames1 + aZoneNames2 ); - - return true; -} - -HYDROGUI_SplitZonesTool::SplitDataList -HYDROGUI_SplitZonesTool::ExtractSeparateData( const SplitData& theData ) -{ - SplitDataList aSplitDataList; - TopExp_Explorer anExp( theData.Shape, TopAbs_FACE ); - for( ; anExp.More(); anExp.Next() ) - { - TopoDS_Shape aShape = anExp.Current(); - if( aShape.ShapeType() == TopAbs_FACE ) - { - TopoDS_Face aFace = TopoDS::Face( aShape ); - if( !aFace.IsNull() ) - { - SplitData aSplitData( aFace, theData.ZoneNames ); - aSplitDataList.append( aSplitData ); - } - } - } - return aSplitDataList; -} diff --git a/src/HYDROGUI/HYDROGUI_SplitZonesTool.h b/src/HYDROGUI/HYDROGUI_SplitZonesTool.h deleted file mode 100644 index ca74d3c5..00000000 --- a/src/HYDROGUI/HYDROGUI_SplitZonesTool.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef HYDROGUI_SPLITZONESTOOL_H -#define HYDROGUI_SPLITZONESTOOL_H - -#include - -#include - -#include - -class Handle(HYDROData_Polyline); - -/** - * \class HYDROGUI_SplitZonesTool - * \brief This class contains methods used for splitting zones - * into non-intersected regions. - */ -class HYDROGUI_SplitZonesTool -{ -public: - struct SplitData - { - TopoDS_Shape Shape; - QStringList ZoneNames; - - SplitData() {} - - SplitData( const TopoDS_Shape& theShape, - const QStringList& theZoneNames ) : - Shape( theShape ), ZoneNames( theZoneNames ) {} - - SplitData( const TopoDS_Shape& theShape, - const QString& theZoneName ) : - Shape( theShape ), ZoneNames( theZoneName ) {} - - TopoDS_Face Face() const; - }; - - typedef QList SplitDataList; - typedef QListIterator SplitDataListIterator; - -public: - static SplitDataList SplitZones( const HYDROData_SequenceOfObjects& theZoneList, - const Handle(HYDROData_Polyline)& thePolyline ); - -private: - static bool SplitTwoData( const SplitData& theData1, - const SplitData& theData2, - SplitData& theData1Subtracted, - SplitData& theData2Subtracted, - SplitData& theDataIntersected ); - - static SplitDataList ExtractSeparateData( const SplitData& theData ); -}; - -#endif diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 67abb156..6fa0a831 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -29,7 +29,8 @@ #include #include -#include +#include +#include #include @@ -185,14 +186,6 @@ QString HYDROGUI_Tool::GetTempDir( const bool theToCreate ) return aRes; } -bool HYDROGUI_Tool::IsEqual( const Handle(HYDROData_Object)& theObj1, - const Handle(HYDROData_Object)& theObj2 ) -{ - if( !theObj1.IsNull() && !theObj2.IsNull() ) - return theObj1->Label() == theObj2->Label(); //ouv: check that the names can be used here - return false; -} - void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule, SUIT_ViewManager* theViewManager ) { @@ -213,7 +206,7 @@ void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule, HYDROData_Iterator anIterator( aDocument, KIND_IMAGE ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Object) anObject = anIterator.Current(); + Handle(HYDROData_Entity) anObject = anIterator.Current(); if( !anObject.IsNull() ) theSeq.Append( anObject ); } @@ -221,21 +214,21 @@ void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule, anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Object) anObject = anIterator.Current(); + Handle(HYDROData_Entity) anObject = anIterator.Current(); if( !anObject.IsNull() ) theSeq.Append( anObject ); } - anIterator = HYDROData_Iterator( aDocument, KIND_ZONE ); + anIterator = HYDROData_Iterator( aDocument, KIND_IMMERSIBLE_ZONE ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Object) anObject = anIterator.Current(); + Handle(HYDROData_Entity) anObject = anIterator.Current(); if( !anObject.IsNull() ) theSeq.Append( anObject ); } } -HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Object)& theObj, +HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Entity)& theObj, const GraphicsView_ObjectList& theObjects ) { if( !theObj.IsNull() ) @@ -245,7 +238,7 @@ HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Object)& th { if( HYDROGUI_Prs* aPrs = dynamic_cast( anIter.next() ) ) { - Handle(HYDROData_Object) anObj = aPrs->getObject(); + Handle(HYDROData_Entity) anObj = aPrs->getObject(); if( IsEqual( anObj, theObj ) ) return aPrs; } @@ -282,7 +275,7 @@ HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module* { if( LightApp_DataOwner* anOwner = dynamic_cast( aSUITOwner ) ) { - Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() ); + Handle(HYDROData_Entity) anObject = aModel->objectByEntry( anOwner->entry() ); if( !anObject.IsNull() ) { QString aName = anObject->GetName(); @@ -297,7 +290,7 @@ HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module* return aSeq; } -Handle(HYDROData_Object) HYDROGUI_Tool::GetSelectedObject( HYDROGUI_Module* theModule ) +Handle(HYDROData_Entity) HYDROGUI_Tool::GetSelectedObject( HYDROGUI_Module* theModule ) { HYDROData_SequenceOfObjects aSeq = GetSelectedObjects( theModule ); if( !aSeq.IsEmpty() ) @@ -331,79 +324,28 @@ ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule ) return KIND_UNKNOWN; } -Handle(HYDROData_Object) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule, +Handle(HYDROData_Entity) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule, const QString& theName, const ObjectKind theObjectKind ) { - Handle(HYDROData_Object) anObject; - if ( theName.isEmpty() ) - return anObject; - - QStringList aNamesList; - aNamesList << theName; - - HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theModule, aNamesList, theObjectKind ); - if( aSeqOfObjs.IsEmpty() ) - return anObject; - - anObject = aSeqOfObjs.First(); - return anObject; + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); + return HYDROData_Tool::FindObjectByName( aDocument, theName, theObjectKind ); } HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module* theModule, const QStringList& theNames, const ObjectKind theObjectKind ) { - HYDROData_SequenceOfObjects aResSeq; - if ( theNames.isEmpty() ) - return aResSeq; - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); - if( aDocument.IsNull() ) - return aResSeq; - - QStringList aNamesList = theNames; - - HYDROData_Iterator anIter( aDocument, theObjectKind ); - for( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Object) anObjectRef = anIter.Current(); - if( anObjectRef.IsNull() ) - continue; - - QString anObjName = anObjectRef->GetName(); - if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) ) - continue; - - aResSeq.Append( anObjectRef ); - - aNamesList.removeAll( anObjName ); - if ( aNamesList.isEmpty() ) - break; - } - - return aResSeq; + return HYDROData_Tool::FindObjectsByNames( aDocument, theNames, theObjectKind ); } QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule, const QString& thePrefix, const QStringList& theUsedNames ) { - QString aName; - int anId = 1; - while( anId < 100 ) - { - aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) ); - - if ( theUsedNames.contains( aName ) ) - continue; - - // check that there are no other objects with the same name in the document - Handle(HYDROData_Object) anObject = FindObjectByName( theModule, aName, KIND_UNKNOWN ); - if( anObject.IsNull() ) - break; - } - return aName; + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); + return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames ); } size_t HYDROGUI_Tool::GetActiveViewId( HYDROGUI_Module* theModule, @@ -466,7 +408,7 @@ void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Image)& theImage for( int anIndex = 0, aNbRef = theImage->NbReferences(); anIndex < aNbRef; anIndex++ ) { - Handle(HYDROData_Object) aRefObj = theImage->Reference( anIndex ); + Handle(HYDROData_Entity) aRefObj = theImage->Reference( anIndex ); if( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) { QString aName = aRefObj->GetName(); @@ -486,7 +428,7 @@ void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Image)& theImage } void HYDROGUI_Tool::GetObjectBackReferences( HYDROGUI_Module* theModule, - const Handle(HYDROData_Object)& theObj, + const Handle(HYDROData_Entity)& theObj, HYDROData_SequenceOfObjects& theBackRefObjects, QStringList& theBackRefNames ) { @@ -536,7 +478,14 @@ QDockWidget* HYDROGUI_Tool::WindowDock( QWidget* wid ) QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module* theModule, const QStringList& theZoneNames ) { - QColor aFillingColor( HYDROData_Zone::DefaultFillingColor() ); + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); + return GenerateFillingColor( aDocument, theZoneNames ); +} + +QColor HYDROGUI_Tool::GenerateFillingColor( const Handle(HYDROData_Document)& theDoc, + const QStringList& theZoneNames ) +{ + QColor aFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() ); int aCounter = 0; int aR = 0, aG = 0, aB = 0; @@ -544,8 +493,9 @@ QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module* theModule, while( aZoneNameIter.hasNext() ) { const QString& aZoneName = aZoneNameIter.next(); - Handle(HYDROData_Zone) aRefZone = Handle(HYDROData_Zone)::DownCast( - FindObjectByName( theModule, aZoneName, KIND_ZONE ) ); + Handle(HYDROData_ImmersibleZone) aRefZone = + Handle(HYDROData_ImmersibleZone)::DownCast( + HYDROData_Tool::FindObjectByName( theDoc, aZoneName, KIND_IMMERSIBLE_ZONE ) ); if( !aRefZone.IsNull() ) { QColor aRefColor = aRefZone->GetFillingColor(); diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 869dd4d2..1874513a 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -40,6 +40,7 @@ class HYDROGUI_Module; class HYDROGUI_Prs; class QDockWidget; +class Handle(HYDROData_Document); /** * \class HYDROGUI_Tool @@ -101,14 +102,6 @@ public: */ static QString GetTempDir( const bool theToCreate ); - /** - * \brief Check that the specified objects are equal. - * \param theObj1 first object - * \param theObj2 second object - */ - static bool IsEqual( const Handle(HYDROData_Object)& theObj1, - const Handle(HYDROData_Object)& theObj2 ); - /** * \brief Set the specified view manager to be active on the desktop. * \param theModule module @@ -131,7 +124,7 @@ public: * \param theObjects list of existing presentations * \return presentation */ - static HYDROGUI_Prs* GetPresentation( const Handle(HYDROData_Object)& theObj, + static HYDROGUI_Prs* GetPresentation( const Handle(HYDROData_Entity)& theObj, const GraphicsView_ObjectList& theObjects ); /** @@ -153,7 +146,7 @@ public: * \param theModule module * \return selected data object */ - static Handle(HYDROData_Object) GetSelectedObject( HYDROGUI_Module* theModule ); + static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule ); /** * \brief Get kind of objects the selected partition contains. @@ -169,7 +162,7 @@ public: * \param theObjectKind kind of object * \return data object */ - static Handle(HYDROData_Object) FindObjectByName( HYDROGUI_Module* theModule, + static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule, const QString& theName, const ObjectKind theObjectKind = KIND_UNKNOWN ); @@ -249,7 +242,7 @@ public: * \param theBackRefNames list of back-reference object names */ static void GetObjectBackReferences( HYDROGUI_Module* theModule, - const Handle(HYDROData_Object)& theObj, + const Handle(HYDROData_Entity)& theObj, HYDROData_SequenceOfObjects& theBackRefObjects, QStringList& theBackRefNames ); @@ -269,6 +262,15 @@ public: static QColor GenerateFillingColor( HYDROGUI_Module* theModule, const QStringList& theZoneNames ); + /* + * \brief Generates the filling color for intersected zone + * \param theDoc model document + * \param theZoneNames list of intersected zones + * \return result color + */ + static QColor GenerateFillingColor( const Handle(HYDROData_Document)& theDoc, + const QStringList& theZoneNames ); + }; #endif diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index d946766c..38375491 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -103,19 +103,19 @@ void HYDROGUI_TwoImagesOp::startOperation() { if( myEditedObject->NbReferences() > 0 ) { - Handle(HYDROData_Object) anObject1 = myEditedObject->Reference( 0 ); + Handle(HYDROData_Entity) anObject1 = myEditedObject->Reference( 0 ); if( !anObject1.IsNull() ) aSelectedName1 = anObject1->GetName(); } if( myEditedObject->NbReferences() > 1 ) { - Handle(HYDROData_Object) anObject2 = myEditedObject->Reference( 1 ); + Handle(HYDROData_Entity) anObject2 = myEditedObject->Reference( 1 ); if( !anObject2.IsNull() ) aSelectedName2 = anObject2->GetName(); } aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 ); - HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); + HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) ) { QColor aColor; @@ -154,7 +154,7 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) ) { // check that there are no other objects with the same name in the document - Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName ); + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName ); if( !anObject.IsNull() ) { theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName ); @@ -162,14 +162,14 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, } } - Handle(HYDROData_Object) anObject1 = Handle(HYDROData_Object)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ); - Handle(HYDROData_Object) anObject2 = Handle(HYDROData_Object)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN ) ); + Handle(HYDROData_Entity) anObject1 = + HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ; + Handle(HYDROData_Entity) anObject2 = + HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN ); if( anObject1.IsNull() || anObject2.IsNull() ) return false; - HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); + HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); Handle(HYDROData_Image) aResult; ImageComposer_Operator* anOperator = 0; diff --git a/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx b/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx index 90a79828..0cb4447b 100644 --- a/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx +++ b/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx @@ -137,7 +137,7 @@ bool HYDROGUI_VisualStateOp::saveVisualState() for( int anObjIndex = 1, aLength = aSeq.Length(); anObjIndex <= aLength; anObjIndex++ ) { - Handle(HYDROData_Object) anObject = aSeq.Value( anObjIndex ); + Handle(HYDROData_Entity) anObject = aSeq.Value( anObjIndex ); if( !anObject.IsNull() ) { // Format: "Name|Visibility[|CoordX|CoordY]" @@ -243,7 +243,7 @@ bool HYDROGUI_VisualStateOp::loadVisualState() for( int anObjIndex = 1, aLength = aSeq.Length(); anObjIndex <= aLength; anObjIndex++ ) { - Handle(HYDROData_Object) anObject = aSeq.Value( anObjIndex ); + Handle(HYDROData_Entity) anObject = aSeq.Value( anObjIndex ); if( !anObject.IsNull() ) { QString aName = anObject->GetName(); diff --git a/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx b/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx deleted file mode 100644 index 1806765e..00000000 --- a/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx +++ /dev/null @@ -1,305 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "HYDROGUI_ZoneDlg.h" - -#include "HYDROGUI_ColorWidget.h" -#include "HYDROGUI_Tool.h" - -#include -#include -#include -#include -#include -#include -#include - -HYDROGUI_ZoneDlg::HYDROGUI_ZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle ) -: HYDROGUI_InputPanel( theModule, theTitle ) -{ - // Zone name - myObjectNameGroup = new QGroupBox( tr( "ZONE_NAME" ), mainFrame() ); - - myObjectName = new QLineEdit( myObjectNameGroup ); - - QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup ); - aNameLayout->setMargin( 5 ); - aNameLayout->setSpacing( 5 ); - aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) ); - aNameLayout->addWidget( myObjectName ); - - - QGroupBox* aParamGroup = new QGroupBox( tr( "ZONE_PARAMETERS" ), mainFrame() ); - - QFrame* aPolylineFrame = new QFrame( aParamGroup ); - - myPolylines = new QComboBox( aPolylineFrame ); - myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - - QBoxLayout* aPolyLayout = new QHBoxLayout( aPolylineFrame ); - aPolyLayout->setMargin( 0 ); - aPolyLayout->setSpacing( 5 ); - aPolyLayout->addWidget( new QLabel( tr( "ZONE_POLYLINE" ), aPolylineFrame ) ); - aPolyLayout->addWidget( myPolylines ); - - - QFrame* aFillingFrame = new QFrame( aParamGroup ); - QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame ); - myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame ); - myFillingTransparent->setChecked( true ); - myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame ); - myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame ); - - QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame ); - aFillingLayout->setMargin( 0 ); - aFillingLayout->setSpacing( 5 ); - aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 ); - aFillingLayout->addWidget( myFillingTransparent, 0, 1 ); - aFillingLayout->addWidget( myFillingColor, 1, 1 ); - aFillingLayout->addWidget( myFillingColorBox, 1, 2 ); - - - myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), mainFrame() ); - myBorderColorGroup->setCheckable( true ); - - myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup ); - - QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup ); - aBorderColorLayout->setMargin( 5 ); - aBorderColorLayout->setSpacing( 5 ); - aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) ); - aBorderColorLayout->addWidget( myBorderColorBox ); - - - QBoxLayout* aParamLayout = new QVBoxLayout( aParamGroup ); - aParamLayout->setMargin( 5 ); - aParamLayout->setSpacing( 5 ); - aParamLayout->addWidget( aPolylineFrame ); - aParamLayout->addWidget( aFillingFrame ); - aParamLayout->addWidget( myBorderColorGroup ); - - - QGroupBox* aBathGroup = new QGroupBox( tr( "ZONE_BATHYMETRIES" ), mainFrame() ); - - myBathymetries = new QListWidget( aBathGroup ); - myBathymetries->setSelectionMode( QListWidget::SingleSelection ); - myBathymetries->setEditTriggers( QListWidget::NoEditTriggers ); - myBathymetries->setViewMode( QListWidget::ListMode ); - - QBoxLayout* aBathLayout = new QHBoxLayout( aBathGroup ); - aBathLayout->setMargin( 5 ); - aBathLayout->setSpacing( 5 ); - aBathLayout->addWidget( myBathymetries ); - - - // Common - addWidget( myObjectNameGroup ); - addWidget( aParamGroup ); - addWidget( aBathGroup ); - - addStretch(); - - - // Connect signals and slots - connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) ); - connect( myFillingTransparent, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); - connect( myFillingColor, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); - connect( myFillingColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onFillingColorChanged() ) ); - connect( myBorderColorGroup, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); - connect( myBorderColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onZoneDefChanged() ) ); -} - -HYDROGUI_ZoneDlg::~HYDROGUI_ZoneDlg() -{ -} - -void HYDROGUI_ZoneDlg::reset() -{ - bool isBlocked = blockSignals( true ); - - myObjectName->clear(); - - myPolylines->clear(); - myBathymetries->clear(); - - myFillingTransparent->setChecked( true ); - myFillingColorBox->resetColor(); - - myBorderColorGroup->setChecked( false ); - myBorderColorBox->resetColor(); - - blockSignals( isBlocked ); - - onZoneDefChanged(); -} - -void HYDROGUI_ZoneDlg::setObjectName( const QString& theName ) -{ - myObjectName->setText( theName ); -} - -QString HYDROGUI_ZoneDlg::getObjectName() const -{ - return myObjectName->text(); -} - -void HYDROGUI_ZoneDlg::setPolylineNames( const QStringList& thePolylines ) -{ - bool isBlocked = blockSignals( true ); - - myPolylines->clear(); - myPolylines->addItems( thePolylines ); - - blockSignals( isBlocked ); -} - -void HYDROGUI_ZoneDlg::setPolylineName( const QString& theName ) -{ - int aNewIdx = myPolylines->findText( theName ); - if ( aNewIdx != myPolylines->currentIndex() ) - { - myPolylines->setCurrentIndex( aNewIdx ); - } - else - { - onZoneDefChanged(); - } -} - -QString HYDROGUI_ZoneDlg::getPolylineName() const -{ - return myPolylines->currentText(); -} - -void HYDROGUI_ZoneDlg::setBathymetries( const QStringList& theBathymetries ) -{ - myBathymetries->clear(); - - for ( int i = 0, n = theBathymetries.length(); i < n; ++i ) - { - QString aBathymetryName = theBathymetries.at( i ); - - QListWidgetItem* aListItem = new QListWidgetItem( aBathymetryName, myBathymetries ); - aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable ); - aListItem->setCheckState( Qt::Unchecked ); - } -} - -void HYDROGUI_ZoneDlg::setSelectedBathymetries( const QStringList& theBathymetries ) -{ - for ( int i = 0, n = theBathymetries.length(); i < n; ++i ) - { - QString aBathymetryName = theBathymetries.at( i ); - - QList anItems = - myBathymetries->findItems( aBathymetryName, Qt::MatchFixedString | Qt::MatchCaseSensitive ); - if ( anItems.isEmpty() ) - continue; - - QListWidgetItem* aListItem = anItems.first(); - if ( !aListItem ) - continue; - - aListItem->setCheckState( Qt::Checked ); - } -} - -QStringList HYDROGUI_ZoneDlg::getSelectedBathymetries() const -{ - QStringList aResList; - - for ( int i = 0, n = myBathymetries->count(); i < n; ++i ) - { - QListWidgetItem* aListItem = myBathymetries->item( i ); - if ( !aListItem || aListItem->checkState() != Qt::Checked ) - continue; - - QString aSelBathName = aListItem->text(); - aResList.append( aSelBathName ); - } - - return aResList; -} - -void HYDROGUI_ZoneDlg::setFillingColor( const QColor& theColor ) -{ - bool isBlocked = blockSignals( true ); - - if( theColor.alpha() == 0 ) // transparent - myFillingTransparent->setChecked( true ); - else - myFillingColor->setChecked( true ); - - myFillingColorBox->setColor( theColor ); - - blockSignals( isBlocked ); - - onZoneDefChanged(); -} - -QColor HYDROGUI_ZoneDlg::getFillingColor() const -{ - QColor aColor( 255, 255, 255, 0 ); // transparent - if( myFillingColor->isChecked() ) - aColor = myFillingColorBox->color(); - return aColor; -} - -void HYDROGUI_ZoneDlg::setBorderColor( const QColor& theColor ) -{ - bool isBlocked = blockSignals( true ); - - bool isTransparent = theColor.alpha() == 0; - myBorderColorGroup->setChecked( !isTransparent ); - myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) ); - - blockSignals( isBlocked ); - - onZoneDefChanged(); -} - -QColor HYDROGUI_ZoneDlg::getBorderColor() const -{ - QColor aColor( Qt::transparent ); // transparent - if( myBorderColorGroup->isChecked() ) - aColor = myBorderColorBox->color(); - return aColor; -} - -void HYDROGUI_ZoneDlg::onFillingColorChanged() -{ - if ( !myFillingColor->isChecked() ) - return; - - onZoneDefChanged(); -} - -void HYDROGUI_ZoneDlg::onZoneDefChanged() -{ - if ( signalsBlocked() ) - return; - - QString aPolylineName = getPolylineName(); - emit CreatePreview( aPolylineName ); -} - - diff --git a/src/HYDROGUI/HYDROGUI_ZoneDlg.h b/src/HYDROGUI/HYDROGUI_ZoneDlg.h deleted file mode 100644 index ad70cb5e..00000000 --- a/src/HYDROGUI/HYDROGUI_ZoneDlg.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef HYDROGUI_ZONEDLG_H -#define HYDROGUI_ZONEDLG_H - -#include "HYDROGUI_InputPanel.h" - -class HYDROGUI_ColorWidget; -class QComboBox; -class QGroupBox; -class QLineEdit; -class QListWidget; -class QRadioButton; - -class HYDROGUI_ZoneDlg : public HYDROGUI_InputPanel -{ - Q_OBJECT - -public: - HYDROGUI_ZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle ); - virtual ~HYDROGUI_ZoneDlg(); - - void reset(); - - void setObjectName( const QString& theName ); - QString getObjectName() const; - - void setPolylineNames( const QStringList& thePolylines ); - void setPolylineName( const QString& thePolyline ); - QString getPolylineName() const; - - void setBathymetries( const QStringList& theBathymetries ); - void setSelectedBathymetries( const QStringList& theBathymetries ); - QStringList getSelectedBathymetries() const; - - void setFillingColor( const QColor& theColor ); - QColor getFillingColor() const; - - void setBorderColor( const QColor& theColor ); - QColor getBorderColor() const; - -signals: - void CreatePreview( const QString& thePolylineName ); - -private slots: - void onZoneDefChanged(); - void onFillingColorChanged(); - -private: - - QGroupBox* myObjectNameGroup; - QLineEdit* myObjectName; - - QComboBox* myPolylines; - QListWidget* myBathymetries; - - QRadioButton* myFillingTransparent; - QRadioButton* myFillingColor; - HYDROGUI_ColorWidget* myFillingColorBox; - - QGroupBox* myBorderColorGroup; - HYDROGUI_ColorWidget* myBorderColorBox; -}; - -#endif diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ZoneOp.cxx deleted file mode 100644 index e6daf5f8..00000000 --- a/src/HYDROGUI/HYDROGUI_ZoneOp.cxx +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "HYDROGUI_ZoneOp.h" - -#include "HYDROGUI_DataModel.h" -#include "HYDROGUI_ZoneDlg.h" -#include "HYDROGUI_Module.h" -#include "HYDROGUI_Shape.h" -#include "HYDROGUI_Tool.h" -#include "HYDROGUI_UpdateFlags.h" - -#include -#include -#include - -#include -#include - -#include -#include - -#include - -HYDROGUI_ZoneOp::HYDROGUI_ZoneOp( HYDROGUI_Module* theModule, - const bool theIsEdit ) -: HYDROGUI_Operation( theModule ), - myIsEdit( theIsEdit ), - myViewManager( 0 ), - myPreviewPrs( 0 ) -{ - setName( theIsEdit ? tr( "EDIT_ZONE" ) : tr( "CREATE_ZONE" ) ); -} - -HYDROGUI_ZoneOp::~HYDROGUI_ZoneOp() -{ - closePreview(); -} - -void HYDROGUI_ZoneOp::startOperation() -{ - HYDROGUI_Operation::startOperation(); - - HYDROGUI_ZoneDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) - return; - - aPanel->blockSignals( true ); - - aPanel->reset(); - - QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Zone" ); - - QColor aFillingColor( HYDROData_Zone::DefaultFillingColor() ); - QColor aBorderColor( HYDROData_Zone::DefaultBorderColor() ); - QString aSelectedPolyline; - QStringList aSelectedBathymetries; - - if ( myIsEdit ) - { - myEditedObject = Handle(HYDROData_Zone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - if( !myEditedObject.IsNull() ) - { - anObjectName = myEditedObject->GetName(); - - aFillingColor = myEditedObject->GetFillingColor(); - aBorderColor = myEditedObject->GetBorderColor(); - - Handle(HYDROData_Polyline) aRefPolyline = myEditedObject->GetPolyline(); - if ( !aRefPolyline.IsNull() ) - aSelectedPolyline = aRefPolyline->GetName(); - - HYDROData_SequenceOfObjects aRefBathymetries = myEditedObject->GetBathymetries(); - HYDROData_SequenceOfObjects::Iterator anIter( aRefBathymetries ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Bathymetry) aRefBathymetry = - Handle(HYDROData_Bathymetry)::DownCast( anIter.Value() ); - if ( aRefBathymetry.IsNull() ) - continue; - - QString aRefBathymetryName = aRefBathymetry->GetName(); - if ( aRefBathymetryName.isEmpty() ) - continue; - - aSelectedBathymetries.append( aRefBathymetryName ); - } - } - } - - // collect information about existing closed polylines - QStringList aPolylines; - - HYDROData_Iterator anIter( doc(), KIND_POLYLINE ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Polyline) aPolylineObj = - Handle(HYDROData_Polyline)::DownCast( anIter.Current() ); - if ( aPolylineObj.IsNull() || !aPolylineObj->isClosed() ) - continue; - - QString aPolylineName = aPolylineObj->GetName(); - if ( aPolylineName.isEmpty() ) - continue; - - aPolylines.append( aPolylineName ); - } - - // collect information about existing bathymetries - QStringList aBathymetries; - - anIter = HYDROData_Iterator( doc(), KIND_BATHYMETRY ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Bathymetry) aBathymetryObj = - Handle(HYDROData_Bathymetry)::DownCast( anIter.Current() ); - if ( aBathymetryObj.IsNull() ) - continue; - - QString aBathymetryName = aBathymetryObj->GetName(); - if ( aBathymetryName.isEmpty() ) - continue; - - aBathymetries.append( aBathymetryName ); - } - - aPanel->setObjectName( anObjectName ); - - aPanel->setFillingColor( aFillingColor ); - aPanel->setBorderColor( aBorderColor ); - - aPanel->setPolylineNames( aPolylines ); - - aPanel->setBathymetries( aBathymetries ); - aPanel->setSelectedBathymetries( aSelectedBathymetries ); - - aPanel->blockSignals( false ); - - aPanel->setPolylineName( aSelectedPolyline ); - -} - -void HYDROGUI_ZoneOp::abortOperation() -{ - closePreview(); - - HYDROGUI_Operation::abortOperation(); -} - -void HYDROGUI_ZoneOp::commitOperation() -{ - closePreview(); - - HYDROGUI_Operation::commitOperation(); -} - -HYDROGUI_InputPanel* HYDROGUI_ZoneOp::createInputPanel() const -{ - HYDROGUI_ZoneDlg* aPanel = new HYDROGUI_ZoneDlg( module(), getName() ); - connect( aPanel, SIGNAL( CreatePreview( const QString& ) ), - this, SLOT( onCreatePreview( const QString& ) ) ); - return aPanel; -} - -bool HYDROGUI_ZoneOp::processApply( int& theUpdateFlags, - QString& theErrorMsg ) -{ - HYDROGUI_ZoneDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) - return false; - - QString anObjectName = aPanel->getObjectName().simplified(); - if ( anObjectName.isEmpty() ) - { - theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); - return false; - } - - if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) - { - // check that there are no other objects with the same name in the document - Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); - if( !anObject.IsNull() ) - { - theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName ); - return false; - } - } - - Handle(HYDROData_Zone) aZoneObj = myIsEdit ? myEditedObject : - Handle(HYDROData_Zone)::DownCast( doc()->CreateObject( KIND_ZONE ) ); - if ( aZoneObj.IsNull() ) - return false; - - aZoneObj->SetName( anObjectName ); - - aZoneObj->SetFillingColor( aPanel->getFillingColor() ); - aZoneObj->SetBorderColor( aPanel->getBorderColor() ); - - Handle(HYDROData_Polyline) aZonePolyline; - - QString aPolylineName = aPanel->getPolylineName(); - if ( !aPolylineName.isEmpty() ) - { - aZonePolyline = Handle(HYDROData_Polyline)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) ); - } - - aZoneObj->SetPolyline( aZonePolyline ); - - - aZoneObj->RemoveBathymetries(); - - QStringList aBathymetries = aPanel->getSelectedBathymetries(); - for ( int i = 0; i < aBathymetries.length(); ++i ) - { - const QString& aBathymetryName = aBathymetries.at( i ); - if ( aBathymetryName.isEmpty() ) - continue; - - Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) ); - if ( aBathymetry.IsNull() ) - continue; - - aZoneObj->AddBathymetry( aBathymetry ); - } - - closePreview(); - - if( !myIsEdit ) - module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true ); - - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; - - return true; -} - -void HYDROGUI_ZoneOp::onCreatePreview( const QString& thePolylineName ) -{ - HYDROGUI_ZoneDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) - return; - - TopoDS_Wire aWire; - - Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINE ) ); - if ( !aPolyline.IsNull() ) - { - aWire = aPolyline->Wire(); - } - - LightApp_Application* anApp = module()->getApp(); - if ( !myViewManager ) - myViewManager = ::qobject_cast( - anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ); - - if ( myViewManager && !myPreviewPrs ) - { - if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() ) - { - Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); - if ( !aCtx.IsNull() ) - myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL ); - } - } - - if ( !myViewManager || !myPreviewPrs ) - return; - - myPreviewPrs->setFillingColor( aPanel->getFillingColor(), false, false ); - myPreviewPrs->setBorderColor( aPanel->getBorderColor(), false, false ); - myPreviewPrs->setFace( aWire ); -} - -void HYDROGUI_ZoneOp::closePreview() -{ - if( myPreviewPrs ) - { - delete myPreviewPrs; - myPreviewPrs = 0; - } -} diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.h b/src/HYDROGUI/HYDROGUI_ZoneOp.h deleted file mode 100644 index 85760aac..00000000 --- a/src/HYDROGUI/HYDROGUI_ZoneOp.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef HYDROGUI_ZONEOP_H -#define HYDROGUI_ZONEOP_H - -#include "HYDROGUI_Operation.h" - -#include - -class OCCViewer_ViewManager; - -class HYDROGUI_Shape; - -class HYDROGUI_ZoneOp : public HYDROGUI_Operation -{ - Q_OBJECT - -public: - HYDROGUI_ZoneOp( HYDROGUI_Module* theModule, const bool theIsEdit ); - virtual ~HYDROGUI_ZoneOp(); - -protected: - virtual void startOperation(); - virtual void abortOperation(); - virtual void commitOperation(); - - virtual HYDROGUI_InputPanel* createInputPanel() const; - - virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); - -protected slots: - void onCreatePreview( const QString& thePolylineName ); - -private: - void closePreview(); - -private: - bool myIsEdit; - Handle(HYDROData_Zone) myEditedObject; - - OCCViewer_ViewManager* myViewManager; - - HYDROGUI_Shape* myPreviewPrs; -}; - -#endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 63f72ab8..ae546f69 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -7,10 +7,6 @@ BATHYMETRY_FILTER Bathymetry files (*.xyz);;All files (*.* *) - - CASE_BND_POLYLINE - Boundary polyline - CASE_REFERENCE_ZONES Reference zones @@ -61,53 +57,25 @@ does not exist or you have not enough permissions to open it. Polyline - ZONE_BATHYMETRIES - Bathymetries + ZONE_BATHYMETRY + Bathymetry HYDROGUI_CalculationDlg - - BOUNDARY_POLYLINE - Polyline - - - CALCULATION_BOUNDARY - Domain of calculation case - CALCULATION_NAME Calculation case name - CALCULATION_REFERENCE_ZONES - Reference zones - - - CALCULATION_REGIONS - Regions - - - CALCULATION_ZONES - Case zones - - - DEFAULT_PREFIX_REGIONS - Region + CALCULATION_REFERENCE_OBJECTS + Objects NAME Name - - PREFIX_REGIONS - Prefix for regions - - - SPLIT_REFERENCE_ZONES - Split zones - @@ -324,12 +292,12 @@ file cannot be correctly imported for a Bathymetry definition. Create polyline - DSK_CREATE_ZONE - Create zone + DSK_CREATE_IMMERSIBLE_ZONE + Create immersible zone - DSK_EDIT_ZONE - Edit zone + DSK_EDIT_IMMERSIBLE_ZONE + Edit immersible zone DSK_COPY @@ -448,12 +416,12 @@ file cannot be correctly imported for a Bathymetry definition. Create zone - MEN_EDIT_ZONE - Edit zone + MEN_CREATE_IMMERSIBLE_ZONE + Create immersible zone - MEN_COPY - Copy + MEN_EDIT_IMMERSIBLE_ZONE + Edit immersible zone MEN_CUT_IMAGES @@ -568,12 +536,12 @@ file cannot be correctly imported for a Bathymetry definition. Create polyline - STB_CREATE_ZONE - Create zone + STB_CREATE_IMMERSIBLE_ZONE + Create immersible zone - STB_EDIT_ZONE - Edit zone + STB_EDIT_IMMERSIBLE_ZONE + Edit immersible zone STB_COPY @@ -846,7 +814,7 @@ file cannot be correctly imported for a Bathymetry definition. - HYDROGUI_ZoneDlg + HYDROGUI_ImmersibleZoneDlg BORDER_COLOR Border @@ -868,8 +836,8 @@ file cannot be correctly imported for a Bathymetry definition. Transparent - ZONE_BATHYMETRIES - Bathymetries + ZONE_BATHYMETRY + Bathymetry ZONE_NAME @@ -886,14 +854,14 @@ file cannot be correctly imported for a Bathymetry definition. - HYDROGUI_ZoneOp + HYDROGUI_ImmersibleZoneOp - CREATE_ZONE - Create zone + CREATE_IMMERSIBLE_ZONE + Create immersible zone - EDIT_ZONE - Edit zone + EDIT_IMMERSIBLE_ZONE + Edit immersible zone diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index 97fd2024..c4c8ca3d 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -52,11 +52,14 @@ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com %Import QtGui/QtGuimod.sip +%Include HYDROData_Entity.sip %Include HYDROData_Object.sip +%Include HYDROData_ArtificialObject.sip +%Include HYDROData_NaturalObject.sip %Include HYDROData_Image.sip %Include HYDROData_Polyline.sip %Include HYDROData_Bathymetry.sip -%Include HYDROData_Domain.sip +%Include HYDROData_ImmersibleZone.sip %Include HYDROData_Zone.sip %Include HYDROData_Region.sip %Include HYDROData_Calculation.sip diff --git a/src/HYDROPy/HYDROData_ArtificialObject.sip b/src/HYDROPy/HYDROData_ArtificialObject.sip new file mode 100644 index 00000000..dc301f89 --- /dev/null +++ b/src/HYDROPy/HYDROData_ArtificialObject.sip @@ -0,0 +1,64 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +%ExportedHeaderCode +#include +%End + +class HYDROData_ArtificialObject : HYDROData_Object /Abstract/ +{ +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + // HYDROData_ArtificialObject sub-classes provide a unique kind ID. + switch ( sipCpp->GetKind() ) + { + case KIND_UNKNOWN: + sipClass = sipClass_HYDROData_ArtificialObject; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } +%End + +public: + + +protected: + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDROData_ArtificialObject(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual ~HYDROData_ArtificialObject(); + +}; diff --git a/src/HYDROPy/HYDROData_Bathymetry.sip b/src/HYDROPy/HYDROData_Bathymetry.sip index 8666ba56..f26ec885 100644 --- a/src/HYDROPy/HYDROData_Bathymetry.sip +++ b/src/HYDROPy/HYDROData_Bathymetry.sip @@ -32,14 +32,20 @@ HYDROData_Bathymetry::AltitudePoints convertFromPythonAltitudeList( PyObject* th %End -class HYDROData_Bathymetry : HYDROData_Object +class HYDROData_Bathymetry : HYDROData_Entity { %ConvertToSubClassCode - if ( !Handle(HYDROData_Bathymetry)::DownCast( sipCpp ).IsNull() ) - sipClass = sipClass_HYDROData_Bathymetry; - else - sipClass = NULL; + switch ( sipCpp->GetKind() ) + { + case KIND_BATHYMETRY: + sipClass = sipClass_HYDROData_Bathymetry; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } %End %TypeHeaderCode @@ -95,12 +101,6 @@ HYDROData_Bathymetry::AltitudePoints convertFromPythonAltitudeList( PyObject* th %End - -public: - - const ObjectKind GetKind() const; - - public: // Public methods to work with Bathymetry altitudes. diff --git a/src/HYDROPy/HYDROData_Calculation.sip b/src/HYDROPy/HYDROData_Calculation.sip index 15d026ec..2ca69234 100644 --- a/src/HYDROPy/HYDROData_Calculation.sip +++ b/src/HYDROPy/HYDROData_Calculation.sip @@ -32,143 +32,131 @@ class HYDROData_Calculation : HYDROData_Object %End %ConvertToSubClassCode - if ( !Handle(HYDROData_Calculation)::DownCast( sipCpp ).IsNull() ) - sipClass = sipClass_HYDROData_Calculation; - else - sipClass = NULL; -%End - -public: - - const ObjectKind GetKind() const; - -public: - - /** - * Sets boundary polyline for calculation case. - */ - void SetBoundaryPolyline( HYDROData_Polyline thePolyline ) [void (const Handle_HYDROData_Polyline&)]; - %MethodCode - - Handle(HYDROData_Polyline) aRefPolyline = - Handle(HYDROData_Polyline)::DownCast( createHandle( a0 ) ); - if ( !aRefPolyline.IsNull() ) + switch ( sipCpp->GetKind() ) { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Calculation::SetBoundaryPolyline( aRefPolyline ) : - sipCpp->SetBoundaryPolyline( aRefPolyline ); - Py_END_ALLOW_THREADS - } - - %End + case KIND_CALCULATION: + sipClass = sipClass_HYDROData_Calculation; + break; - /** - * Returns boundary polyline of calculation case. - */ - HYDROData_Polyline GetBoundaryPolyline() const [Handle_HYDROData_Polyline ()]; - %MethodCode + default: + // We don't recognise the type. + sipClass = NULL; + } +%End - Handle(HYDROData_Polyline) aRefPolyline; - - Py_BEGIN_ALLOW_THREADS - aRefPolyline = sipSelfWasArg ? sipCpp->HYDROData_Calculation::GetBoundaryPolyline() : - sipCpp->GetBoundaryPolyline(); - Py_END_ALLOW_THREADS - - sipRes = (HYDROData_Polyline*)createPointer( aRefPolyline ); - - %End +public: /** - * Removes boundary polyline of calculation case. + * Split reference geometry objects to non-intersected regions. */ - void RemoveBoundaryPolyline(); - - + void SplitGeometryObjects(); /** - * Returns number of refrence zones for calculation case. + * Returns number of geometry objects for calculation case. */ - int NbZones() const; + int NbGeometryObjects() const; /** - * Add new one refrence zone for calculation case. + * dd new one geometry object for calculation case. */ - void AddZone( HYDROData_Zone theZone ) [void (const Handle_HYDROData_Zone&)]; + void AddGeometryObject( HYDROData_Object theRegion ) [void (const Handle_HYDROData_Object&)]; %MethodCode - Handle(HYDROData_Zone) aRefZone = - Handle(HYDROData_Zone)::DownCast( createHandle( a0 ) ); - if ( !aRefZone.IsNull() ) + Handle(HYDROData_Object) aGeomObj = + Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); + if ( !aGeomObj.IsNull() ) { Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Calculation::AddZone( aRefZone ) : - sipCpp->AddZone( aRefZone ); + sipSelfWasArg ? sipCpp->HYDROData_Calculation::AddGeometryObject( aGeomObj ) : + sipCpp->AddGeometryObject( aGeomObj ); Py_END_ALLOW_THREADS } %End /** - * Replace the refrence zone for calculation case. + * Replace the geometry object for calculation case. */ - void SetZone( const int theIndex, - HYDROData_Zone theZone ) [void (const int, const Handle_HYDROData_Zone&)]; + void SetGeometryObject( const int theIndex, + HYDROData_Object theObject ) [void (const int, const Handle_HYDROData_Object&)]; %MethodCode - Handle(HYDROData_Zone) aRefZone = - Handle(HYDROData_Zone)::DownCast( createHandle( a1 ) ); - if ( !aRefZone.IsNull() ) + Handle(HYDROData_Object) aGeomObj = + Handle(HYDROData_Object)::DownCast( createHandle( a1 ) ); + if ( !aGeomObj.IsNull() ) { Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Calculation::SetZone( a0, aRefZone ) : - sipCpp->SetZone( a0, aRefZone ); + sipSelfWasArg ? sipCpp->HYDROData_Calculation::SetGeometryObject( a0, aGeomObj ) : + sipCpp->SetGeometryObject( a0, aGeomObj ); Py_END_ALLOW_THREADS } %End /** - * Sets the refrence zones for calculation case. + * Sets the geometry object for calculation case. */ - //void SetZones( const HYDROData_SequenceOfObjects& theZones ); + //void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); /** - * Returns refrence zone of calculation case by index. + * Returns geometry object of calculation case by index. */ - HYDROData_Zone GetZone( const int theIndex ) const [Handle_HYDROData_Zone (const int)]; + HYDROData_Object GetGeometryObject( const int theIndex ) const [Handle_HYDROData_Object (const int)]; %MethodCode - Handle(HYDROData_Zone) aRefZone; + Handle(HYDROData_Object) aGeomObj; Py_BEGIN_ALLOW_THREADS - aRefZone = sipSelfWasArg ? sipCpp->HYDROData_Calculation::GetZone( a0 ) : - sipCpp->GetZone( a0 ); + aGeomObj = sipSelfWasArg ? sipCpp->HYDROData_Calculation::GetGeometryObject( a0 ) : + sipCpp->GetGeometryObject( a0 ); Py_END_ALLOW_THREADS - sipRes = (HYDROData_Zone*)createPointer( aRefZone ); + sipRes = (HYDROData_Object*)createPointer( aGeomObj ); %End /** - * Returns all refrence zone of calculation case. + * Returns all geometry objects of calculation case. */ - //HYDROData_SequenceOfObjects GetZones() const; + //HYDROData_SequenceOfObjects GetGeometryObjects() const; /** - * Removes all refrence zone of calculation case. + * Removes all geometry objects from calculation case. */ - void RemoveZones(); + void RemoveGeometryObjects(); + + + /** + * Add new one region for calculation case. + * The new region is not added into the list of reference regions. + */ + HYDROData_Region AddNewRegion() [Handle_HYDROData_Region ()]; + %MethodCode + + Handle(HYDROData_Region) aNewRegion; + + Py_BEGIN_ALLOW_THREADS + aNewRegion = sipSelfWasArg ? sipCpp->HYDROData_Calculation::AddNewRegion() : + sipCpp->AddNewRegion(); + Py_END_ALLOW_THREADS + + sipRes = (HYDROData_Region*)createPointer( aNewRegion ); + %End + + /** + * Removes all child regions from calculation case. + */ + void RemoveChildRegions(); /** - * Returns number of regions for calculation case. + * Returns number of reference regions for calculation case. */ int NbRegions() const; /** - * Add new one region for calculation case. + * Add new one reference region for calculation case. */ void AddRegion( HYDROData_Region theRegion ) [void (const Handle_HYDROData_Region&)]; %MethodCode @@ -186,7 +174,7 @@ public: %End /** - * Replace the region for calculation case. + * Replace the reference region for calculation case. */ void SetRegion( const int theIndex, HYDROData_Region theRegion ) [void (const int, const Handle_HYDROData_Region&)]; @@ -205,34 +193,76 @@ public: %End /** - * Sets the refrence region for calculation case. + * Inserts the reference region for calculation case before given index. + */ + void InsertRegion( const int theBeforeIndex, + HYDROData_Region theRegion ) [void (const int, const Handle_HYDROData_Region&)]; + %MethodCode + + Handle(HYDROData_Region) aRegion = + Handle(HYDROData_Region)::DownCast( createHandle( a1 ) ); + if ( !aRegion.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Calculation::InsertRegion( a0, aRegion ) : + sipCpp->InsertRegion( a0, aRegion ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Sets reference regions for calculation case. */ //void SetRegions( const HYDROData_SequenceOfObjects& theRegions ); /** - * Returns region of calculation case by index. + * Returns reference region of calculation case by index. */ HYDROData_Region GetRegion( const int theIndex ) const [Handle_HYDROData_Region (const int)]; %MethodCode - Handle(HYDROData_Region) aRegion; + Handle(HYDROData_Region) aRefRegion; Py_BEGIN_ALLOW_THREADS - aRegion = sipSelfWasArg ? sipCpp->HYDROData_Calculation::GetRegion( a0 ) : - sipCpp->GetRegion( a0 ); + aRefRegion = sipSelfWasArg ? sipCpp->HYDROData_Region::GetRegion( a0 ) : + sipCpp->GetRegion( a0 ); Py_END_ALLOW_THREADS - sipRes = (HYDROData_Region*)createPointer( aRegion ); + sipRes = (HYDROData_Region*)createPointer( aRefRegion ); %End /** - * Returns all regions of calculation case. + * Returns all reference regions of calculation case. + */ + //void HYDROData_SequenceOfObjects GetRegions() const; + + /** + * Removes reference region from calculation case. + */ + void RemoveRegion( HYDROData_Region theRegion ) const [void (const Handle_HYDROData_Region&)]; + %MethodCode + + Handle(HYDROData_Region) aRegion = + Handle(HYDROData_Region)::DownCast( createHandle( a0 ) ); + if ( !aRegion.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Calculation::RemoveRegion( aRegion ) : + sipCpp->RemoveRegion( aRegion ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Removes region from calculation case by it index. */ - //HYDROData_SequenceOfObjects GetRegions() const; + void RemoveRegion( const int theIndex ); /** - * Removes all regions of calculation case. + * Removes all reference regions from calculation case. */ void RemoveRegions(); diff --git a/src/HYDROPy/HYDROData_Document.sip b/src/HYDROPy/HYDROData_Document.sip index e79e16d5..539d91cb 100644 --- a/src/HYDROPy/HYDROData_Document.sip +++ b/src/HYDROPy/HYDROData_Document.sip @@ -25,9 +25,9 @@ %End %ModuleHeaderCode -HYDROData_Object* copyObject( HYDROData_Object* theObject ); -Handle(HYDROData_Object) createHandle( HYDROData_Object* theObject ); -HYDROData_Object* createPointer( const Handle(HYDROData_Object)& theObject ); +HYDROData_Entity* copyObject( HYDROData_Entity* theObject ); +Handle(HYDROData_Entity) createHandle( HYDROData_Entity* theObject ); +HYDROData_Entity* createPointer( const Handle(HYDROData_Entity)& theObject ); %End enum Data_DocError { @@ -54,9 +54,9 @@ class HYDROData_Document %TypeCode - HYDROData_Object* copyObject( HYDROData_Object* theObject ) + HYDROData_Entity* copyObject( HYDROData_Entity* theObject ) { - HYDROData_Object* aRes = NULL; + HYDROData_Entity* aRes = NULL; if ( theObject == NULL ) return aRes; @@ -77,14 +77,14 @@ class HYDROData_Document aRes = new HYDROData_Bathymetry( *dynamic_cast( theObject ) ); break; } - case KIND_CALCULATION: + case KIND_IMMERSIBLE_ZONE: { - aRes = new HYDROData_Calculation( *dynamic_cast( theObject ) ); + aRes = new HYDROData_ImmersibleZone( *dynamic_cast( theObject ) ); break; } - case KIND_ZONE: + case KIND_CALCULATION: { - aRes = new HYDROData_Zone( *dynamic_cast( theObject ) ); + aRes = new HYDROData_Calculation( *dynamic_cast( theObject ) ); break; } case KIND_REGION: @@ -92,20 +92,25 @@ class HYDROData_Document aRes = new HYDROData_Region( *dynamic_cast( theObject ) ); break; } + case KIND_ZONE: + { + aRes = new HYDROData_Zone( *dynamic_cast( theObject ) ); + break; + } } return aRes; } - Handle(HYDROData_Object) createHandle( HYDROData_Object* theObject ) + Handle(HYDROData_Entity) createHandle( HYDROData_Entity* theObject ) { - Handle(HYDROData_Object) aRes = copyObject( theObject ); + Handle(HYDROData_Entity) aRes = copyObject( theObject ); return aRes; } - HYDROData_Object* createPointer( const Handle(HYDROData_Object)& theObject ) + HYDROData_Entity* createPointer( const Handle(HYDROData_Entity)& theObject ) { - HYDROData_Object* aRes = NULL; + HYDROData_Entity* aRes = NULL; if ( !theObject.IsNull() ) aRes = copyObject( theObject.operator->() ); @@ -192,10 +197,10 @@ public: //! Creates and locates in the document a new object //! \param theKind kind of the created object, can not be UNKNOWN //! \returns the created object - HYDROData_Object CreateObject( const ObjectKind theKind ) [Handle_HYDROData_Object (const ObjectKind)] ; + HYDROData_Entity CreateObject( const ObjectKind theKind ) [Handle_HYDROData_Entity (const ObjectKind)] ; %MethodCode - Handle(HYDROData_Object) anObject; + Handle(HYDROData_Entity) anObject; Py_BEGIN_ALLOW_THREADS anObject = sipSelfWasArg ? sipCpp->HYDROData_Document::CreateObject( a0 ) : sipCpp->CreateObject( a0 ); diff --git a/src/HYDROPy/HYDROData_Domain.sip b/src/HYDROPy/HYDROData_Domain.sip deleted file mode 100644 index 083c3a3c..00000000 --- a/src/HYDROPy/HYDROData_Domain.sip +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -%ExportedHeaderCode -#include -%End - -class HYDROData_Domain : HYDROData_Object /Abstract/ -{ - -%TypeHeaderCode -#include -%End - -%ConvertToSubClassCode - // HYDROData_Object sub-classes provide a unique kind ID. - switch ( sipCpp->GetKind() ) - { - case KIND_REGION: - sipClass = sipClass_HYDROData_Region; - break; - - case KIND_ZONE: - sipClass = sipClass_HYDROData_Zone; - break; - - case KIND_UNKNOWN: - sipClass = sipClass_HYDROData_Object; - break; - - default: - // We don't recognise the type. - sipClass = NULL; - } -%End - -public: - - /** - * Sets filling color for zone. - */ - void SetFillingColor( const QColor& theColor ); - - /** - * Returns filling color of zone. - */ - QColor GetFillingColor() const; - - /** - * Sets border color for zone. - */ - void SetBorderColor( const QColor& theColor ); - - /** - * Returns border color of zone. - */ - QColor GetBorderColor() const; - - /** - * Returns number of bathymetry objects for zone. - */ - int NbBathymetries() const; - - /** - * Add reference bathymetry object for zone. - */ - void AddBathymetry( HYDROData_Bathymetry theBathymetry ) [void (const Handle_HYDROData_Bathymetry&)]; - %MethodCode - - Handle(HYDROData_Bathymetry) aRefBath = - Handle(HYDROData_Bathymetry)::DownCast( createHandle( a0 ) ); - if ( !aRefBath.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Domain::AddBathymetry( aRefBath ) : - sipCpp->AddBathymetry( aRefBath ); - Py_END_ALLOW_THREADS - } - - %End - - /** - * Change reference bathymetry object with given index for zone. - */ - void SetBathymetry( const int theIndex, - HYDROData_Bathymetry theBathymetry ) [void (const int, const Handle_HYDROData_Bathymetry&)]; - %MethodCode - - Handle(HYDROData_Bathymetry) aRefBath = - Handle(HYDROData_Bathymetry)::DownCast( createHandle( a1 ) ); - if ( !aRefBath.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Domain::SetBathymetry( a0, aRefBath ) : - sipCpp->SetBathymetry( a0, aRefBath ); - Py_END_ALLOW_THREADS - } - - %End - - /** - * Returns reference bathymetry object of zone by it index. - */ - HYDROData_Bathymetry GetBathymetry( const int theIndex ) const [Handle_HYDROData_Bathymetry (const int)]; - %MethodCode - - Handle(HYDROData_Bathymetry) aRefBath; - - Py_BEGIN_ALLOW_THREADS - aRefBath = sipSelfWasArg ? sipCpp->HYDROData_Domain::GetBathymetry( a0 ) : - sipCpp->GetBathymetry( a0 ); - Py_END_ALLOW_THREADS - - sipRes = (HYDROData_Bathymetry*)createPointer( aRefBath ); - - %End - - /** - * Returns list of all reference bathymetry objects of zone. - */ - //HYDROData_SequenceOfObjects GetBathymetries() const; - - /** - * Clear list of bathymetry objects of zone. - */ - void RemoveBathymetries(); - -protected: - - /** - * Creates new object in the internal data structure. Use higher level objects - * to create objects with real content. - */ - HYDROData_Domain(); - - /** - * Destructs properties of the object and object itself, removes it from the document. - */ - ~HYDROData_Domain(); -}; - - diff --git a/src/HYDROPy/HYDROData_Entity.sip b/src/HYDROPy/HYDROData_Entity.sip new file mode 100644 index 00000000..20ab25cb --- /dev/null +++ b/src/HYDROPy/HYDROData_Entity.sip @@ -0,0 +1,148 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +%ExportedHeaderCode +#include +%End + +typedef int ObjectKind; + +const ObjectKind KIND_UNKNOWN; +const ObjectKind KIND_IMAGE; +const ObjectKind KIND_POLYLINE; +const ObjectKind KIND_BATHYMETRY; +const ObjectKind KIND_IMMERSIBLE_ZONE; +const ObjectKind KIND_CALCULATION; +const ObjectKind KIND_ZONE; +const ObjectKind KIND_REGION; + +class HYDROData_Entity +{ +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + // HYDROData_Entity sub-classes provide a unique kind ID. + switch ( sipCpp->GetKind() ) + { + case KIND_IMAGE: + sipClass = sipClass_HYDROData_Image; + break; + + case KIND_POLYLINE: + sipClass = sipClass_HYDROData_Polyline; + break; + + case KIND_BATHYMETRY: + sipClass = sipClass_HYDROData_Bathymetry; + break; + + case KIND_IMMERSIBLE_ZONE: + sipClass = sipClass_HYDROData_ImmersibleZone; + break; + + case KIND_CALCULATION: + sipClass = sipClass_HYDROData_Calculation; + break; + + case KIND_REGION: + sipClass = sipClass_HYDROData_Region; + break; + + case KIND_ZONE: + sipClass = sipClass_HYDROData_Zone; + break; + + case KIND_UNKNOWN: + sipClass = sipClass_HYDROData_Entity; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } +%End + +public: + + /** + * Returns the kind of this object. Must be redefined in all objects of known type. + */ + const ObjectKind GetKind() const; + + /** + * Returns the name of this object. + */ + QString GetName() const; + + /** + * Updates the name of this object. + */ + void SetName(const QString& theName); + + /** + * Updates object state. + * \param theIsForce force reupdating of data object + */ + void Update(const bool theIsForce); + + /** + * Checks is object exists in the data structure. + * \returns true is object is not exists in the data model + */ + bool IsRemoved() const; + + /** + * Removes object from the data structure. + */ + void Remove(); + + /** + * Returns unique integer identifier of the object (may be used for ordering of objects) + */ + int ID() const; + + /** + * Copies all properties of this to the destinated object. + * Objects must be the same type. + * \param theDestination initialized object (from any document) - target of copying + */ + /* + void CopyTo( HYDROData_Entity theDestination ) const; + */ + +protected: + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDROData_Entity(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual ~HYDROData_Entity(); + +}; diff --git a/src/HYDROPy/HYDROData_Image.sip b/src/HYDROPy/HYDROData_Image.sip index b79f0f74..860fcc75 100644 --- a/src/HYDROPy/HYDROData_Image.sip +++ b/src/HYDROPy/HYDROData_Image.sip @@ -24,24 +24,26 @@ #include %End -class HYDROData_Image : HYDROData_Object +class HYDROData_Image : HYDROData_Entity { %ConvertToSubClassCode - if ( !Handle(HYDROData_Image)::DownCast( sipCpp ).IsNull() ) - sipClass = sipClass_HYDROData_Image; - else - sipClass = NULL; + switch ( sipCpp->GetKind() ) + { + case KIND_IMAGE: + sipClass = sipClass_HYDROData_Image; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } %End %TypeHeaderCode #include %End -public: - - const ObjectKind GetKind() const; - public: /** @@ -104,14 +106,20 @@ public: QPointF& thePointBOut, QPointF& thePointCOut ); + /** + * Returns the number of referenced images + * \return zero if there is no references + */ + int NbReferences(); + /** * Appends reference to other image. * \param theReferenced the image referenced by this */ - void AppendReference( HYDROData_Object theReferenced ) [void (Handle_HYDROData_Object)]; + void AppendReference( HYDROData_Entity theReferenced ) [void (Handle_HYDROData_Entity)]; %MethodCode - Handle(HYDROData_Object) aRefObj = createHandle( a0 ); + Handle(HYDROData_Entity) aRefObj = createHandle( a0 ); if ( !aRefObj.IsNull() ) { Py_BEGIN_ALLOW_THREADS @@ -122,21 +130,15 @@ public: %End - /** - * Returns the number of referenced images - * \return zero if there is no references - */ - int NbReferences(); - /** * Returns reference by index. * \param theIndex number of reference [0; NbReference) * \returns the referenced image, or Null if index is invalid */ - HYDROData_Object Reference( const int theIndex ) const [Handle_HYDROData_Object (const int)]; + HYDROData_Entity Reference( const int theIndex ) const [Handle_HYDROData_Entity (const int)]; %MethodCode - Handle(HYDROData_Object) aRefObj; + Handle(HYDROData_Entity) aRefObj; Py_BEGIN_ALLOW_THREADS aRefObj = sipSelfWasArg ? sipCpp->HYDROData_Image::Reference( a0 ) : @@ -153,10 +155,10 @@ public: * \param theIndex number of reference [0; NbReference] * \param theReferenced the image referenced by this */ - void ChangeReference( const int theIndex, HYDROData_Object theReferenced ) [void (const int, Handle_HYDROData_Object)]; + void ChangeReference( const int theIndex, HYDROData_Entity theReferenced ) [void (const int, Handle_HYDROData_Entity)]; %MethodCode - Handle(HYDROData_Object) aRefObj = createHandle( a1 ); + Handle(HYDROData_Entity) aRefObj = createHandle( a1 ); if ( !aRefObj.IsNull() ) { Py_BEGIN_ALLOW_THREADS diff --git a/src/HYDROPy/HYDROData_ImmersibleZone.sip b/src/HYDROPy/HYDROData_ImmersibleZone.sip new file mode 100644 index 00000000..5346eb3b --- /dev/null +++ b/src/HYDROPy/HYDROData_ImmersibleZone.sip @@ -0,0 +1,163 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%ExportedHeaderCode +#include +%End + +class HYDROData_ImmersibleZone : HYDROData_NaturalObject +{ + +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + switch ( sipCpp->GetKind() ) + { + case KIND_IMMERSIBLE_ZONE: + sipClass = sipClass_HYDROData_ImmersibleZone; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } +%End + +public: + + /** + * Sets filling color for zone. + */ + void SetFillingColor( const QColor& theColor ); + + /** + * Returns filling color of zone. + */ + QColor GetFillingColor() const; + + /** + * Sets border color for zone. + */ + void SetBorderColor( const QColor& theColor ); + + /** + * Returns border color of zone. + */ + QColor GetBorderColor() const; + + /** + * Sets reference polyline object for zone. + */ + void SetPolyline( HYDROData_Polyline thePolyline ) [void (const Handle_HYDROData_Polyline&)]; + %MethodCode + + Handle(HYDROData_Polyline) aRefPolyline = + Handle(HYDROData_Polyline)::DownCast( createHandle( a0 ) ); + if ( !aRefPolyline.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_ImmersibleZone::SetPolyline( aRefPolyline ) : + sipCpp->SetPolyline( aRefPolyline ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Returns reference polyline object of zone. + */ + HYDROData_Polyline GetPolyline() const [Handle_HYDROData_Polyline ()]; + %MethodCode + + Handle(HYDROData_Polyline) aRefPolyline; + + Py_BEGIN_ALLOW_THREADS + aRefPolyline = sipSelfWasArg ? sipCpp->HYDROData_ImmersibleZone::GetPolyline() : + sipCpp->GetPolyline(); + Py_END_ALLOW_THREADS + + sipRes = (HYDROData_Polyline*)createPointer( aRefPolyline ); + + %End + + /** + * Remove reference polyline object of zone. + */ + void RemovePolyline(); + + /** + * Set reference bathymetry object for zone. + */ + void SetBathymetry( HYDROData_Bathymetry theBathymetry ) [void (const Handle_HYDROData_Bathymetry&)]; + %MethodCode + + Handle(HYDROData_Bathymetry) aRefBath = + Handle(HYDROData_Bathymetry)::DownCast( createHandle( a0 ) ); + if ( !aRefBath.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_ImmersibleZone::SetBathymetry( aRefBath ) : + sipCpp->SetBathymetry( aRefBath ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Returns reference bathymetry object of zone. + */ + HYDROData_Bathymetry GetBathymetry() const [Handle_HYDROData_Bathymetry ()]; + %MethodCode + + Handle(HYDROData_Bathymetry) aRefBath; + + Py_BEGIN_ALLOW_THREADS + aRefBath = sipSelfWasArg ? sipCpp->HYDROData_ImmersibleZone::GetBathymetry() : + sipCpp->GetBathymetry(); + Py_END_ALLOW_THREADS + + sipRes = (HYDROData_Bathymetry*)createPointer( aRefBath ); + + %End + + /** + * Clear the bathymetry object for zone. + */ + void RemoveBathymetry(); + +protected: + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDROData_ImmersibleZone(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + ~HYDROData_ImmersibleZone(); +}; + + diff --git a/src/HYDROPy/HYDROData_NaturalObject.sip b/src/HYDROPy/HYDROData_NaturalObject.sip new file mode 100644 index 00000000..d0ec9300 --- /dev/null +++ b/src/HYDROPy/HYDROData_NaturalObject.sip @@ -0,0 +1,68 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +%ExportedHeaderCode +#include +%End + +class HYDROData_NaturalObject : HYDROData_Object /Abstract/ +{ +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + // HYDROData_NaturalObject sub-classes provide a unique kind ID. + switch ( sipCpp->GetKind() ) + { + case KIND_IMMERSIBLE_ZONE: + sipClass = sipClass_HYDROData_ImmersibleZone; + break; + + case KIND_UNKNOWN: + sipClass = sipClass_HYDROData_NaturalObject; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } +%End + +public: + + +protected: + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDROData_NaturalObject(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + virtual ~HYDROData_NaturalObject(); + +}; diff --git a/src/HYDROPy/HYDROData_Object.sip b/src/HYDROPy/HYDROData_Object.sip index 1d67675d..85322fc9 100644 --- a/src/HYDROPy/HYDROData_Object.sip +++ b/src/HYDROPy/HYDROData_Object.sip @@ -25,108 +25,39 @@ #include %End -typedef int ObjectKind; - -const ObjectKind KIND_UNKNOWN; -const ObjectKind KIND_IMAGE; -const ObjectKind KIND_POLYLINE; -const ObjectKind KIND_VISUAL_STATE; -const ObjectKind KIND_BATHYMETRY; -const ObjectKind KIND_CALCULATION; -const ObjectKind KIND_ZONE; -const ObjectKind KIND_REGION; - -class HYDROData_Object +class HYDROData_Object : HYDROData_Entity /Abstract/ { %TypeHeaderCode #include %End %ConvertToSubClassCode - // HYDROData_Object sub-classes provide a unique kind ID. - switch ( sipCpp->GetKind() ) + if ( !Handle(HYDROData_ArtificialObject)::DownCast( sipCpp ).IsNull() ) + sipClass = sipClass_HYDROData_ArtificialObject; + else if ( !Handle(HYDROData_NaturalObject)::DownCast( sipCpp ).IsNull() ) + sipClass = sipClass_HYDROData_NaturalObject; + else { - case KIND_IMAGE: - sipClass = sipClass_HYDROData_Image; - break; - - case KIND_POLYLINE: - sipClass = sipClass_HYDROData_Polyline; - break; - - case KIND_BATHYMETRY: - sipClass = sipClass_HYDROData_Bathymetry; - break; - - case KIND_CALCULATION: - sipClass = sipClass_HYDROData_Calculation; - break; - - case KIND_ZONE: - sipClass = sipClass_HYDROData_Zone; - break; - - case KIND_REGION: - sipClass = sipClass_HYDROData_Region; - break; - - case KIND_UNKNOWN: - sipClass = sipClass_HYDROData_Object; - break; - - default: - // We don't recognise the type. - sipClass = NULL; + // HYDROData_Object sub-classes provide a unique kind ID. + switch ( sipCpp->GetKind() ) + { + case KIND_POLYLINE: + sipClass = sipClass_HYDROData_Polyline; + break; + + case KIND_UNKNOWN: + sipClass = sipClass_HYDROData_Object; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } } %End public: - /** - * Returns the kind of this object. Must be redefined in all objects of known type. - */ - const ObjectKind GetKind() const; - - /** - * Returns the name of this object. - */ - QString GetName() const; - - /** - * Updates the name of this object. - */ - void SetName(const QString& theName); - - /** - * Updates object state. - * \param theIsForce force reupdating of data object - */ - void Update(const bool theIsForce); - - /** - * Checks is object exists in the data structure. - * \returns true is object is not exists in the data model - */ - bool IsRemoved() const; - - /** - * Removes object from the data structure. - */ - void Remove(); - - /** - * Returns unique integer identifier of the object (may be used for ordering of objects) - */ - int ID() const; - - /** - * Copies all properties of this to the destinated object. - * Objects must be the same type. - * \param theDestination initialized object (from any document) - target of copying - */ - /* - void CopyTo( HYDROData_Object theDestination ) const; - */ protected: diff --git a/src/HYDROPy/HYDROData_Polyline.sip b/src/HYDROPy/HYDROData_Polyline.sip index d0a8b1ce..0798d97e 100644 --- a/src/HYDROPy/HYDROData_Polyline.sip +++ b/src/HYDROPy/HYDROData_Polyline.sip @@ -63,56 +63,69 @@ class HYDROData_Polyline : HYDROData_Object { %ConvertToSubClassCode - if ( !Handle(HYDROData_Polyline)::DownCast( sipCpp ).IsNull() ) - sipClass = sipClass_HYDROData_Polyline; - else - sipClass = NULL; + switch ( sipCpp->GetKind() ) + { + case KIND_POLYLINE: + sipClass = sipClass_HYDROData_Polyline; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } %End public: typedef QList PolylineData; -public: - - const ObjectKind GetKind() const; - public: /** * Replace current polyline data by new sections list * \param theSections the sections list */ - void setPolylineData( const PolylineData& theSections ); + void SetPolylineData( const PolylineData& theSections ); /** * Return polyline data * \return polyline section list */ - PolylineData getPolylineData(); + PolylineData GetPolylineData(); /** * Return polyline dimension * \return polyline dimension (2 or 3) */ - int getDimension() const; + int GetDimension() const; /** * Set polyline dimension (2 or 3) * \param theDimension the polyline dimension */ - void setDimension( int theDimension ); + void SetDimension( int theDimension ); /** * Remove all sections from polyline */ - void removeAll(); + void RemoveAll(); /** * Returns the painter path. The painter path is construct by lines */ - QPainterPath painterPath(); + QPainterPath GetPainterPath(); + + + /** + * Sets the z value for polyline. + */ + void SetZValue( const double theZValue ); + + /** + * Returns the z value for polyline. + */ + double ZValue() const; protected: diff --git a/src/HYDROPy/HYDROData_Region.sip b/src/HYDROPy/HYDROData_Region.sip index 3199acc2..8c2017cb 100644 --- a/src/HYDROPy/HYDROData_Region.sip +++ b/src/HYDROPy/HYDROData_Region.sip @@ -24,7 +24,7 @@ #include %End -class HYDROData_Region : HYDROData_Domain +class HYDROData_Region : HYDROData_Entity { %TypeHeaderCode @@ -32,15 +32,160 @@ class HYDROData_Region : HYDROData_Domain %End %ConvertToSubClassCode - if ( !Handle(HYDROData_Region)::DownCast( sipCpp ).IsNull() ) - sipClass = sipClass_HYDROData_Region; - else - sipClass = NULL; + switch ( sipCpp->GetKind() ) + { + case KIND_REGION: + sipClass = sipClass_HYDROData_Region; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } %End -public: +public: + + /** + * Create new one reference zone for region on child label. + * The new zone is not added into the list of reference zones. + */ + HYDROData_Zone AddNewZone() [Handle_HYDROData_Zone ()]; + %MethodCode + + Handle(HYDROData_Zone) aNewZone; + + Py_BEGIN_ALLOW_THREADS + aNewZone = sipSelfWasArg ? sipCpp->HYDROData_Region::AddNewZone() : + sipCpp->AddNewZone(); + Py_END_ALLOW_THREADS + + sipRes = (HYDROData_Zone*)createPointer( aNewZone ); + + %End + + /** + * Removes all child zones from region. + */ + void RemoveChildZones(); + + + /** + * Returns number of reference zones of region. + */ + int NbZones() const; + + /** + * Add new one reference zone for region. + */ + void AddZone( HYDROData_Zone theZone ) [void (const Handle_HYDROData_Zone&)]; + %MethodCode + + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( createHandle( a0 ) ); + if ( !aZone.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Region::AddZone( aZone ) : + sipCpp->AddZone( aZone ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Replace the reference zone for region. + */ + void SetZone( const int theIndex, + HYDROData_Zone theZone ) [void (const int, const Handle_HYDROData_Zone&)]; + %MethodCode + + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( createHandle( a1 ) ); + if ( !aZone.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Region::SetZone( a0, aZone ) : + sipCpp->SetZone( a0, aZone ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Inserts the reference zone for region before given index. + */ + void InsertZone( const int theBeforeIndex, + HYDROData_Zone theZone ) [void (const int, const Handle_HYDROData_Zone&)]; + %MethodCode + + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( createHandle( a1 ) ); + if ( !aZone.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Region::InsertZone( a0, aZone ) : + sipCpp->InsertZone( a0, aZone ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Sets reference zones for calculation region. + */ + //void SetZones( const HYDROData_SequenceOfObjects& theZones ); + + /** + * Returns reference zone of region by index. + */ + HYDROData_Zone GetZone( const int theIndex ) const [Handle_HYDROData_Zone (const int)]; + %MethodCode + + Handle(HYDROData_Zone) aRefZone; + + Py_BEGIN_ALLOW_THREADS + aRefZone = sipSelfWasArg ? sipCpp->HYDROData_Region::GetZone( a0 ) : + sipCpp->GetZone( a0 ); + Py_END_ALLOW_THREADS + + sipRes = (HYDROData_Zone*)createPointer( aRefZone ); + + %End + + /** + * Returns all reference zone of region. + */ + //void HYDROData_SequenceOfObjects GetZones() const; + + /** + * Removes reference zone from region. + */ + void RemoveZone( HYDROData_Zone theZone ) const [void (const Handle_HYDROData_Zone&)]; + %MethodCode + + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( createHandle( a0 ) ); + if ( !aZone.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Region::RemoveZone( aZone ) : + sipCpp->RemoveZone( aZone ); + Py_END_ALLOW_THREADS + } + + %End + + /** + * Removes reference zone from region by it index. + */ + void RemoveZone( const int theIndex ); + + /** + * Removes all reference zones from region. + */ + void RemoveZones(); - const ObjectKind GetKind() const; protected: diff --git a/src/HYDROPy/HYDROData_Zone.sip b/src/HYDROPy/HYDROData_Zone.sip index c7c4bb7e..e70baae0 100644 --- a/src/HYDROPy/HYDROData_Zone.sip +++ b/src/HYDROPy/HYDROData_Zone.sip @@ -24,7 +24,7 @@ #include %End -class HYDROData_Zone : HYDROData_Domain +class HYDROData_Zone : HYDROData_Entity { %TypeHeaderCode @@ -32,62 +32,93 @@ class HYDROData_Zone : HYDROData_Domain %End %ConvertToSubClassCode - if ( !Handle(HYDROData_Zone)::DownCast( sipCpp ).IsNull() ) - sipClass = sipClass_HYDROData_Zone; - else - sipClass = NULL; + switch ( sipCpp->GetKind() ) + { + case KIND_ZONE: + sipClass = sipClass_HYDROData_Zone; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } %End -public: +public: - const ObjectKind GetKind() const; + /** + * Returns number of geometry objects for zone. + */ + int NbGeometryObjects() const; -public: + /** + * dd new one geometry object for zone. + */ + void AddGeometryObject( HYDROData_Object theRegion ) [void (const Handle_HYDROData_Object&)]; + %MethodCode + + Handle(HYDROData_Object) aGeomObj = + Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); + if ( !aGeomObj.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Zone::AddGeometryObject( aGeomObj ) : + sipCpp->AddGeometryObject( aGeomObj ); + Py_END_ALLOW_THREADS + } + + %End /** - * Sets reference polyline object for zone. + * Replace the geometry object for zone. */ - void SetPolyline( HYDROData_Polyline thePolyline ) [void (const Handle_HYDROData_Polyline&)]; + void SetGeometryObject( const int theIndex, + HYDROData_Object theObject ) [void (const int, const Handle_HYDROData_Object&)]; %MethodCode - Handle(HYDROData_Polyline) aRefPolyline = - Handle(HYDROData_Polyline)::DownCast( createHandle( a0 ) ); - if ( !aRefPolyline.IsNull() ) + Handle(HYDROData_Object) aGeomObj = + Handle(HYDROData_Object)::DownCast( createHandle( a1 ) ); + if ( !aGeomObj.IsNull() ) { Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Zone::SetPolyline( aRefPolyline ) : - sipCpp->SetPolyline( aRefPolyline ); + sipSelfWasArg ? sipCpp->HYDROData_Zone::SetGeometryObject( a0, aGeomObj ) : + sipCpp->SetGeometryObject( a0, aGeomObj ); Py_END_ALLOW_THREADS } %End /** - * Returns reference polyline object of zone. + * Sets the geometry object for zone. + */ + //void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); + + /** + * Returns geometry object of zone by index. */ - HYDROData_Polyline GetPolyline() const [Handle_HYDROData_Polyline ()]; + HYDROData_Object GetGeometryObject( const int theIndex ) const [Handle_HYDROData_Object (const int)]; %MethodCode - Handle(HYDROData_Polyline) aRefPolyline; + Handle(HYDROData_Object) aGeomObj; Py_BEGIN_ALLOW_THREADS - aRefPolyline = sipSelfWasArg ? sipCpp->HYDROData_Zone::GetPolyline() : - sipCpp->GetPolyline(); + aGeomObj = sipSelfWasArg ? sipCpp->HYDROData_Zone::GetGeometryObject( a0 ) : + sipCpp->GetGeometryObject( a0 ); Py_END_ALLOW_THREADS - sipRes = (HYDROData_Polyline*)createPointer( aRefPolyline ); + sipRes = (HYDROData_Object*)createPointer( aGeomObj ); %End /** - * Remove reference polyline object of zone. + * Returns all geometry objects of zone. */ - void RemovePolyline(); + //HYDROData_SequenceOfObjects GetGeometryObjects() const; /** - * Returns the painter path. The painter path is construct by polyline + * Removes all geometry objects from zone. */ - QPainterPath GetPainterPath() const; + void RemoveGeometryObjects(); protected: diff --git a/src/HYDROPy/HYDROPy.vcproj b/src/HYDROPy/HYDROPy.vcproj index bb69aa65..e2282ee6 100644 --- a/src/HYDROPy/HYDROPy.vcproj +++ b/src/HYDROPy/HYDROPy.vcproj @@ -166,6 +166,10 @@ RelativePath=".\HYDROData.sip" > + + @@ -179,13 +183,21 @@ > + + + +