%shared_ptr(BuildAPI_Vertex)
%shared_ptr(BuildAPI_Wire)
%shared_ptr(BuildAPI_Polyline)
+%shared_ptr(BuildAPI_Interpolation)
// all supported interfaces
%include "BuildAPI_Compound.h"
%include "BuildAPI_Vertex.h"
%include "BuildAPI_Wire.h"
%include "BuildAPI_Polyline.h"
+%include "BuildAPI_Interpolation.h"
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "BuildAPI_Interpolation.h"
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+BuildAPI_Interpolation::BuildAPI_Interpolation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+//==================================================================================================
+BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const ModelHighAPI_Selection& theStartTangent,
+ const ModelHighAPI_Selection& theEndTangent,
+ const bool theIsClosed,
+ const bool theIsToReorder)
+: ModelHighAPI_Interface(theFeature)
+{
+ if(initialize()) {
+ setUseTangents(true);
+ setTangents(theStartTangent, theEndTangent);
+ setClosed(theIsClosed);
+ setReorder(theIsToReorder);
+ setBase(theBaseObjects);
+ }
+}
+
+//==================================================================================================
+BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const bool theIsClosed,
+ const bool theIsToReorder)
+ : ModelHighAPI_Interface(theFeature)
+{
+ if (initialize()) {
+ setClosed(theIsClosed);
+ setReorder(theIsToReorder);
+ setUseTangents(false);
+ setBase(theBaseObjects);
+ }
+}
+
+//==================================================================================================
+BuildAPI_Interpolation::~BuildAPI_Interpolation()
+{
+}
+
+//==================================================================================================
+void BuildAPI_Interpolation::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
+{
+ fillAttribute(theBaseObjects, mybaseObjects);
+
+ execute();
+}
+
+//==================================================================================================
+void BuildAPI_Interpolation::setClosed(const bool theIsClosed)
+{
+ fillAttribute(theIsClosed, myclosed);
+
+ execIfBaseNotEmpty();
+}
+
+void BuildAPI_Interpolation::setReorder(const bool theIsToReorder)
+{
+ fillAttribute(theIsToReorder, myreorder);
+
+ execIfBaseNotEmpty();
+}
+
+void BuildAPI_Interpolation::setUseTangents(const bool theIsToUseTangents)
+{
+ fillAttribute(theIsToUseTangents ? "true" : "", myuseTangents);
+
+ execIfBaseNotEmpty();
+}
+
+void BuildAPI_Interpolation::setTangents(const ModelHighAPI_Selection& theStartTangent,
+ const ModelHighAPI_Selection& theEndTangent)
+{
+ fillAttribute(theStartTangent, mystartTangent);
+ fillAttribute(theEndTangent, myendTangent);
+
+ execIfBaseNotEmpty();
+}
+
+//==================================================================================================
+void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ std::string aPartName = theDumper.name(aBase->document());
+
+ AttributeSelectionListPtr anAttrBaseObjects =
+ aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID());
+ AttributeSelectionPtr anAttrStartTangent =
+ aBase->selection(BuildPlugin_Interpolation::TANGENT_START_ID());
+ AttributeSelectionPtr anAttrEndTangent =
+ aBase->selection(BuildPlugin_Interpolation::TANGENT_END_ID());
+
+ theDumper << aBase << " = model.addInterpolation(" << aPartName << ", "
+ << anAttrBaseObjects << ", ";
+
+ if (anAttrStartTangent->isInitialized() && anAttrEndTangent->isInitialized()) {
+ theDumper << anAttrStartTangent << ", " << anAttrEndTangent << ", ";
+ }
+
+ theDumper << closed() << ", " << reorder() << ")" << std::endl;
+}
+
+//==================================================================================================
+InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const bool theIsClosed,
+ const bool theIsToReorder)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
+ return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
+ theBaseObjects,
+ theIsClosed,
+ theIsToReorder));
+}
+
+//==================================================================================================
+InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const ModelHighAPI_Selection& theStartTangent,
+ const ModelHighAPI_Selection& theEndTangent,
+ const bool theIsClosed,
+ const bool theIsToReorder)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
+ return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
+ theBaseObjects,
+ theStartTangent,
+ theEndTangent,
+ theIsClosed,
+ theIsToReorder));
+}
+
+//==================================================================================================
+void BuildAPI_Interpolation::execIfBaseNotEmpty()
+{
+ if (baseObjects()->size() > 0)
+ execute();
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef BuildAPI_Interpolation_H_
+#define BuildAPI_Interpolation_H_
+
+#include "BuildAPI.h"
+
+#include <BuildPlugin_Interpolation.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+#include <ModelHighAPI_Selection.h>
+
+class ModelHighAPI_Selection;
+
+/// \class BuildAPI_Interpolation
+/// \ingroup CPPHighAPI
+/// \brief Interface for Interpolation feature.
+class BuildAPI_Interpolation : public ModelHighAPI_Interface
+{
+public:
+ /// Constructor without values.
+ BUILDAPI_EXPORT
+ explicit BuildAPI_Interpolation(const FeaturePtr& theFeature);
+
+ /// Constructor with values.
+ BUILDAPI_EXPORT
+ explicit BuildAPI_Interpolation(const FeaturePtr& theFeature,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const ModelHighAPI_Selection& theStartTangent,
+ const ModelHighAPI_Selection& theEndTangent,
+ const bool theIsClosed, const bool theIsToReorder);
+
+ /// Constructor with base objects, closed and reorder parameters.
+ BUILDAPI_EXPORT
+ explicit BuildAPI_Interpolation(const FeaturePtr& theFeature,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const bool theIsClosed, const bool theIsToReorder);
+
+ /// Destructor.
+ BUILDAPI_EXPORT
+ virtual ~BuildAPI_Interpolation();
+
+ INTERFACE_6(BuildPlugin_Interpolation::ID(),
+ baseObjects, BuildPlugin_Interpolation::BASE_OBJECTS_ID(),
+ ModelAPI_AttributeSelectionList, /** Base objects */,
+ closed, BuildPlugin_Interpolation::CLOSED_ID(),
+ ModelAPI_AttributeBoolean, /** Closed flag */,
+ reorder, BuildPlugin_Interpolation::REORDER_ID(),
+ ModelAPI_AttributeBoolean, /** Reorder flag */,
+ useTangents, BuildPlugin_Interpolation::USE_TANGENTS_ID(),
+ ModelAPI_AttributeString, /** Use tangents flag */,
+ startTangent, BuildPlugin_Interpolation::TANGENT_START_ID(),
+ ModelAPI_AttributeSelection, /** Start point tangent */,
+ endTangent, BuildPlugin_Interpolation::TANGENT_END_ID(),
+ ModelAPI_AttributeSelection, /** End point tangent */)
+
+ /// Modify base attribute of the feature.
+ BUILDAPI_EXPORT
+ void setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects);
+
+ /// Set closed flag
+ BUILDAPI_EXPORT void setClosed(const bool theIsClosed);
+
+ /// Set reorder flag
+ BUILDAPI_EXPORT void setReorder(const bool theIsToReorder);
+
+ /// Set use tangents flag
+ BUILDAPI_EXPORT void setUseTangents(const bool theIsToUseTangents);
+
+ /// Set start and end tangents
+ BUILDAPI_EXPORT void setTangents(const ModelHighAPI_Selection& theStartTangent,
+ const ModelHighAPI_Selection& theEndTangent);
+
+ /// Dump wrapped feature
+ BUILDAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+
+private:
+ void execIfBaseNotEmpty();
+};
+
+/// Pointer on Interpolation object.
+typedef std::shared_ptr<BuildAPI_Interpolation> InterpolationPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create Interpolation feature.
+BUILDAPI_EXPORT
+InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const bool theIsClosed = false,
+ const bool theIsToReorder = false);
+
+/// \ingroup CPPHighAPI
+/// \brief Create Interpolation feature using tangents.
+BUILDAPI_EXPORT
+InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theBaseObjects,
+ const ModelHighAPI_Selection& theStartTangent,
+ const ModelHighAPI_Selection& theEndTangent,
+ const bool theIsClosed = false,
+ const bool theIsToReorder = false);
+
+#endif // BuildAPI_Interpolation_H_
#include "BuildAPI_Vertex.h"
#include "BuildAPI_Wire.h"
#include "BuildAPI_Polyline.h"
+ #include "BuildAPI_Interpolation.h"
#endif // FeaturesAPI_swig_H_
BuildAPI_Vertex.h
BuildAPI_Wire.h
BuildAPI_Polyline.h
+ BuildAPI_Interpolation.h
)
SET(PROJECT_SOURCES
BuildAPI_Vertex.cpp
BuildAPI_Wire.cpp
BuildAPI_Polyline.cpp
+ BuildAPI_Interpolation.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "BuildPlugin_Interpolation.h"
+
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <Events_InfoMessage.h>
+
+#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_CurveBuilder.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeExplorer.h>
+
+#include <algorithm>
+
+//=================================================================================================
+BuildPlugin_Interpolation::BuildPlugin_Interpolation()
+{
+}
+
+//=================================================================================================
+void BuildPlugin_Interpolation::initAttributes()
+{
+ data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
+ data()->addAttribute(CLOSED_ID(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(REORDER_ID(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(USE_TANGENTS_ID(), ModelAPI_AttributeString::typeId());
+ data()->addAttribute(TANGENT_START_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(TANGENT_END_ID(), ModelAPI_AttributeSelection::typeId());
+}
+
+//=================================================================================================
+static GeomDirPtr selectionToDir(const AttributeSelectionPtr& theSelection)
+{
+ GeomDirPtr aDir;
+ GeomEdgePtr anEdge;
+
+ GeomShapePtr aShape = theSelection->value();
+ if (!aShape && theSelection->context()) {
+ aShape = theSelection->context()->shape();
+ }
+
+ if (aShape && aShape->isEdge()) {
+ anEdge = GeomEdgePtr(new GeomAPI_Edge(aShape));
+ }
+
+ if (anEdge && anEdge->isLine()) {
+ aDir = anEdge->line()->direction();
+ }
+
+ return aDir;
+}
+
+//=================================================================================================
+void BuildPlugin_Interpolation::execute()
+{
+ // Get closed flag value
+ bool isClosed = boolean(CLOSED_ID())->value();
+
+ // Get reorder flag value
+ bool isToReorder = boolean(REORDER_ID())->value();
+
+ // Get use tangents flag value
+ bool isToUseTangents = !string(USE_TANGENTS_ID())->value().empty();
+
+ // Get tangent for start and end points
+ GeomDirPtr aDirStart, aDirEnd;
+ if (isToUseTangents) {
+ aDirStart = selectionToDir(selection(TANGENT_START_ID()));
+ aDirEnd = selectionToDir(selection(TANGENT_END_ID()));
+ }
+
+ // Get base objects list.
+ AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
+
+ // Collect points.
+ std::list<GeomPointPtr> aPoints;
+ std::set<GeomShapePtr> aContexts;
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+
+ GeomShapePtr aContextShape = aSelection->context()->shape();
+ aContexts.insert(aContextShape);
+
+ GeomShapePtr aShape = aSelection->value();
+ if (!aShape.get()) {
+ aShape = aContextShape;
+ }
+
+ GeomPointPtr aPoint = GeomAlgoAPI_PointBuilder::point(aShape);
+ aPoints.push_back(aPoint);
+ }
+
+ // Create curve from points
+ GeomEdgePtr anEdge =
+ GeomAlgoAPI_CurveBuilder::edge(aPoints, isClosed, isToReorder, aDirStart, aDirEnd);
+ if (!anEdge.get()) {
+ setError("Error: Result curve is empty.");
+ return;
+ }
+
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data());
+ std::set<GeomShapePtr>::const_iterator aContextIt = aContexts.begin();
+ for (; aContextIt != aContexts.end(); aContextIt++) {
+ aResultBody->storeModified(*aContextIt, anEdge, aContextIt == aContexts.begin() ? 0 : -2);
+ }
+ int aVertexIndex = 1;
+ for (GeomAPI_ShapeExplorer anExp(anEdge, GeomAPI_Shape::VERTEX); anExp.more(); anExp.next()) {
+ std::string aVertexName = "Vertex_" + std::to_string((long long)aVertexIndex);
+ aResultBody->generated(anExp.current(), aVertexName, aVertexIndex++);
+ }
+
+ setResult(aResultBody);
+}
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef BuildPlugin_Interpolation_H_
+#define BuildPlugin_Interpolation_H_
+
+#include "BuildPlugin.h"
+
+#include <ModelAPI_Feature.h>
+
+/// \class BuildPlugin_Interpolation
+/// \ingroup Plugins
+/// \brief Feature for creation of interpolation curve from set of points.
+class BuildPlugin_Interpolation : public ModelAPI_Feature
+{
+public:
+ /// Use plugin manager for features creation
+ BuildPlugin_Interpolation();
+
+ /// Feature kind.
+ inline static const std::string& ID()
+ {
+ static const std::string MY_ID("Interpolation");
+ return MY_ID;
+ }
+
+ /// Attribute name of base objects.
+ inline static const std::string& BASE_OBJECTS_ID()
+ {
+ static const std::string MY_BASE_OBJECTS_ID("base_objects");
+ return MY_BASE_OBJECTS_ID;
+ }
+
+ /// Attribute name of closed flag.
+ inline static const std::string& CLOSED_ID()
+ {
+ static const std::string MY_CLOSED_ID("closed");
+ return MY_CLOSED_ID;
+ }
+
+ /// Attribute name of reorder flag.
+ inline static const std::string& REORDER_ID()
+ {
+ static const std::string MY_REORDER_ID("reorder");
+ return MY_REORDER_ID;
+ }
+
+ /// Attribute name of use tangents flag.
+ inline static const std::string& USE_TANGENTS_ID()
+ {
+ static const std::string MY_USE_TANGENTS_ID("use_tangents");
+ return MY_USE_TANGENTS_ID;
+ }
+
+ /// Attribute name of tangent for start point.
+ inline static const std::string& TANGENT_START_ID()
+ {
+ static const std::string MY_TANGENT_START_ID("tangent_start");
+ return MY_TANGENT_START_ID;
+ }
+
+ /// Attribute name of tangent for end point.
+ inline static const std::string& TANGENT_END_ID()
+ {
+ static const std::string MY_TANGENT_END_ID("tangent_end");
+ return MY_TANGENT_END_ID;
+ }
+
+ /// Default value of the closed attribute
+ inline static bool CLOSED_DEFAULT() { return false; }
+
+ /// \return the kind of a feature.
+ BUILDPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = BuildPlugin_Interpolation::ID();
+ return MY_KIND;
+ }
+
+ /// Request for initialization of data model of the feature: adding all attributes.
+ BUILDPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Creates a new part document if needed.
+ BUILDPLUGIN_EXPORT virtual void execute();
+};
+
+#endif
#include <BuildPlugin_Edge.h>
#include <BuildPlugin_Wire.h>
#include <BuildPlugin_Polyline.h>
+#include <BuildPlugin_Interpolation.h>
#include <BuildPlugin_Face.h>
#include <BuildPlugin_Shell.h>
#include <BuildPlugin_Solid.h>
return FeaturePtr(new BuildPlugin_Wire());
} else if (theFeatureID == BuildPlugin_Polyline::ID()) {
return FeaturePtr(new BuildPlugin_Polyline());
+ } else if (theFeatureID == BuildPlugin_Interpolation::ID()) {
+ return FeaturePtr(new BuildPlugin_Interpolation());
} else if (theFeatureID == BuildPlugin_Face::ID()) {
return FeaturePtr(new BuildPlugin_Face());
} else if(theFeatureID == BuildPlugin_Shell::ID()) {
#include <Events_InfoMessage.h>
#include <GeomAPI_ShapeExplorer.h>
-#include <GeomAlgoAPI_WireBuilder.h>
#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
<translation>Points list should contain at least 2 items</translation>
</message>
</context>
+ <context>
+ <name>Interpolation:GeomValidators_MinObjectsSelected</name>
+ <message>
+ <source>Error: Attribute "%1" should contain at least %2 items.</source>
+ <translation>Points list should contain at least 2 items</translation>
+ </message>
+ </context>
</TS>
BuildPlugin_Edge.h
BuildPlugin_Wire.h
BuildPlugin_Polyline.h
+ BuildPlugin_Interpolation.h
BuildPlugin_Face.h
BuildPlugin_Shell.h
BuildPlugin_Solid.h
BuildPlugin_Edge.cpp
BuildPlugin_Wire.cpp
BuildPlugin_Polyline.cpp
+ BuildPlugin_Interpolation.cpp
BuildPlugin_Face.cpp
BuildPlugin_Shell.cpp
BuildPlugin_Solid.cpp
edge_widget.xml
wire_widget.xml
polyline_widget.xml
+ interpolation_widget.xml
face_widget.xml
shell_widget.xml
solid_widget.xml
TestEdge.py
TestWire.py
TestPolyline.py
+ TestInterpolation.py
TestFace.py
TestShell.py
TestSolid.py
--- /dev/null
+## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+##
+## 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, or (at your option) any later version.
+##
+## 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<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+
+# Create document
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+# Create sketch
+#
+# 2 4
+#
+# 3
+#
+# 1 5
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchPoint_1 = Sketch_1.addPoint(0, 0)
+SketchPoint_2 = Sketch_1.addPoint(0, 50)
+SketchPoint_3 = Sketch_1.addPoint(25, 25)
+SketchPoint_4 = Sketch_1.addPoint(50, 50)
+SketchPoint_5 = Sketch_1.addPoint(50, 0)
+
+SketchLine_1 = Sketch_1.addLine(0, 0, -45, -45)
+SketchLine_2 = Sketch_1.addLine(0, 0, 45, 45)
+model.do()
+
+# Get sketch points
+base_name = "Sketch_1/Vertex-SketchPoint_"
+p_1, p_2, p_3, p_4, p_5 = [model.selection("VERTEX", base_name + str(i + 1)) for i in range(0, 5)]
+
+# Get sketch edges
+Tangent_1 = model.selection("EDGE", "Sketch_1/Edge-SketchLine_1")
+Tangent_2 = model.selection("EDGE", "Sketch_1/Edge-SketchLine_2")
+
+# =============================================================================
+# Test 1. Create curve 1-2-3-4-5, closed off, reorder off, without tangents
+# =============================================================================
+Interpolation_1 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4, p_5], False, False)
+model.do()
+
+model.checkBooleansResult(Interpolation_1, model, 1, [0], [0], [0], [1], [2])
+
+# # =============================================================================
+# # Test 2. Create curve 1-2-3-4-5-1, closed on, reorder off, without tangents
+# # =============================================================================
+Interpolation_2 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4, p_5], True, False)
+model.do()
+
+model.checkBooleansResult(Interpolation_2, model, 1, [0], [0], [0], [1], [2])
+
+# # =============================================================================
+# # Test 3. Create curve 1-2-3-4, closed off, reorder on, without tangents
+# # =============================================================================
+Interpolation_3 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4], False, True)
+model.do()
+
+model.checkBooleansResult(Interpolation_3, model, 1, [0], [0], [0], [1], [2])
+
+# =============================================================================
+# Test 4. Create curve 1-2-3-5, closed on, reorder on, without tangents
+# =============================================================================
+Interpolation_4 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_5], True, True)
+model.do()
+
+model.checkBooleansResult(Interpolation_4, model, 1, [0], [0], [0], [1], [2])
+
+# =============================================================================
+# Test 5. Create curve 1-2-3-4-5, closed off, reorder off, with tangents
+# =============================================================================
+
+Interpolation_5 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4, p_5],
+ Tangent_1, Tangent_2, False, False)
+model.do()
+
+model.checkBooleansResult(Interpolation_5, model, 1, [0], [0], [0], [1], [2])
+
+# =============================================================================
+# Test 6. Try to create closed curve 1-2-1, closed off, reorder off, without tangents
+# =============================================================================
+Interpolation_6 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_1], False, False)
+model.do()
+
+# TODO uncomment
+#model.testNbResults(Interpolation_6, 0)
+
+# =============================================================================
+# Test 7. Try to create curve on a single point 3
+# =============================================================================
+Interpolation_7 = model.addInterpolation(Part_1_doc, [p_3], False, False)
+model.do()
+
+model.testNbResults(Interpolation_7, 0)
+
+# =============================================================================
+# Test 8. Create curve on box vertices, closed off, reorder off, without tangents
+# =============================================================================
+Part_2 = model.addPart(partSet)
+Part_2_doc = Part_2.document()
+Box_1 = model.addBox(Part_2_doc, 10, 10, 10)
+
+point_names = ("Box_1_1/Back&Box_1_1/Left&Box_1_1/Bottom",
+ "Box_1_1/Back&Box_1_1/Left&Box_1_1/Top",
+ "Box_1_1/Front&Box_1_1/Left&Box_1_1/Top",
+ "Box_1_1/Front&Box_1_1/Left&Box_1_1/Bottom",
+ "Box_1_1/Front&Box_1_1/Right&Box_1_1/Bottom",
+ "Box_1_1/Front&Box_1_1/Right&Box_1_1/Top",
+ "Box_1_1/Back&Box_1_1/Right&Box_1_1/Top",
+ "Box_1_1/Back&Box_1_1/Right&Box_1_1/Bottom")
+points = [model.selection("VERTEX", name) for name in point_names]
+
+Interpolation_8 = model.addInterpolation(Part_2_doc, points, False, False)
+model.do()
+
+model.checkBooleansResult(Interpolation_8, model, 1, [0], [0], [0], [1], [2])
+
+# =============================================================================
+# Test 9. Create curve on box vertices, closed off, reorder off, with tangents
+# =============================================================================
+Part_3 = model.addPart(partSet)
+Part_3_doc = Part_3.document()
+Box_1 = model.addBox(Part_3_doc, 20, 30, 40)
+
+points = [model.selection("VERTEX", name) for name in point_names]
+Tangent_1 = model.selection("EDGE", "Box_1_1/Back&Box_1_1/Top")
+Tangent_2 = model.selection("EDGE", "Box_1_1/Left&Box_1_1/Top")
+
+Interpolation_9 = model.addInterpolation(Part_3_doc, points,
+ Tangent_1, Tangent_2, False, False)
+model.do()
+
+model.checkBooleansResult(Interpolation_9, model, 1, [0], [0], [0], [1], [2])
+
+# =============================================================================
+# Test 10. Create curve using equal vertices
+# =============================================================================
+Part_4 = model.addPart(partSet)
+Part_4_doc = Part_4.document()
+
+Point_1 = model.addPoint(Part_4_doc, 0, 0, 0)
+Point_2 = model.addPoint(Part_4_doc, 0, 0, 0)
+P_1 = model.selection("VERTEX", "Point_1")
+P_2 = model.selection("VERTEX", "Point_2")
+
+# TODO uncomment
+#Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2],
+# False, False)
+#model.do()
+#model.testNbResults(Interpolation_10, 0)
+
+# =============================================================================
+# Test 11. Check subshapes naming
+# =============================================================================
+model.testHaveNamingSubshapes(Interpolation_5, model, Part_1_doc)
+model.testHaveNamingSubshapes(Interpolation_9, model, Part_3_doc)
+model.end()
+
+# =============================================================================
+# Test 12. Check Python dump
+# =============================================================================
+assert(model.checkPythonDump())
model.checkBooleansResult(Polyline_8, model, 1, [0], [0], [0], [8], [8*2])
# =============================================================================
-# Test 9. Check subshapes naming
+# Test 9. Create polyline using equal vertices
+# =============================================================================
+Part_4 = model.addPart(partSet)
+Part_4_doc = Part_4.document()
+
+Point_1 = model.addPoint(Part_4_doc, 0, 0, 0)
+Point_2 = model.addPoint(Part_4_doc, 0, 0, 0)
+P_1 = model.selection("VERTEX", "Point_1")
+P_2 = model.selection("VERTEX", "Point_2")
+
+# TODO uncomment
+#Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
+#model.do()
+
+#model.testNbResults(Polyline_9, 0)
+
+# =============================================================================
+# Test 10. Check subshapes naming
# =============================================================================
model.testHaveNamingSubshapes(Polyline_1, model, Part_1_doc)
model.end()
# =============================================================================
-# Test 10. Check Python dump
+# Test 11. Check Python dump
# =============================================================================
assert(model.checkPythonDump())
\ No newline at end of file
--- /dev/null
+<!--
+Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+
+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, or (at your option) any later version.
+
+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<mailto:webmaster.salome@opencascade.com>
+-->
+
+<source>
+ <multi_selector id="base_objects"
+ label="Points and vertices:"
+ tooltip="Select points or vertices objects."
+ type_choice="vertices"
+ concealment="true">
+ </multi_selector>
+ <boolvalue id="closed" label="Closed" tooltip="Makes the curve closed." default="false"/>
+ <boolvalue id="reorder" label="Reorder" tooltip="Changes the order of points to construct the shortest curve." default="false"/>
+ <optionalbox id="use_tangents" title="Tangents" default="false">
+ <shape_selector id="tangent_start"
+ icon="icons/Features/axis.png"
+ label="Start"
+ tooltip="Select vector tangent to the start of curve"
+ shape_types="edge"
+ default="<start>">
+ <validator id="GeomValidators_ShapeType" parameters="empty,line"/>
+ </shape_selector>
+ <shape_selector id="tangent_end"
+ icon="icons/Features/axis.png"
+ label="End"
+ tooltip="Select vector tangent to the end of curve"
+ shape_types="edge"
+ default="<end>">
+ <validator id="GeomValidators_ShapeType" parameters="empty,line"/>
+ </shape_selector>
+ </optionalbox>
+ <validator id="GeomValidators_MinObjectsSelected" parameters="base_objects,2"/>
+</source>
<feature id="Edge" title="Edge" tooltip ="Create an edge from sketch edges and edge objects" icon="icons/Build/feature_edge.png">
<source path="edge_widget.xml"/>
</feature>
+ <feature id="Interpolation" title="Interpolation" tooltip ="Create an interpolation curve from points" icon="icons/Build/feature_interpolation.png">
+ <source path="interpolation_widget.xml"/>
+ </feature>
<feature id="Wire" title="Wire" tooltip ="Create a wire from sketch edges, edges and wires objects" icon="icons/Build/feature_wire.png">
<source path="wire_widget.xml"/>
</feature>
/// Returns true if the current edge is geometrically equal to the given edge.
GEOMAPI_EXPORT
- bool isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const;
+ virtual bool isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const;
};
//! Pointer on the object
GeomAlgoAPI_Fillet.h
GeomAlgoAPI_SortListOfShapes.h
GeomAlgoAPI_Filling.h
+ GeomAlgoAPI_CurveBuilder.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_Fillet.cpp
GeomAlgoAPI_SortListOfShapes.cpp
GeomAlgoAPI_Filling.cpp
+ GeomAlgoAPI_CurveBuilder.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "GeomAlgoAPI_CurveBuilder.h"
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_ShapeExplorer.h>
+
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
+#include <GeomAPI_Interpolate.hxx>
+#include <gp_Pnt.hxx>
+#include <Precision.hxx>
+
+
+static void reorder(Handle(TColgp_HArray1OfPnt) thePoints);
+
+//=================================================================================================
+GeomEdgePtr GeomAlgoAPI_CurveBuilder::edge(const std::list<GeomPointPtr>& thePoints,
+ const bool theIsClosed,
+ const bool theIsToReorder,
+ const GeomDirPtr& theStartTangent,
+ const GeomDirPtr& theEndTangent)
+{
+ // Prepare points array
+ Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt(1, (int)thePoints.size());
+ std::list<GeomPointPtr>::const_iterator anIt = thePoints.begin();
+ for (int i = 1; anIt != thePoints.end(); anIt++, i++) {
+ GeomPointPtr aPoint = *anIt;
+ aPoints->SetValue(i, aPoint->impl<gp_Pnt>());
+ }
+
+ // Reorder points if required
+ if (theIsToReorder) {
+ reorder(aPoints);
+ }
+
+ // If the curve to be closed - remove last point if it is too close to the first one
+ bool isClose = aPoints->First().Distance(aPoints->Last()) <= gp::Resolution();
+ if (isClose && theIsClosed) {
+ aPoints->Resize(aPoints->Lower(), aPoints->Upper() - 1, Standard_True);
+ }
+
+ // Initialize interpolator
+ GeomAPI_Interpolate anInterp(aPoints, theIsClosed, gp::Resolution());
+
+ // Assign tangents if defined
+ if (theStartTangent && theEndTangent) {
+ gp_Dir aDir = theStartTangent->impl<gp_Dir>();
+ gp_Vec anInitialTangent(aDir.XYZ());
+ aDir = theEndTangent->impl<gp_Dir>();
+ gp_Vec aFinalTangent(aDir.XYZ());
+
+ anInterp.Load(anInitialTangent, aFinalTangent);
+ }
+
+ // Compute
+ if (aPoints->Length() > 1) {
+ anInterp.Perform();
+ }
+
+ // Set result in form of edge
+ TopoDS_Edge anEdge;
+ if (anInterp.IsDone()) {
+ anEdge = BRepBuilderAPI_MakeEdge(anInterp.Curve()).Edge();
+ }
+
+ GeomEdgePtr aResultShape(new GeomAPI_Edge);
+ aResultShape->setImpl(new TopoDS_Shape(anEdge));
+
+ return aResultShape;
+}
+
+//================ Auxiliary functions ========================================================
+void reorder(Handle(TColgp_HArray1OfPnt) thePoints)
+{
+ if (thePoints->Length() < 3) {
+ return;
+ }
+
+ int aNbPoints = thePoints->Length();
+ int aNbDup = 0;
+ gp_Pnt aPrevPnt = thePoints->Value(1);
+ for (int i = 1; i < aNbPoints - 1; i++) {
+ gp_Pnt aPnt = thePoints->Value(i);
+ int aNearest = 0;
+ double aMinDist = RealLast();
+ for (int j = i + 1; j <= aNbPoints; j++) {
+ double aDist = aPnt.SquareDistance(thePoints->Value(j));
+ if (aDist < aMinDist && (aMinDist - aDist) > Precision::Confusion()) {
+ aNearest = j;
+ aMinDist = aDist;
+ }
+ }
+ if (aNearest > 0 && aNearest != i + 1) {
+ // Keep given order of points to use it in case of equidistant candidates
+ // .-<---<-.
+ // / \
+ // o o o c o->o->o->o->n o o
+ // | | |
+ // i i+1 nearest
+ gp_Pnt aNearestPnt = thePoints->Value(aNearest);
+ for (int j = aNearest; j > i + 1; j--) {
+ thePoints->SetValue(j, thePoints->Value(j - 1));
+ }
+ thePoints->SetValue(i + 1, aNearestPnt);
+ }
+ if (aPrevPnt.Distance(thePoints->Value(i + 1)) <= Precision::Confusion())
+ aNbDup++;
+ else
+ aPrevPnt = thePoints->Value(i + 1);
+ }
+
+ if (aNbDup > 0) {
+ Handle(TColgp_HArray1OfPnt) aTmpPoints = new TColgp_HArray1OfPnt(1, aNbPoints - aNbDup);
+ for (int j = 1, i = 1; i <= aNbPoints; i++) {
+ if (i == 1 || aPrevPnt.Distance(thePoints->Value(i)) > Precision::Confusion()) {
+ aTmpPoints->SetValue(j++, thePoints->Value(i));
+ aPrevPnt = thePoints->Value(i);
+ }
+ }
+ thePoints = aTmpPoints;
+ }
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef GeomAlgoAPI_CurveBuilder_H_
+#define GeomAlgoAPI_CurveBuilder_H_
+
+#include "GeomAlgoAPI.h"
+
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Edge.h>
+
+/// \class GeomAlgoAPI_CurveBuilder
+/// \ingroup DataAlgo
+/// \brief Allows to create interpolation curve.
+class GeomAlgoAPI_CurveBuilder
+{
+ public:
+ /// \brief Creates an interpolation curve from points.
+ /// \param[in] thePoints list of points.
+ /// \param[in] theIsClosed defines whether the curve to be closed.
+ /// \param[in] theIsToReorder defines whether to change the order of points to construct
+ /// the shortest curve.
+ /// \param[in] theStartTangent vector tangent to the start of curve.
+ /// \param[in] theEndTangent vector tangent to the end of curve.
+ /// \return Interpolation curve (edge). Empty in case of error or bad input.
+ GEOMALGOAPI_EXPORT static GeomEdgePtr edge(const std::list<GeomPointPtr>& thePoints,
+ const bool theIsClosed,
+ const bool theIsToReorder,
+ const GeomDirPtr& theStartTangent,
+ const GeomDirPtr& theEndTangent);
+};
+
+#endif
"""Package for Build plugin for the Parametric Geometry API of the Modeler.
"""
-from BuildAPI import addVertex, addEdge, addWire, addPolyline3D, addFace, addShell, addSolid, addCompSolid, addCompound
+from BuildAPI import addVertex, addEdge, addInterpolation, addWire, addPolyline3D, addFace, addShell, addSolid, addCompSolid, addCompound
from BuildAPI import addSubShapes
from BuildAPI import addFilling