Modification of GEOM interface

This commit is contained in:
vsv 2019-12-09 16:11:19 +03:00
parent e87935b0f9
commit b654dab419
10 changed files with 80 additions and 42 deletions

View File

@ -258,6 +258,7 @@ module GEOM
typedef sequence<ListOfDouble> ListOfListOfDouble; typedef sequence<ListOfDouble> ListOfListOfDouble;
typedef sequence<ListOfLong> ListOfListOfLong; typedef sequence<ListOfLong> ListOfListOfLong;
interface GEOM_Gen;
interface GEOM_Object; interface GEOM_Object;
interface GEOM_BaseObject; interface GEOM_BaseObject;
interface GEOM_Field; interface GEOM_Field;
@ -359,6 +360,11 @@ module GEOM
* \brief Return name of operation and values of parameters used for object creation * \brief Return name of operation and values of parameters used for object creation
*/ */
CreationInformationSeq GetCreationInformation(); CreationInformationSeq GetCreationInformation();
/*!
* \brief Return the engine creating this object
*/
GEOM_Gen GetGen();
}; };
//# GEOM_Object //# GEOM_Object
@ -4366,12 +4372,13 @@ module GEOM
GEOM_Object GetCentreOfMass (in GEOM_Object theShape); 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 theShape Shape (wire or edge) to find the vertex on it
* \param theIndex Index of vertex sub-shape * \param theIndex Index of vertex sub-shape
* \param theUseOri To consider edge/wire orientation or not
* \return New GEOM_Object, vertex. * \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. * \brief Get a vector, representing the normal of theFace.

View File

@ -24,15 +24,13 @@
// //
#include "GEOM_Function.hxx" #include "GEOM_Function.hxx"
//#define MEASURE_ARG_BASE 1
//#define MEASURE_ARG_POINT 2
class GEOMImpl_IMeasure class GEOMImpl_IMeasure
{ {
enum { enum {
MEASURE_ARG_BASE = 1, MEASURE_ARG_BASE = 1,
MEASURE_ARG_POINT = 2, MEASURE_ARG_POINT = 2,
MEASURE_INDEX = 3 MEASURE_INDEX = 3,
MEASURE_USE_ORI = 4
}; };
public: public:
@ -52,6 +50,12 @@ class GEOMImpl_IMeasure
int GetIndex() { return _func->GetInteger(MEASURE_INDEX); } 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: private:
Handle(GEOM_Function) _func; Handle(GEOM_Function) _func;

View File

@ -850,7 +850,8 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
//============================================================================= //=============================================================================
Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
(Handle(GEOM_Object) theShape, (Handle(GEOM_Object) theShape,
Standard_Integer theIndex) Standard_Integer theIndex,
Standard_Boolean theUseOri)
{ {
SetErrorCode(KO); SetErrorCode(KO);
@ -873,6 +874,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
GEOMImpl_IMeasure aCI (aFunction); GEOMImpl_IMeasure aCI (aFunction);
aCI.SetBase(aRefShape); aCI.SetBase(aRefShape);
aCI.SetIndex(theIndex); aCI.SetIndex(theIndex);
aCI.SetUseOri(theUseOri);
//Compute //Compute
try { try {
@ -888,7 +890,10 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
} }
//Make a Python command //Make a Python command
GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")"; GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex("
<< theShape << ", "
<< theIndex << ", "
<< theUseOri << ")";
SetErrorCode(OK); SetErrorCode(OK);
return aVertex; return aVertex;

View File

@ -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) GetCentreOfMass (Handle(GEOM_Object) theShape);
Standard_EXPORT Handle(GEOM_Object) GetVertexByIndex (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, Standard_EXPORT Handle(GEOM_Object) GetNormal (Handle(GEOM_Object) theFace,
Handle(GEOM_Object) theOptionalPoint); Handle(GEOM_Object) theOptionalPoint);

View File

@ -154,6 +154,7 @@ Standard_Integer GEOMImpl_MeasureDriver::Execute(Handle(TFunction_Logbook)& log)
} }
int index = aCI.GetIndex(); int index = aCI.GetIndex();
bool useOri = aCI.GetUseOri();
gp_Pnt aVertex; gp_Pnt aVertex;
if (aShapeBase.ShapeType() == TopAbs_VERTEX) { 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"); Standard_NullObject::Raise("Vertex index is out of range");
else else
aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)); aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase));
} else if (aShapeBase.ShapeType() == TopAbs_EDGE) { }
TopoDS_Vertex aV1, aV2; else if (aShapeBase.ShapeType() == TopAbs_EDGE) {
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);
if (index < 0 || index > 1) if (index < 0 || index > 1)
Standard_NullObject::Raise("Vertex index is out of range"); Standard_NullObject::Raise("Vertex index is out of range");
if ( ( anEdgeE.Orientation() == TopAbs_FORWARD && index == 0 ) || TopoDS_Edge anEdgeE = TopoDS::Edge(aShapeBase);
( anEdgeE.Orientation() == TopAbs_REVERSED && index == 1 ) ) if ( anEdgeE.Orientation() != TopAbs_FORWARD &&
aVertex = aP1; anEdgeE.Orientation() != TopAbs_REVERSED )
else anEdgeE.Orientation( TopAbs_FORWARD );
aVertex = aP2;
} else if (aShapeBase.ShapeType() == TopAbs_WIRE) { 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 anEdgeShapes;
TopTools_IndexedMapOfShape aVertexShapes; TopTools_IndexedMapOfShape aVertexShapes;
TopoDS_Vertex aV1, aV2; TopoDS_Vertex aV1, aV2;
@ -198,11 +197,12 @@ Standard_Integer GEOMImpl_MeasureDriver::Execute(Handle(TFunction_Logbook)& log)
if (index < 0 || index > aVertexShapes.Extent()) if (index < 0 || index > aVertexShapes.Extent())
Standard_NullObject::Raise("Vertex index is out of range"); 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))); aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aVertexShapes(index+1)));
else else
aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aVertexShapes(aVertexShapes.Extent() - index))); 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"); Standard_NullObject::Raise("Shape for vertex calculation is not an edge or wire");
} }
@ -352,6 +352,7 @@ GetCreationInformation(std::string& theOperationName,
theOperationName = "GetVertexByIndex"; theOperationName = "GetVertexByIndex";
AddParam( theParams, "Object", aCI.GetBase() ); AddParam( theParams, "Object", aCI.GetBase() );
AddParam( theParams, "Index", aCI.GetIndex() ); AddParam( theParams, "Index", aCI.GetIndex() );
AddParam( theParams, "Oriented", aCI.GetUseOri() );
break; break;
case VECTOR_FACE_NORMALE: case VECTOR_FACE_NORMALE:
theOperationName = "NORMALE"; theOperationName = "NORMALE";

View File

@ -312,3 +312,14 @@ GEOM::CreationInformationSeq* GEOM_BaseObject_i::GetCreationInformation()
return info._retn(); return info._retn();
} }
//================================================================================
/*!
* \brief Return the engine creating this object
*/
//================================================================================
GEOM::GEOM_Gen_ptr GEOM_BaseObject_i::GetGen()
{
return GEOM::GEOM_Gen::_duplicate( _engine );
}

View File

@ -66,6 +66,8 @@ class GEOM_I_EXPORT GEOM_BaseObject_i : public virtual POA_GEOM::GEOM_BaseObject
virtual GEOM::CreationInformationSeq* GetCreationInformation(); virtual GEOM::CreationInformationSeq* GetCreationInformation();
virtual GEOM::GEOM_Gen_ptr GetGen();
Handle(::GEOM_BaseObject) GetImpl() { return _impl; } Handle(::GEOM_BaseObject) GetImpl() { return _impl; }
protected: protected:

View File

@ -440,8 +440,10 @@ GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
* GetVertexByIndex * GetVertexByIndex
*/ */
//============================================================================= //=============================================================================
GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex GEOM::GEOM_Object_ptr
(GEOM::GEOM_Object_ptr theShape, CORBA::Long theIndex) GEOM_IMeasureOperations_i::GetVertexByIndex( GEOM::GEOM_Object_ptr theShape,
CORBA::Long theIndex,
CORBA::Boolean theUseOri )
{ {
GEOM::GEOM_Object_var aGEOMObject; GEOM::GEOM_Object_var aGEOMObject;
@ -453,7 +455,7 @@ GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex
if ( aShape.IsNull() ) return aGEOMObject._retn(); if ( aShape.IsNull() ) return aGEOMObject._retn();
// Get vertex by index // 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()) if (!GetOperations()->IsDone() || anObject.IsNull())
return aGEOMObject._retn(); return aGEOMObject._retn();

View File

@ -63,7 +63,8 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i :
GEOM::GEOM_Object_ptr theOptionalPoint); GEOM::GEOM_Object_ptr theOptionalPoint);
GEOM::GEOM_Object_ptr GetVertexByIndex (GEOM::GEOM_Object_ptr theObject, 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, void GetInertia (GEOM::GEOM_Object_ptr theShape,
CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13, CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,

View File

@ -11325,9 +11325,10 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
self._autoPublish(anObj, theName, "centerOfMass") self._autoPublish(anObj, theName, "centerOfMass")
return anObj 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 theShape Shape to find sub-shape.
# @param theIndex Index to find vertex by this index (starting from zero) # @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 # @param theName Object name; when specified, this parameter is used
# for result publication in the study. Otherwise, if automatic # for result publication in the study. Otherwise, if automatic
# publication is switched on, default value is used for result name. # 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" # @ref tui_measurement_tools_page "Example"
@ManageTransactions("MeasuOp") @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: Parameters:
theShape Shape to find sub-shape. theShape Shape to find sub-shape.
theIndex Index to find vertex by this index (starting from zero) 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 theName Object name; when specified, this parameter is used
for result publication in the study. Otherwise, if automatic for result publication in the study. Otherwise, if automatic
publication is switched on, default value is used for result name. 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. New GEOM.GEOM_Object, containing the created vertex.
""" """
# Example: see GEOM_TestMeasures.py # 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) RaiseIfFailed("GetVertexByIndex", self.MeasuOp)
self._autoPublish(anObj, theName, "vertex") self._autoPublish(anObj, theName, "vertex")
return anObj return anObj
@ -11380,7 +11384,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
""" """
# Example: see GEOM_TestMeasures.py # Example: see GEOM_TestMeasures.py
# note: auto-publishing is done in self.GetVertexByIndex() # 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. ## Get the last vertex of wire/edge depended orientation.
# @param theShape Shape to find last vertex. # @param theShape Shape to find last vertex.
@ -11407,7 +11411,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
# Example: see GEOM_TestMeasures.py # Example: see GEOM_TestMeasures.py
nb_vert = self.NumberOfSubShapes(theShape, self.ShapeType["VERTEX"]) nb_vert = self.NumberOfSubShapes(theShape, self.ShapeType["VERTEX"])
# note: auto-publishing is done in self.GetVertexByIndex() # 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, ## Get a normale to the given face. If the point is not given,
# the normale is calculated at the center of mass. # the normale is calculated at the center of mass.