From b654dab4196604cf30846f9369ca01aef0bd4fd5 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 9 Dec 2019 16:11:19 +0300 Subject: [PATCH 1/3] Modification of GEOM interface --- idl/GEOM_Gen.idl | 11 +++++-- src/GEOMImpl/GEOMImpl_IMeasure.hxx | 12 ++++--- src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx | 17 ++++++---- src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx | 9 +++--- src/GEOMImpl/GEOMImpl_MeasureDriver.cxx | 33 ++++++++++---------- src/GEOM_I/GEOM_BaseObject_i.cc | 11 +++++++ src/GEOM_I/GEOM_BaseObject_i.hh | 2 ++ src/GEOM_I/GEOM_IMeasureOperations_i.cc | 8 +++-- src/GEOM_I/GEOM_IMeasureOperations_i.hh | 3 +- src/GEOM_SWIG/geomBuilder.py | 16 ++++++---- 10 files changed, 80 insertions(+), 42 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 59afc08d2..fe78db396 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -258,6 +258,7 @@ module GEOM typedef sequence ListOfListOfDouble; typedef sequence ListOfListOfLong; + interface GEOM_Gen; interface GEOM_Object; interface GEOM_BaseObject; interface GEOM_Field; @@ -359,6 +360,11 @@ module GEOM * \brief Return name of operation and values of parameters used for object creation */ CreationInformationSeq GetCreationInformation(); + + /*! + * \brief Return the engine creating this object + */ + GEOM_Gen GetGen(); }; //# GEOM_Object @@ -4366,12 +4372,13 @@ module GEOM GEOM_Object GetCentreOfMass (in GEOM_Object theShape); /* - * Get the vertex by index for 1D objects depends the edge/wire orientation + * Get the vertex by index for 1D objects * \param theShape Shape (wire or edge) to find the vertex on it * \param theIndex Index of vertex sub-shape + * \param theUseOri To consider edge/wire orientation or not * \return New GEOM_Object, vertex. */ - GEOM_Object GetVertexByIndex( in GEOM_Object theShape, in long index ); + GEOM_Object GetVertexByIndex( in GEOM_Object theShape, in long theIndex, in boolean theUseOri ); /*! * \brief Get a vector, representing the normal of theFace. diff --git a/src/GEOMImpl/GEOMImpl_IMeasure.hxx b/src/GEOMImpl/GEOMImpl_IMeasure.hxx index 2c6b2cc1e..4ebfa1751 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasure.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasure.hxx @@ -24,15 +24,13 @@ // #include "GEOM_Function.hxx" -//#define MEASURE_ARG_BASE 1 -//#define MEASURE_ARG_POINT 2 - class GEOMImpl_IMeasure { enum { MEASURE_ARG_BASE = 1, MEASURE_ARG_POINT = 2, - MEASURE_INDEX = 3 + MEASURE_INDEX = 3, + MEASURE_USE_ORI = 4 }; public: @@ -52,6 +50,12 @@ class GEOMImpl_IMeasure int GetIndex() { return _func->GetInteger(MEASURE_INDEX); } + void SetUseOri(int theIndex) { _func->SetInteger(MEASURE_USE_ORI, theIndex); } + + bool GetUseOri() { return ( _func->GetInteger(MEASURE_USE_ORI) || + !_func->IsDone() ); // old behavior was to useOri + } + private: Handle(GEOM_Function) _func; diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx index 080cc669f..bcb6443d6 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx @@ -850,7 +850,8 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass //============================================================================= Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex (Handle(GEOM_Object) theShape, - Standard_Integer theIndex) + Standard_Integer theIndex, + Standard_Boolean theUseOri) { SetErrorCode(KO); @@ -873,6 +874,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex GEOMImpl_IMeasure aCI (aFunction); aCI.SetBase(aRefShape); aCI.SetIndex(theIndex); + aCI.SetUseOri(theUseOri); //Compute try { @@ -888,7 +890,10 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex } //Make a Python command - GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")"; + GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" + << theShape << ", " + << theIndex << ", " + << theUseOri << ")"; SetErrorCode(OK); return aVertex; @@ -2139,16 +2144,16 @@ Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) for (int i = 1; i <= nbSolutions; i++) { P1 = dst.PointOnShape1(i); P2 = dst.PointOnShape2(i); - + theDoubles->Append(P1.X()); theDoubles->Append(P1.Y()); theDoubles->Append(P1.Z()); theDoubles->Append(P2.X()); theDoubles->Append(P2.Y()); theDoubles->Append(P2.Z()); - - Standard_Real Dist = P1.Distance(P2); - singularBetter = singularBetter && dist < Dist; + + Standard_Real Dist = P1.Distance(P2); + singularBetter = singularBetter && dist < Dist; } } diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx index c71e6b881..c10c91f90 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx @@ -113,7 +113,8 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) GetCentreOfMass (Handle(GEOM_Object) theShape); Standard_EXPORT Handle(GEOM_Object) GetVertexByIndex (Handle(GEOM_Object) theShape, - Standard_Integer theIndex); + Standard_Integer theIndex, + Standard_Boolean theUseOri); Standard_EXPORT Handle(GEOM_Object) GetNormal (Handle(GEOM_Object) theFace, Handle(GEOM_Object) theOptionalPoint); @@ -162,9 +163,9 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { Handle(TColStd_HSequenceOfInteger)& theIntersections); Standard_EXPORT bool CheckSelfIntersectionsFast (Handle(GEOM_Object) theShape, - float deflection, - double tolerance, - Handle(TColStd_HSequenceOfInteger)& theIntersections); + float deflection, + double tolerance, + Handle(TColStd_HSequenceOfInteger)& theIntersections); Standard_EXPORT bool CheckBOPArguments (const Handle(GEOM_Object) &theShape); diff --git a/src/GEOMImpl/GEOMImpl_MeasureDriver.cxx b/src/GEOMImpl/GEOMImpl_MeasureDriver.cxx index 0fe1c4eaf..eb89ee9d6 100644 --- a/src/GEOMImpl/GEOMImpl_MeasureDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_MeasureDriver.cxx @@ -154,6 +154,7 @@ Standard_Integer GEOMImpl_MeasureDriver::Execute(Handle(TFunction_Logbook)& log) } int index = aCI.GetIndex(); + bool useOri = aCI.GetUseOri(); gp_Pnt aVertex; if (aShapeBase.ShapeType() == TopAbs_VERTEX) { @@ -161,23 +162,21 @@ Standard_Integer GEOMImpl_MeasureDriver::Execute(Handle(TFunction_Logbook)& log) Standard_NullObject::Raise("Vertex index is out of range"); else aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)); - } else if (aShapeBase.ShapeType() == TopAbs_EDGE) { - TopoDS_Vertex aV1, aV2; - TopoDS_Edge anEdgeE = TopoDS::Edge(aShapeBase); - - TopExp::Vertices(anEdgeE, aV1, aV2); - gp_Pnt aP1 = BRep_Tool::Pnt(aV1); - gp_Pnt aP2 = BRep_Tool::Pnt(aV2); - + } + else if (aShapeBase.ShapeType() == TopAbs_EDGE) { if (index < 0 || index > 1) Standard_NullObject::Raise("Vertex index is out of range"); - if ( ( anEdgeE.Orientation() == TopAbs_FORWARD && index == 0 ) || - ( anEdgeE.Orientation() == TopAbs_REVERSED && index == 1 ) ) - aVertex = aP1; - else - aVertex = aP2; - } else if (aShapeBase.ShapeType() == TopAbs_WIRE) { + TopoDS_Edge anEdgeE = TopoDS::Edge(aShapeBase); + if ( anEdgeE.Orientation() != TopAbs_FORWARD && + anEdgeE.Orientation() != TopAbs_REVERSED ) + anEdgeE.Orientation( TopAbs_FORWARD ); + + TopoDS_Vertex aV[2]; + TopExp::Vertices(anEdgeE, aV[0], aV[1], useOri ); + aVertex = BRep_Tool::Pnt( aV[ index ]); + } + else if (aShapeBase.ShapeType() == TopAbs_WIRE) { TopTools_IndexedMapOfShape anEdgeShapes; TopTools_IndexedMapOfShape aVertexShapes; TopoDS_Vertex aV1, aV2; @@ -198,11 +197,12 @@ Standard_Integer GEOMImpl_MeasureDriver::Execute(Handle(TFunction_Logbook)& log) if (index < 0 || index > aVertexShapes.Extent()) Standard_NullObject::Raise("Vertex index is out of range"); - if (aWire.Orientation() == TopAbs_FORWARD) + if ( aWire.Orientation() == TopAbs_FORWARD || !useOri ) aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aVertexShapes(index+1))); else aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aVertexShapes(aVertexShapes.Extent() - index))); - } else { + } + else { Standard_NullObject::Raise("Shape for vertex calculation is not an edge or wire"); } @@ -352,6 +352,7 @@ GetCreationInformation(std::string& theOperationName, theOperationName = "GetVertexByIndex"; AddParam( theParams, "Object", aCI.GetBase() ); AddParam( theParams, "Index", aCI.GetIndex() ); + AddParam( theParams, "Oriented", aCI.GetUseOri() ); break; case VECTOR_FACE_NORMALE: theOperationName = "NORMALE"; diff --git a/src/GEOM_I/GEOM_BaseObject_i.cc b/src/GEOM_I/GEOM_BaseObject_i.cc index 953995317..a5b14ec7a 100644 --- a/src/GEOM_I/GEOM_BaseObject_i.cc +++ b/src/GEOM_I/GEOM_BaseObject_i.cc @@ -312,3 +312,14 @@ GEOM::CreationInformationSeq* GEOM_BaseObject_i::GetCreationInformation() return info._retn(); } + +//================================================================================ +/*! + * \brief Return the engine creating this object + */ +//================================================================================ + +GEOM::GEOM_Gen_ptr GEOM_BaseObject_i::GetGen() +{ + return GEOM::GEOM_Gen::_duplicate( _engine ); +} diff --git a/src/GEOM_I/GEOM_BaseObject_i.hh b/src/GEOM_I/GEOM_BaseObject_i.hh index c57864b48..ff83a0017 100644 --- a/src/GEOM_I/GEOM_BaseObject_i.hh +++ b/src/GEOM_I/GEOM_BaseObject_i.hh @@ -66,6 +66,8 @@ class GEOM_I_EXPORT GEOM_BaseObject_i : public virtual POA_GEOM::GEOM_BaseObject virtual GEOM::CreationInformationSeq* GetCreationInformation(); + virtual GEOM::GEOM_Gen_ptr GetGen(); + Handle(::GEOM_BaseObject) GetImpl() { return _impl; } protected: diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.cc b/src/GEOM_I/GEOM_IMeasureOperations_i.cc index cc32f3410..b334c6e27 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.cc +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.cc @@ -440,8 +440,10 @@ GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass * GetVertexByIndex */ //============================================================================= -GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex - (GEOM::GEOM_Object_ptr theShape, CORBA::Long theIndex) +GEOM::GEOM_Object_ptr +GEOM_IMeasureOperations_i::GetVertexByIndex( GEOM::GEOM_Object_ptr theShape, + CORBA::Long theIndex, + CORBA::Boolean theUseOri ) { GEOM::GEOM_Object_var aGEOMObject; @@ -453,7 +455,7 @@ GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex if ( aShape.IsNull() ) return aGEOMObject._retn(); // Get vertex by index - Handle(::GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex); + Handle(::GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex, theUseOri); if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn(); diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.hh b/src/GEOM_I/GEOM_IMeasureOperations_i.hh index a64895562..1a9595b5c 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.hh +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.hh @@ -63,7 +63,8 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i : GEOM::GEOM_Object_ptr theOptionalPoint); GEOM::GEOM_Object_ptr GetVertexByIndex (GEOM::GEOM_Object_ptr theObject, - CORBA::Long theIndex); + CORBA::Long theIndex, + CORBA::Boolean theUseOri); void GetInertia (GEOM::GEOM_Object_ptr theShape, CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13, diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index e4ebf8d5f..f41eb5fb4 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -11325,9 +11325,10 @@ class geomBuilder(GEOM._objref_GEOM_Gen): self._autoPublish(anObj, theName, "centerOfMass") return anObj - ## Get a vertex sub-shape by index depended with orientation. + ## Get a vertex sub-shape by index. # @param theShape Shape to find sub-shape. # @param theIndex Index to find vertex by this index (starting from zero) + # @param theUseOri To consider edge/wire orientation or not # @param theName Object name; when specified, this parameter is used # for result publication in the study. Otherwise, if automatic # publication is switched on, default value is used for result name. @@ -11336,13 +11337,14 @@ class geomBuilder(GEOM._objref_GEOM_Gen): # # @ref tui_measurement_tools_page "Example" @ManageTransactions("MeasuOp") - def GetVertexByIndex(self, theShape, theIndex, theName=None): + def GetVertexByIndex(self, theShape, theIndex, theUseOri=True, theName=None): """ - Get a vertex sub-shape by index depended with orientation. + Get a vertex sub-shape by index. Parameters: theShape Shape to find sub-shape. theIndex Index to find vertex by this index (starting from zero) + theUseOri To consider edge/wire orientation or not theName Object name; when specified, this parameter is used for result publication in the study. Otherwise, if automatic publication is switched on, default value is used for result name. @@ -11351,7 +11353,9 @@ class geomBuilder(GEOM._objref_GEOM_Gen): New GEOM.GEOM_Object, containing the created vertex. """ # Example: see GEOM_TestMeasures.py - anObj = self.MeasuOp.GetVertexByIndex(theShape, theIndex) + if isinstance( theUseOri, str ): # theUseOri was inserted before theName + theUseOri, theName = True, theUseOri + anObj = self.MeasuOp.GetVertexByIndex(theShape, theIndex, theUseOri) RaiseIfFailed("GetVertexByIndex", self.MeasuOp) self._autoPublish(anObj, theName, "vertex") return anObj @@ -11380,7 +11384,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen): """ # Example: see GEOM_TestMeasures.py # note: auto-publishing is done in self.GetVertexByIndex() - return self.GetVertexByIndex(theShape, 0, theName) + return self.GetVertexByIndex(theShape, 0, True, theName) ## Get the last vertex of wire/edge depended orientation. # @param theShape Shape to find last vertex. @@ -11407,7 +11411,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen): # Example: see GEOM_TestMeasures.py nb_vert = self.NumberOfSubShapes(theShape, self.ShapeType["VERTEX"]) # note: auto-publishing is done in self.GetVertexByIndex() - return self.GetVertexByIndex(theShape, (nb_vert-1), theName) + return self.GetVertexByIndex(theShape, (nb_vert-1), True, theName) ## Get a normale to the given face. If the point is not given, # the normale is calculated at the center of mass. From e2fe8c13602419e70e70ba96ac7a9e0b4ff05675 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 20 Dec 2019 15:54:12 +0300 Subject: [PATCH 2/3] Define IsParametrical and BreakLinks methods --- idl/GEOM_Gen.idl | 11 +++++++++++ src/GEOM_I/GEOM_Object_i.hh | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index fe78db396..eac174954 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -509,6 +509,17 @@ module GEOM */ GEOM_Object GetMainShape(); + /* + * \brief Returns true if the current object has connection to a parametrical model + * which can be modified by parameters change. + */ + boolean IsParametrical(); + + /* + * \brief Breaks links to parametrical mode for parametrical shape + */ + void BreakLinks(); + }; //# GEOM_Field diff --git a/src/GEOM_I/GEOM_Object_i.hh b/src/GEOM_I/GEOM_Object_i.hh index 5e7ea8d45..a3d61e205 100644 --- a/src/GEOM_I/GEOM_Object_i.hh +++ b/src/GEOM_I/GEOM_Object_i.hh @@ -81,6 +81,11 @@ class GEOM_I_EXPORT GEOM_Object_i : public virtual POA_GEOM::GEOM_Object, public virtual bool IsShape(); + virtual bool IsParametrical() { return false; } + + virtual void BreakLinks() {} + + Handle(::GEOM_Object) GetImpl() { return _impl; } private: From f1da3f8dedb593eb28542b24f0a09770adfd8334 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 23 Dec 2019 14:55:03 +0300 Subject: [PATCH 3/3] Transfer BreakLink from Object to Gen --- idl/GEOM_Gen.idl | 10 +++++----- src/GEOM_I/GEOM_Gen_i.hh | 3 +++ src/GEOM_I/GEOM_Object_i.hh | 2 -- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index eac174954..1087faba2 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -515,11 +515,6 @@ module GEOM */ boolean IsParametrical(); - /* - * \brief Breaks links to parametrical mode for parametrical shape - */ - void BreakLinks(); - }; //# GEOM_Field @@ -5154,6 +5149,11 @@ module GEOM inout string_array theSubEntries, inout string_array theOtherEntries); + + /* + * \brief Breaks links to parametrical mode for parametrical shape + */ + void BreakLink(in string theEntry); }; }; diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index 6178a4847..b59041d10 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -385,6 +385,9 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi void LoadPlugin(const std::string& theLibName); + + virtual void BreakLink(const char*) {} + private: ::GEOMImpl_Gen* _impl; diff --git a/src/GEOM_I/GEOM_Object_i.hh b/src/GEOM_I/GEOM_Object_i.hh index a3d61e205..cd314a564 100644 --- a/src/GEOM_I/GEOM_Object_i.hh +++ b/src/GEOM_I/GEOM_Object_i.hh @@ -83,8 +83,6 @@ class GEOM_I_EXPORT GEOM_Object_i : public virtual POA_GEOM::GEOM_Object, public virtual bool IsParametrical() { return false; } - virtual void BreakLinks() {} - Handle(::GEOM_Object) GetImpl() { return _impl; }