MODELHIGHAPI_EXPORT
void fillMessage(const std::shared_ptr<ModelAPI_ObjectMovedMessage>& theMessage) const;
+ std::shared_ptr<ModelAPI_Attribute> attr() const { return myAttribute; }
+ std::shared_ptr<ModelAPI_Object> object() const { return myObject; }
+
private:
enum VariantType { VT_ATTRIBUTE, VT_OBJECT } myVariantType;
std::shared_ptr<ModelAPI_Attribute> myAttribute;
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/addons_Features.xml DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
INSTALL(FILES __init__.py DESTINATION ${SHAPER_INSTALL_ADDONS})
-INSTALL(DIRECTORY macros/compoundVertices DESTINATION ${SHAPER_INSTALL_ADDONS}/macros)
-INSTALL(DIRECTORY macros/importParameters DESTINATION ${SHAPER_INSTALL_ADDONS}/macros)
+INSTALL(DIRECTORY macros DESTINATION ${SHAPER_INSTALL_ADDONS})
INSTALL(DIRECTORY macros/rectangle/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
INSTALL(DIRECTORY macros/compoundVertices/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
INCLUDE(UnitTest)
ADD_UNIT_TESTS(
- #TestRectangle.py
+ TestRectangle.py
+ TestRectangleCentered.py
TestcompoundVertices.py
TestimportParameters.py
)
--- /dev/null
+# Copyright (C) 2021 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
+#
+
+from salome.shaper import model
+from salome.shaper import geom
+
+from SketchAPI import *
+
+import math
+
+def checkRectangle(lines, center, corner, tolerance = 1.e-7):
+ dx = corner.x() - center.x()
+ dy = corner.y() - center.y()
+ points = [geom.Pnt2d(center.x() - dx, center.y() - dy),
+ geom.Pnt2d(center.x() - dx, center.y() + dy),
+ geom.Pnt2d(center.x() + dx, center.y() + dy),
+ geom.Pnt2d(center.x() + dx, center.y() - dy)]
+ for i in range(0, 4):
+ line = SketchAPI_Line(lines[i])
+ sp = line.startPoint().pnt()
+ sp_ref = points[i-1]
+ assert(sp.distance(sp_ref) <= tolerance)
+ ep = line.endPoint().pnt()
+ ep_ref = points[i]
+ assert(ep.distance(ep_ref) <= tolerance)
+
+
+model.begin()
+partSet = model.moduleDocument()
+part = model.addPart(partSet).document()
+
+centerPoint = geom.Pnt2d(50, 50)
+endPoint = geom.Pnt2d(100, 100)
+
+sketch = model.addSketch(part, model.defaultPlane("XOY"))
+rectangle_1 = sketch.addRectangleCentered(centerPoint, endPoint)
+lines_1 = rectangle_1.lines()
+model.end()
+
+checkRectangle(lines_1, centerPoint, endPoint)
+
+model.begin()
+projection_1 = sketch.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
+point_1 = SketchAPI_Point(projection_1.createdFeature())
+
+rectangle_2 = sketch.addRectangleCentered(point_1.coordinates(), endPoint)
+lines_2 = rectangle_2.lines()
+model.end()
+
+checkRectangle(lines_2, geom.Pnt2d(0.0, 0.0), endPoint)
+
+model.begin()
+rectangle_3 = sketch.addRectangleCentered(SketchAPI_Line(lines_1[0]).startPoint(), SketchAPI_Line(lines_2[0]).endPoint())
+lines_3 = rectangle_3.lines()
+model.end()
+
+checkRectangle(lines_3, SketchAPI_Line(lines_1[0]).startPoint().pnt(), SketchAPI_Line(lines_2[0]).endPoint().pnt())
+
+assert(model.checkPythonDump())
"""
import ModelAPI
-#from macros.rectangle.feature import SketchPlugin_Rectangle
+from macros.rectangle.feature import SketchPlugin_Rectangle
from macros.compoundVertices.feature import compoundVertices
from macros.importParameters.feature import importParameters
"""Override ModelAPI_Plugin.createFeature()"""
aFeature = None
- #if theFeatureID == SketchPlugin_Rectangle.ID():
- # aFeature = SketchPlugin_Rectangle().__disown__()
- #el
- if theFeatureID == compoundVertices.ID():
+ if theFeatureID == SketchPlugin_Rectangle.ID():
+ aFeature = SketchPlugin_Rectangle().__disown__()
+ elif theFeatureID == compoundVertices.ID():
aFeature = compoundVertices().__disown__()
elif theFeatureID == importParameters.ID():
aFeature = importParameters().__disown__()
<plugin>
- <!--source path="@ADDONS_FOLDER_PATH@/macros/rectangle/widget.xml"/-->
+ <source path="@ADDONS_FOLDER_PATH@/macros/rectangle/widget.xml"/>
<source path="@ADDONS_FOLDER_PATH@/macros/compoundVertices/widget.xml"/>
<source path="@ADDONS_FOLDER_PATH@/macros/importParameters/widget.xml"/>
</plugin>
"""Returns ID of list containing lines created."""
return "RectangleList"
+ @staticmethod
+ def RECTANGLE_TYPE_ID():
+ """Returns ID of type of rectangle creation (by corners or by center and corner)."""
+ return "RectangleType"
+
+ @staticmethod
+ def RECTANGLE_BY_CORNERS_ID():
+ """Returns ID of creation type by opposite corners."""
+ return "RectangleTypeByCorners"
+
+ @staticmethod
+ def RECTANGLE_CENTERED_ID():
+ """Returns ID of creation type by center point and a corner."""
+ return "RectangleTypeCentered"
+
+ @staticmethod
+ def CENTER_ID():
+ """Returns ID of center point."""
+ return "RectCenterPoint"
+
+ @staticmethod
+ def CENTER_REF_ID():
+ """Returns ID of the reference to the center point."""
+ return "RectCenterPointRef"
+
+ @staticmethod
+ def CORNER_ID():
+ """Returns ID of a corner."""
+ return "RectCornerPoint"
+
+
def getKind(self):
"""Override Feature.getKind()"""
return SketchPlugin_Rectangle.ID()
# Creating list to store lines
self.data().addAttribute(self.LINES_LIST_ID(), ModelAPI.ModelAPI_AttributeRefList_typeId())
ModelAPI.ModelAPI_Session.get().validators().registerNotObligatory(self.getKind(), self.LINES_LIST_ID())
+ # Type of rectangle
+ self.data().addAttribute(self.RECTANGLE_TYPE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
+ # Center and corner of the rectangle
+ self.data().addAttribute(self.CENTER_ID(), GeomDataAPI.GeomDataAPI_Point2D_typeId())
+ self.data().addAttribute(self.CORNER_ID(), GeomDataAPI.GeomDataAPI_Point2D_typeId())
+
+ self.data().addAttribute(self.CENTER_REF_ID(), ModelAPI.ModelAPI_AttributeRefAttr_typeId())
+ ModelAPI.ModelAPI_Session.get().validators().registerNotObligatory(self.getKind(), self.CENTER_REF_ID())
def isMacro(self):
"""
aLinesList.append(aLine)
self.updateLines()
aNbLines = aLinesList.size()
+ aStartPoints = []
# Create constraints to keep the rectangle
for i in range (0, aNbLines):
aLine = ModelAPI.objectToFeature(aLinesList.object(i))
aRefAttrB = aCoincidence.refattr("ConstraintEntityB")
aRefAttrA.setAttr(aPrevLine.attribute("EndPoint"))
aRefAttrB.setAttr(aLine.attribute("StartPoint"))
+ aStartPoints.append(aLine.attribute("StartPoint"))
# Flags which show horizontal or vertical constraint is build for correponding line
self.__isHV = [False, False, False, False]
# Update coordinates of created lines
self.updateLines()
+ # Create auxiliary diagonals in case of centered rectangle
+ if self.string(self.RECTANGLE_TYPE_ID()).value() == self.RECTANGLE_CENTERED_ID():
+ aDiag1 = self.__sketch.addFeature("SketchLine")
+ aLinesList.append(aDiag1)
+ aDiag2 = self.__sketch.addFeature("SketchLine")
+ aLinesList.append(aDiag2)
+ # coincidences in corners
+ aPoints = [aDiag1.attribute("StartPoint"), aDiag2.attribute("StartPoint"),
+ aDiag1.attribute("EndPoint"), aDiag2.attribute("EndPoint")]
+ for i in range (0, len(aPoints)):
+ aCoincidence = self.__sketch.addFeature("SketchConstraintCoincidence")
+ aRefAttrA = aCoincidence.refattr("ConstraintEntityA")
+ aRefAttrB = aCoincidence.refattr("ConstraintEntityB")
+ aRefAttrA.setAttr(aStartPoints[i])
+ aRefAttrB.setAttr(aPoints[i])
+ # Update coordinates of created lines
+ self.updateLines()
+ aDiag1.execute()
+ aDiag2.execute()
+ # coincidences between center point and diagonals
+ refPnt = self.getReferencePoint(self.refattr(self.CENTER_REF_ID()))
+ if refPnt is not None:
+ for line in [aDiag1.lastResult(), aDiag2.lastResult()]:
+ aCoincidence = self.__sketch.addFeature("SketchConstraintCoincidence")
+ aCoincidence.refattr("ConstraintEntityA").setAttr(refPnt)
+ aCoincidence.refattr("ConstraintEntityB").setObject(line)
# Add horizontal and vertical constraint for the lines which already have result
- for i in range (0, aNbLines):
+ for i in range (0, 4):
if self.__isHV[i]:
continue
aLine = ModelAPI.objectToFeature(aLinesList.object(i))
self.__isHV[i] = True
def attributeChanged(self, theID):
- if theID == self.START_ID() or theID == self.END_ID():
+ if theID == self.START_ID() or theID == self.END_ID() or theID == self.CENTER_ID() or theID == self.CENTER_REF_ID() or theID == self.CORNER_ID():
# Search the sketch containing this rectangle
self.__sketch = None
aRefs = self.data().refsToMe();
aStartPoint = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.START_ID()))
aEndPoint = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.END_ID()))
- if aStartPoint.isInitialized() and aEndPoint.isInitialized():
+ aCenter = self.getPointByRef(self.attribute(self.CENTER_ID()), self.refattr(self.CENTER_REF_ID()))
+ aCorner = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.CORNER_ID()))
+ if (aStartPoint.isInitialized() and aEndPoint.isInitialized()) or (aCenter is not None and aCorner.isInitialized()):
self.updateLines()
else:
self.updateStartPoint()
aLine = ModelAPI.objectToFeature(aLinesList.object(i))
aLine.data().boolean("Auxiliary").setValue(anAuxiliary)
+ def getReferencePoint(self, theRef):
+ if theRef.isObject() and theRef.object() is not None:
+ feature = ModelAPI.ModelAPI_Feature.feature(theRef.object())
+ if feature.getKind() == "SketchPoint":
+ return feature.attribute("PointCoordinates")
+ else:
+ return theRef.attr()
+ return None
+
+ def getPointByRef(self, thePoint, theRef):
+ attr = thePoint
+ if theRef.isInitialized():
+ refPnt = self.getReferencePoint(theRef)
+ if refPnt is not None:
+ attr = refPnt
+ if attr is None or not attr.isInitialized():
+ return None
+ return GeomDataAPI.geomDataAPI_Point2D(attr).pnt()
def updateLines(self):
# Retrieving list of already created lines
aLinesList = self.reflist(self.LINES_LIST_ID())
- aNbLines = aLinesList.size()
- aStartPoint = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.START_ID()))
- aEndPoint = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.END_ID()))
- aX = [aStartPoint.x(), aStartPoint.x(), aEndPoint.x(), aEndPoint.x()]
- aY = [aStartPoint.y(), aEndPoint.y(), aEndPoint.y(), aStartPoint.y()]
+ aNbLines = min(aLinesList.size(), 4)
+ if self.string(self.RECTANGLE_TYPE_ID()).value() == self.RECTANGLE_CENTERED_ID():
+ aCenter = self.getPointByRef(self.attribute(self.CENTER_ID()), self.refattr(self.CENTER_REF_ID()))
+ aCorner = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.CORNER_ID()))
+ aStartX = 2.0 * aCenter.x() - aCorner.x()
+ aStartY = 2.0 * aCenter.y() - aCorner.y()
+ aX = [aStartX, aStartX, aCorner.x(), aCorner.x()]
+ aY = [aStartY, aCorner.y(), aCorner.y(), aStartY]
+ else:
+ aStartPoint = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.START_ID()))
+ aEndPoint = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.END_ID()))
+ aX = [aStartPoint.x(), aStartPoint.x(), aEndPoint.x(), aEndPoint.x()]
+ aY = [aStartPoint.y(), aEndPoint.y(), aEndPoint.y(), aStartPoint.y()]
anAuxiliary = self.data().boolean(self.AUXILIARY_ID()).value()
+ # do not recalculate the rectrangle after each update
+ wasBlocked = []
+ for i in range (0, aLinesList.size()):
+ wasBlocked.append(aLinesList.object(i).data().blockSendAttributeUpdated(True))
+
# Update coordinates of rectangle lines
for i in range (0, aNbLines):
aLine = ModelAPI.objectToFeature(aLinesList.object(i))
aLineEnd.setValue(aX[i], aY[i])
aLine.data().boolean("Auxiliary").setValue(anAuxiliary)
+ # Update auxiliary diagonals
+ if self.string(self.RECTANGLE_TYPE_ID()).value() == self.RECTANGLE_CENTERED_ID():
+ for i in range (aNbLines, aLinesList.size()):
+ aLine = ModelAPI.objectToFeature(aLinesList.object(i))
+ aLineStart = GeomDataAPI.geomDataAPI_Point2D(aLine.attribute("StartPoint"))
+ aLineEnd = GeomDataAPI.geomDataAPI_Point2D(aLine.attribute("EndPoint"))
+ aLineStart.setValue(aX[i-aNbLines-1], aY[i-aNbLines-1])
+ aLineEnd.setValue(aX[i-aNbLines+1], aY[i-aNbLines+1])
+ aLine.data().boolean("Auxiliary").setValue(True)
+
+ # update the rectangle
+ for i in range (0, aLinesList.size()):
+ aLinesList.object(i).data().blockSendAttributeUpdated(wasBlocked[i], True)
+
def updateStartPoint(self):
# Retrieving list of already created lines
aLinesList = self.reflist(self.LINES_LIST_ID())
aNbLines = aLinesList.size()
aStartPoint = GeomDataAPI.geomDataAPI_Point2D(self.attribute(self.START_ID()))
- aX = aStartPoint.x()
- aY = aStartPoint.y()
+ if aStartPoint.isInitialized:
+ aX = aStartPoint.x()
+ aY = aStartPoint.y()
+ else:
+ aCenter = self.getPointByRef(self.attribute(self.CENTER_ID()), self.refattr(self.CENTER_REF_ID()))
+ aX = aCenter.x()
+ aY = aCenter.y()
# Update coordinates of rectangle lines
for i in range (0, aNbLines):
<group id="Linear geometry">
<!-- SketchRectangle (python feature) -->
- <feature
- id="SketchRectangle"
- title="Rectangle"
- tooltip="Create rectangle"
- icon="icons/Addons/rectangle.png"
- helpfile="rectangleFeature.html">
- <sketch-2dpoint_selector id="RectStartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"
- enable_value="enable_by_preferences"/>
- <sketch-2dpoint_selector id="RectEndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
- enable_value="enable_by_preferences"/>
+ <feature id="SketchRectangle"
+ title="Rectangle"
+ tooltip="Create rectangle"
+ icon="icons/Addons/rectangle.png"
+ helpfile="rectangleFeature.html">
+ <toolbox id="RectangleType">
+ <box id="RectangleTypeByCorners"
+ icon="icons/Addons/rectangle_start_end.png"
+ title="Rectangle by corners">
+ <sketch-2dpoint_selector id="RectStartPoint"
+ accept_expressions="0"
+ title="Start point"
+ tooltip="Start point coordinates"
+ enable_value="enable_by_preferences"/>
+ <sketch-2dpoint_selector id="RectEndPoint"
+ accept_expressions="0"
+ title="End point"
+ tooltip="End point coordinates"
+ enable_value="enable_by_preferences"/>
+ </box>
+ <box id="RectangleTypeCentered"
+ icon="icons/Addons/rectangle_center_end.png"
+ title="Rectangle by center and corner">
+ <sketch-2dpoint_selector id="RectCenterPoint"
+ reference_attribute="RectCenterPointRef"
+ accept_expressions="0"
+ title="Center"
+ tooltip="Center point coordinates"
+ enable_value="enable_by_preferences"/>
+ <sketch-2dpoint_selector id="RectCornerPoint"
+ accept_expressions="0"
+ title="Corner"
+ tooltip="Rectangle's corner coordinates"
+ enable_value="enable_by_preferences"/>
+ </box>
+ </toolbox>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
<validator id="GeomValidators_Different" parameters="RectStartPoint,RectEndPoint"/>
</feature>
SketchAPI_MacroCircle.h
SketchAPI_MacroEllipse.h
SketchAPI_MacroEllipticArc.h
- SketchAPI_MacroRectangle.h
SketchAPI_Mirror.h
SketchAPI_Offset.h
SketchAPI_Point.h
SketchAPI_MacroCircle.cpp
SketchAPI_MacroEllipse.cpp
SketchAPI_MacroEllipticArc.cpp
- SketchAPI_MacroRectangle.cpp
SketchAPI_Mirror.cpp
SketchAPI_Offset.cpp
SketchAPI_Point.cpp
%shared_ptr(SketchAPI_Point)
%shared_ptr(SketchAPI_Projection)
%shared_ptr(SketchAPI_Rectangle)
-%shared_ptr(SketchAPI_MacroRectangle)
%shared_ptr(SketchAPI_Rotation)
%shared_ptr(SketchAPI_Translation)
%include "SketchAPI_Offset.h"
%include "SketchAPI_Translation.h"
%include "SketchAPI_Rectangle.h"
-%include "SketchAPI_MacroRectangle.h"
%include "SketchAPI_Rotation.h"
%include "SketchAPI_Sketch.h"
%include "SketchAPI_Constraint.h"
+++ /dev/null
-// Copyright (C) 2014-2020 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
-//
-
-#include "SketchAPI_MacroRectangle.h"
-#include "SketchAPI_Rectangle.h"
-
-#include <GeomAPI_Pnt2d.h>
-
-#include <ModelHighAPI_Double.h>
-#include <ModelHighAPI_Dumper.h>
-#include <ModelHighAPI_Selection.h>
-#include <ModelHighAPI_Tools.h>
-
-//==================================================================================================
-SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(
- const std::shared_ptr<ModelAPI_Feature>& theFeature)
- : SketchAPI_SketchEntity(theFeature)
-{
- initialize();
-}
-
-//==================================================================================================
-SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(
- const std::shared_ptr<ModelAPI_Feature>& theFeature,
- double theStartX,
- double theStartY,
- double theSecondX,
- double theSecondY,
- bool isFirstPointCenter):
- SketchAPI_SketchEntity(theFeature)
-{
- if(initialize()) {
- if(isFirstPointCenter)
- setByCenterAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
- else
- setByStartAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
- }
-}
-
-//==================================================================================================
-SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(
- const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint, bool isFirstPointCenter):
- SketchAPI_SketchEntity(theFeature)
-{
- if(initialize()) {
- if(isFirstPointCenter)
- setByCenterAndEndPoints(theStartPoint, theSecondPoint);
- else
- setByStartAndEndPoints(theStartPoint, theSecondPoint);
- }
-}
-
-//==================================================================================================
-SketchAPI_MacroRectangle::~SketchAPI_MacroRectangle()
-{
-}
-
-//==================================================================================================
-void SketchAPI_MacroRectangle::setByStartAndEndPoints(double theStartX, double theStartY,
- double theEndX, double theEndY)
-{
- fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
- fillAttribute(startPoint1(), theStartX, theStartY);
- fillAttribute(endPoint1(), theEndX, theEndY);
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroRectangle::setByStartAndEndPoints(
- const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint)
-{
- fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
- fillAttribute(theStartPoint, startPoint1());
- fillAttribute(theEndPoint, endPoint1());
-
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroRectangle::setByCenterAndEndPoints(double theCenterX, double theCenterY,
- double theEndX, double theEndY)
-{
- fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
- fillAttribute(endPoint2(), theEndX, theEndY);
- fillAttribute(centerPoint(), theCenterX, theCenterY);
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroRectangle::setByCenterAndEndPoints(
- const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint){
- fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
- fillAttribute(theEndPoint, endPoint2());
- fillAttribute(theCenterPoint, centerPoint());
-
- execute();
-}
-
-//==================================================================================================
-/*
-void SketchAPI_MacroRectangle::dump(ModelHighAPI_Dumper& theDumper) const
-{
- FeaturePtr aBase = feature();
-
- std::shared_ptr<SketchPlugin_MacroRectangle> myRectangle = std::dynamic_pointer_cast<SketchPlugin_MacroRectangle>(aBase);
- if(!myRectangle)
- return;
-
- if (isCopy())
- return; // no need to dump copied feature
-
- const std::string& aSketchName = theDumper.parentName(aBase);
-
- AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
- if (anExternal->context()) {
- // rectangle is external
- theDumper << aBase << " = " << aSketchName << ".addRectangle(" << anExternal << ")" << std::endl;
- } else {
- theDumper << aBase << " = " << aSketchName << ".addRectangle(";
-
- if(myRectangle->TYPE_ID() == SketchPlugin_MacroRectangle::START_CENTER_POINT_TYPE_ID())
- // rectangle given by start and center points
- theDumper << startPoint2() << ", " << centerPoint() << ", 1)" << std::endl;
- else
- // rectangle given by start and end points
- theDumper << startPoint1() << ", " << endPoint1() << ", 0)" << std::endl;
- }
- // dump "auxiliary" flag if necessary
- SketchAPI_SketchEntity::dump(theDumper);
-}
-*/
+++ /dev/null
-// Copyright (C) 2014-2020 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
-//
-
-#ifndef SketchAPI_MacroRectangle_H_
-#define SketchAPI_MacroRectangle_H_
-
-#include "SketchAPI.h"
-#include "SketchAPI_SketchEntity.h"
-#include <SketchPlugin_MacroRectangle.h>
-
-class ModelHighAPI_Selection;
-
-/// \class SketchAPI_MacroRectangle
-/// \ingroup CPPHighAPI
-/// \brief Interface for Rectangle feature.
-class SketchAPI_MacroRectangle: public SketchAPI_SketchEntity
-{
-public:
- /// Constructor without values.
- SKETCHAPI_EXPORT
- explicit SketchAPI_MacroRectangle(const std::shared_ptr<ModelAPI_Feature>& theFeature);
-
- /// Constructor with values.
- SKETCHAPI_EXPORT
- SketchAPI_MacroRectangle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- double theStartX,
- double theStartY,
- double theSecondX,
- double theSecondY, bool isFirstPointCenter = false);
-
- /// Constructor with values.
- SKETCHAPI_EXPORT
- SketchAPI_MacroRectangle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint,
- bool isFirstPointCenter = false);
-
-
- /// Destructor.
- SKETCHAPI_EXPORT
- virtual ~SketchAPI_MacroRectangle();
-
- INTERFACE_5(SketchPlugin_MacroRectangle::ID(),
- rectangleType, SketchPlugin_MacroRectangle::RECTANGLE_TYPE_ID(),
- ModelAPI_AttributeString, /** Rectangle type */,
- startPoint1, SketchPlugin_MacroRectangle::START1_ID(),
- GeomDataAPI_Point2D, /** Start point 1 */,
- endPoint1, SketchPlugin_MacroRectangle::END1_ID(),
- GeomDataAPI_Point2D, /** End point 1 */,
- endPoint2, SketchPlugin_MacroRectangle::END2_ID(),
- GeomDataAPI_Point2D, /** First point 2 */,
- centerPoint, SketchPlugin_MacroRectangle::CENTER_ID(),
- GeomDataAPI_Point2D, /** Center point */)
-
- /*SKETCHAPI_EXPORT
- void dump(ModelHighAPI_Dumper& theDumper) const;
-*/
-private:
- /// Set by start and end points.
- void setByStartAndEndPoints(double theStartX, double theStartY,
- double theEndX, double theEndY);
-
- /// Set by start and end points.
- void setByStartAndEndPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint);
-
- /// Set by start and center points.
- void setByCenterAndEndPoints(double theCenterX, double theCenterY,
- double theEndX, double theEndY);
-
- /// Set by start and center points.
- void setByCenterAndEndPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint);
-};
-
-/// Pointer on Rectangle object.
-typedef std::shared_ptr<SketchAPI_MacroRectangle> MacroRectanglePtr;
-
-#endif // SketchAPI_MacroRectangle_H_
}
SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
- double theX1, double theY1, double theX2, double theY2,
- bool isFirstPointCenter)
+ double theX1, double theY1, double theX2, double theY2)
: SketchAPI_SketchEntity(theFeature)
{
if (initialize()) {
- setByCoordinates(theX1, theY1, theX2, theY2, isFirstPointCenter);
+ setByCoordinates(theX1, theY1, theX2, theY2);
}
}
SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint,
- bool isFirstPointCenter)
+ const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
: SketchAPI_SketchEntity(theFeature)
{
if (initialize()) {
- setByPoints(theFirstPoint, theEndPoint, isFirstPointCenter);
+ setByPoints(theFirstPoint, theEndPoint);
}
}
//--------------------------------------------------------------------------------------
void SketchAPI_Rectangle::setByCoordinates(
- double theX1, double theY1, double theX2, double theY2, bool isFirstPointCenter)
+ double theX1, double theY1, double theX2, double theY2)
{
- if(isFirstPointCenter){
- fillAttribute(centerPoint(), theX1, theY1);
- double xStart = 2.0*theX1 - theX2;
- double yStart = 2.0*theY1 - theY2;
- fillAttribute(startPoint(), xStart, yStart);
- }
- else
- fillAttribute(startPoint(), theX1, theY1);
-
+ fillAttribute("RectangleTypeByCorners", type());
+ fillAttribute(startPoint(), theX1, theY1);
fillAttribute(endPoint(), theX2, theY2);
- execute(true);
+ execute();
}
void SketchAPI_Rectangle::setByPoints(const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theSecondPoint,
- bool isFirstPointCenter)
-{
- if(isFirstPointCenter){
- fillAttribute(theFirstPoint, centerPoint());
- double xStart = 2.0*theFirstPoint->x() - theSecondPoint->x();
- double yStart = 2.0*theFirstPoint->y() - theSecondPoint->y();
-
- std::shared_ptr<GeomAPI_Pnt2d> theStartPoint = std::make_shared<GeomAPI_Pnt2d>(xStart, yStart);
- fillAttribute(theStartPoint, startPoint());
- }
- else
- fillAttribute(theFirstPoint, startPoint());
-
+ const std::shared_ptr<GeomAPI_Pnt2d> & theSecondPoint)
+{
+ fillAttribute("RectangleTypeByCorners", type());
+ fillAttribute(theFirstPoint, startPoint());
fillAttribute(theSecondPoint, endPoint());
- execute(true);
+ execute();
}
//--------------------------------------------------------------------------------------
aFeatures.push_back(ModelAPI_Feature::feature(*anIt));
return SketchAPI_SketchEntity::wrap(aFeatures);
}
-
-//==================================================================================================
-void SketchAPI_Rectangle::dump(ModelHighAPI_Dumper& theDumper) const
-{
-
- FeaturePtr aBase = feature();
-
- /// do not dump sub-features eg: lines and lines constraints
- AttributeRefListPtr noToDumpList = aBase->reflist(SketchPlugin_Rectangle::NOT_TO_DUMP_LIST_ID());
- for( int i = 0; i < noToDumpList->size(); i++){
- theDumper.doNotDumpFeature(
- std::dynamic_pointer_cast<ModelAPI_Feature>(noToDumpList->object(i)));
- }
-
- if (isCopy())
- return; // no need to dump copied feature
-
- const std::string& aSketchName = theDumper.parentName(aBase);
-
- FeaturePtr aCenterPointFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
- aBase->refattr(SketchPlugin_Rectangle::CENTER_REF_ID())->object());
- if(aCenterPointFeature){
- // rectangle has center
- theDumper << aBase << " = " << aSketchName << ".addRectangle("
- << startPoint() << ", " << centerPoint() << ", 1)" << std::endl;
- }
- else
- // rectangle given by start and end points
- theDumper << aBase << " = " << aSketchName << ".addRectangle("
- << startPoint() << ", " << endPoint() << ")" << std::endl;
-
- // dump "auxiliary" flag if necessary
- SketchAPI_SketchEntity::dump(theDumper);
-
-}
#include "SketchAPI.h"
#include "SketchAPI_SketchEntity.h"
-#include "SketchPlugin_Rectangle.h"
//--------------------------------------------------------------------------------------
class ModelHighAPI_Selection;
/// Constructor with values
SKETCHAPI_EXPORT
SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
- double theX1, double theY1, double theX2, double theY2,
- bool isFirstPointCenter = false);
+ double theX1, double theY1, double theX2, double theY2);
/// Constructor with values
SKETCHAPI_EXPORT
SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint,
- bool isFirstPointCenter = false);
+ const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
/// Destructor
SKETCHAPI_EXPORT
virtual ~SketchAPI_Rectangle();
- INTERFACE_4(SketchPlugin_Rectangle::ID(),
- startPoint, SketchPlugin_Rectangle::START_ID(), GeomDataAPI_Point2D,
+ INTERFACE_7("SketchRectangle",
+ type, "RectangleType", ModelAPI_AttributeString,
+ /** Creation type of rectangle */,
+ startPoint, "RectStartPoint", GeomDataAPI_Point2D,
/** Start point */,
- endPoint, SketchPlugin_Rectangle::END_ID(), GeomDataAPI_Point2D,
+ endPoint, "RectEndPoint", GeomDataAPI_Point2D,
/** End point */,
- centerPoint, SketchPlugin_Rectangle::CENTER_ID(), GeomDataAPI_Point2D,
+ centerPoint, "RectCenterPoint", GeomDataAPI_Point2D,
/** Center point */,
- linesList, SketchPlugin_Rectangle::LINES_LIST_ID(), ModelAPI_AttributeRefList,
+ centerPointRef, "RectCenterPointRef", ModelAPI_AttributeRefAttr,
+ /** Reference to center point */,
+ cornerPoint, "RectCornerPoint", GeomDataAPI_Point2D,
+ /** Corner point */,
+ linesList, "RectangleList", ModelAPI_AttributeRefList,
/** Lines list */
)
/// Set by coordinates
SKETCHAPI_EXPORT
- void setByCoordinates(double theX1, double theY1, double theX2, double theY2,
- bool isFirstPointCenter);
+ void setByCoordinates(double theX1, double theY1, double theX2, double theY2);
/// Set by points
SKETCHAPI_EXPORT
void setByPoints(const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theSecondPoint, bool isFirstPointCenter);
+ const std::shared_ptr<GeomAPI_Pnt2d> & theSecondPoint);
/// List of lines composing rectangle
SKETCHAPI_EXPORT std::list<std::shared_ptr<SketchAPI_SketchEntity> > lines() const;
-
- SKETCHAPI_EXPORT
- virtual void dump(ModelHighAPI_Dumper& theDumper) const;
- };
+};
//! Pointer on Rectangle object
typedef std::shared_ptr<SketchAPI_Rectangle> RectanglePtr;
return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
}
-std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
- double theX1, double theY1, double theX2, double theY2, bool isFirstPointCenter)
+static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(
+ const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & thePoint)
{
- std::shared_ptr<ModelAPI_Feature> aFeature =
- compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
- return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1,
- theX2, theY2, isFirstPointCenter));
-}
-std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
- const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint, bool isFirstPointCenter)
-{
- std::shared_ptr<ModelAPI_Feature> aFeature =
- compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
- return RectanglePtr(new SketchAPI_Rectangle(aFeature, theFirstPoint, theEndPoint,
- isFirstPointCenter));
-}
+ if (thePoint.first)
+ return thePoint.first;
-std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
- double theX1, double theY1, double theX2, double theY2)
-{
- std::shared_ptr<ModelAPI_Feature> aFeature =
- compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
- return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2, true));
+ AttributePtr anAttr = thePoint.second.attr();
+ if (thePoint.second.object()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(thePoint.second.object());
+ if (aFeature)
+ anAttr = aFeature->attribute(SketchPlugin_Point::COORD_ID());
+ }
+
+ std::shared_ptr<GeomDataAPI_Point2D> aPntAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
+ if (aPntAttr)
+ return aPntAttr->pnt();
+ return std::shared_ptr<GeomAPI_Pnt2d>();
}
+
std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
- const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
+ const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
+ const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner)
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
- return RectanglePtr(new SketchAPI_Rectangle(aFeature, theFirstPoint, theEndPoint, true));
+ RectanglePtr aRect(new SketchAPI_Rectangle(aFeature));
+ fillAttribute("RectangleTypeCentered", aRect->type());
+ if (!theCenter.second.isEmpty())
+ fillAttribute(theCenter.second, aRect->centerPointRef());
+ fillAttribute(pointCoordinates(theCenter), aRect->centerPoint());
+ fillAttribute(pointCoordinates(theCorner), aRect->cornerPoint());
+ aRect->execute();
+
+ if (!theCorner.second.isEmpty() && aRect->linesList()->size() > 1) {
+ // get start point of the last line in rectangle and apply coindidence constraint
+ FeaturePtr aLine = ModelAPI_Feature::feature(aRect->linesList()->object(3));
+ AttributePtr aEndPnt = aLine->attribute(SketchPlugin_Line::START_ID());
+ setCoincident(ModelHighAPI_RefAttr(aEndPnt), theCorner.second);
+ }
+ return aRect;
}
//--------------------------------------------------------------------------------------
const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
/// Add rectangle
SKETCHAPI_EXPORT
- std::shared_ptr<SketchAPI_Rectangle> addRectangle(
- double theX1, double theY1, double theX2, double theY2, bool isFirstPointCenter);
- /// Add rectangle
- SKETCHAPI_EXPORT
- std::shared_ptr<SketchAPI_Rectangle> addRectangle(
- const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint, bool isFirstPointCenter);
- /// Add rectangle
- SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
- double theX1, double theY1, double theX2, double theY2);
- /// Add rectangle
- SKETCHAPI_EXPORT
- std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
- const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
+ const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
+ const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner);
+
/// Add circle
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Circle> addCircle(
#include "SketchAPI_Point.h"
#include "SketchAPI_Projection.h"
#include "SketchAPI_Rectangle.h"
- #include "SketchAPI_MacroRectangle.h"
#include "SketchAPI_Rotation.h"
#include "SketchAPI_Translation.h"
SketchPlugin_MacroCircle.h
SketchPlugin_MacroEllipse.h
SketchPlugin_MacroEllipticArc.h
- SketchPlugin_MacroRectangle.h
SketchPlugin_MultiRotation.h
SketchPlugin_MultiTranslation.h
SketchPlugin_Offset.h
SketchPlugin_Plugin.h
SketchPlugin_Point.h
SketchPlugin_Projection.h
- SketchPlugin_Rectangle.h
SketchPlugin_Sketch.h
SketchPlugin_SketchCopy.h
SketchPlugin_SketchDrawer.h
SketchPlugin_MacroCircle.cpp
SketchPlugin_MacroEllipse.cpp
SketchPlugin_MacroEllipticArc.cpp
- SketchPlugin_MacroRectangle.cpp
SketchPlugin_MultiRotation.cpp
SketchPlugin_MultiTranslation.cpp
SketchPlugin_Offset.cpp
SketchPlugin_Plugin.cpp
SketchPlugin_Point.cpp
SketchPlugin_Projection.cpp
- SketchPlugin_Rectangle.cpp
SketchPlugin_Sketch.cpp
SketchPlugin_SketchCopy.cpp
SketchPlugin_SketchDrawer.cpp
+++ /dev/null
-// Copyright (C) 2014-2020 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
-//
-
-#include "SketchPlugin_MacroRectangle.h"
-#include "SketchPlugin_Rectangle.h"
-#include "SketchPlugin_Sketch.h"
-#include "SketchPlugin_Tools.h"
-#include "SketchPlugin_Line.h"
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_AttributeSelection.h>
-#include <ModelAPI_Validator.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_Session.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_AttributeReference.h>
-#include <ModelAPI_Events.h>
-
-#include <GeomAlgoAPI_CompoundBuilder.h>
-#include <GeomAlgoAPI_EdgeBuilder.h>
-#include <GeomAlgoAPI_PointBuilder.h>
-
-#include <GeomAPI_Pnt2d.h>
-
-#include <cmath>
-
-const double tolerance = 1e-7;
-
-
-SketchPlugin_MacroRectangle::SketchPlugin_MacroRectangle()
- : SketchPlugin_SketchEntity(), myHasCenterPoint(false)
-{}
-
-void SketchPlugin_MacroRectangle::initAttributes()
-{
- data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
- data()->addAttribute(START1_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(START1_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
- data()->addAttribute(END1_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(END1_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
- data()->addAttribute(END2_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(END2_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
- data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(CENTER_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
- data()->addAttribute(RECTANGLE_TYPE_ID(), ModelAPI_AttributeString::typeId());
- data()->addAttribute(EDIT_RECTANGLE_TYPE_ID(), ModelAPI_AttributeString::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDIT_RECTANGLE_TYPE_ID());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_REF_ID());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), END2_REF_ID());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), END1_REF_ID());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), START1_REF_ID());
-
- string(EDIT_RECTANGLE_TYPE_ID())->setValue("");
-}
-
-void SketchPlugin_MacroRectangle::endPoint()
-{
- std::shared_ptr<GeomDataAPI_Point2D> aEndPoint;
- if(string(RECTANGLE_TYPE_ID())->value() == START_END_POINT_TYPE_ID())
- aEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(END1_ID()));
- else
- aEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(END2_ID()));
- if(aEndPoint->isInitialized())
- myEndPoint = std::make_shared<GeomAPI_Pnt2d>(aEndPoint->x(), aEndPoint->y());
- else
- myEndPoint.reset();
-}
-
-void SketchPlugin_MacroRectangle::startPoint()
-{
- if(string(RECTANGLE_TYPE_ID())->value() == START_END_POINT_TYPE_ID())
- {
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START1_ID()));
- if(aStartPoint->isInitialized())
- myStartPoint = std::make_shared<GeomAPI_Pnt2d>(aStartPoint->x(), aStartPoint->y());
- else
- myStartPoint.reset();
- }
- else
- {
- /// Compute end point as the symmetric of start point w.r.t. center
- std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(END2_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aCenterPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
-
- if(aCenterPoint->isInitialized())
- {
- myCenterPoint = std::make_shared<GeomAPI_Pnt2d>(aCenterPoint->x(), aCenterPoint->y());
- myHasCenterPoint = true;
- }
- double xStart = 2.0*aCenterPoint->x() - aEndPoint->x();
- double yStart = 2.0*aCenterPoint->y() - aEndPoint->y();
-
- if(aEndPoint->isInitialized() && aCenterPoint->isInitialized())
- myStartPoint = std::make_shared<GeomAPI_Pnt2d>(xStart, yStart);
- else
- myStartPoint.reset();
- }
-}
-
-
-void SketchPlugin_MacroRectangle::execute()
-{
- SketchPlugin_Sketch* aSketch = sketch();
- if(!myStartPoint || !myEndPoint || !aSketch) {
- return ;
- }
- // Wait all constraints being created, then send update events
- static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
- bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
- if (isUpdateFlushed)
- Events_Loop::loop()->setFlushed(anUpdateEvent, false);
-
- /// create a rectangle sketch
- FeaturePtr myRectangleFeature = aSketch->addFeature(SketchPlugin_Rectangle::ID());
- if(!myRectangleFeature)
- return;
-
- if(myHasCenterPoint){
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- myRectangleFeature->attribute(
- SketchPlugin_Rectangle::CENTER_ID()))->setValue(myCenterPoint->x(),
- myCenterPoint->y());
- }
-
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- myRectangleFeature->attribute(
- SketchPlugin_Rectangle::START_ID()))->setValue(myStartPoint->x(),
- myStartPoint->y());
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- myRectangleFeature->attribute(
- SketchPlugin_Rectangle::END_ID()))->setValue(myEndPoint->x(),
- myEndPoint->y());
-
- myRectangleFeature->boolean(SketchPlugin_Rectangle::AUXILIARY_ID())
- ->setValue(boolean(AUXILIARY_ID())->value());
- myRectangleFeature->execute();
-
- /// create coincidences with rectangle start/center and end points
- AttributeRefListPtr aLinesList =
- myRectangleFeature->reflist(SketchPlugin_Rectangle::LINES_LIST_ID());
- FeaturePtr aRectangleStartLineFeature =
- std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(0));
- FeaturePtr aRectangleEndLineFeature =
- std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(2));
- std::shared_ptr<GeomDataAPI_Point2D> aRectanglePointEndAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aRectangleEndLineFeature->attribute(SketchPlugin_Line::END_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aRectanglePointStartAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aRectangleStartLineFeature->attribute(SketchPlugin_Line::END_ID()));
-
- if(myHasCenterPoint){
- FeaturePtr aCenterPointFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
- myRectangleFeature->refattr(CENTER_REF_ID())->object());
- SketchPlugin_Tools::createCoincidenceOrTangency(
- this, CENTER_REF_ID(), AttributePtr(), aCenterPointFeature, false);
- SketchPlugin_Tools::createCoincidenceOrTangency(
- this, END2_REF_ID(), aRectanglePointEndAttr, ObjectPtr(), false);
- }
- else{
- SketchPlugin_Tools::createCoincidenceOrTangency(
- this, START1_REF_ID(), aRectanglePointStartAttr, ObjectPtr(), false);
- SketchPlugin_Tools::createCoincidenceOrTangency(
- this, END1_REF_ID(), aRectanglePointEndAttr, ObjectPtr(), false);
- }
-
- /// Send events to update the sub-features by the solver.
- if (isUpdateFlushed)
- Events_Loop::loop()->setFlushed(anUpdateEvent, true);
-}
-
-void SketchPlugin_MacroRectangle::attributeChanged(const std::string& theID)
-{
- if(theID == RECTANGLE_TYPE_ID()) {
- SketchPlugin_Tools::resetAttribute(this, START1_ID());
- SketchPlugin_Tools::resetAttribute(this, END1_ID());
- SketchPlugin_Tools::resetAttribute(this, CENTER_ID());
- SketchPlugin_Tools::resetAttribute(this, END2_ID());
- SketchPlugin_Tools::resetAttribute(this, START1_REF_ID());
- SketchPlugin_Tools::resetAttribute(this, END1_REF_ID());
- SketchPlugin_Tools::resetAttribute(this, CENTER_REF_ID());
- SketchPlugin_Tools::resetAttribute(this, END2_REF_ID());
- myStartPoint.reset();
- myEndPoint.reset();
- myCenterPoint.reset();
- myHasCenterPoint = false;
- }
- else if (theID == START1_ID() || theID == END1_ID() ||
- theID == START1_REF_ID() || theID == END1_REF_ID() ||
- theID == END2_ID() || theID == CENTER_ID() ||
- theID == END2_REF_ID() || theID == CENTER_REF_ID())
- {
- // update points
- startPoint();
- endPoint();
- }
- bool aWasBlocked = data()->blockSendAttributeUpdated(true);
- data()->blockSendAttributeUpdated(aWasBlocked, false);
-}
-
-AISObjectPtr SketchPlugin_MacroRectangle::getAISObject(AISObjectPtr thePrevious)
-{
- SketchPlugin_Sketch* aSketch = sketch();
-
- if(!aSketch || !myEndPoint || ! myStartPoint)
- return AISObjectPtr();
-
- std::vector<double> aX = {myStartPoint->x(), myStartPoint->x(), myEndPoint->x(), myEndPoint->x()};
- std::vector<double> aY = {myStartPoint->y(), myEndPoint->y(), myEndPoint->y(), myStartPoint->y()};
-
- std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
- /// Update coordinates of rectangle lines
-
- std::set<int> createdPointIndex;
- for(unsigned i = 0; i < 4; i++)
- {
- std::shared_ptr<GeomAPI_Pnt> theStart(aSketch->to3D(aX[(i+3)%4], aY[(i+3)%4]));
- std::shared_ptr<GeomAPI_Pnt> theEnd(aSketch->to3D(aX[i], aY[i]));
- GeomShapePtr aLine = GeomAlgoAPI_EdgeBuilder::line(theStart, theEnd);
-
- if(aLine)
- {
- aShapes.push_back(aLine);
- if(createdPointIndex.insert(i).second){
- GeomShapePtr aPointShape = GeomAlgoAPI_PointBuilder::vertex(theStart);
- aShapes.push_back(aPointShape);
- }
- if(createdPointIndex.insert((i+1)%4).second){
- GeomShapePtr aPointShape = GeomAlgoAPI_PointBuilder::vertex(theEnd);
- aShapes.push_back(aPointShape);
- }
- }
- }
-
- if(string(RECTANGLE_TYPE_ID())->value() == CENTER_END_POINT_TYPE_ID()){
- /// draw a line center->end
- std::shared_ptr<GeomDataAPI_Point2D> aCenterPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
-
- std::shared_ptr<GeomAPI_Pnt> theEnd(aSketch->to3D(myEndPoint->x(), myEndPoint->y()));
- std::shared_ptr<GeomAPI_Pnt> theStart(aSketch->to3D(aCenterPoint->x(), aCenterPoint->y()));
- GeomShapePtr aLine = GeomAlgoAPI_EdgeBuilder::line(theStart, theEnd);
- if(aLine)
- aShapes.push_back(aLine);
- }
-
- // Compute a rectangle in 3D view.
-
- std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- AISObjectPtr anAIS = thePrevious;
- if(!anAIS.get()) {
- anAIS.reset(new GeomAPI_AISObject());
- }
- anAIS->createShape(aCompound);
-
- // Modify attributes
- SketchPlugin_Tools::customizeFeaturePrs(anAIS, boolean(AUXILIARY_ID())->value());
-
- return anAIS;
-}
+++ /dev/null
-// Copyright (C) 2014-2020 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
-//
-
-#ifndef SketchPlugin_MacroRectangle_H_
-#define SketchPlugin_MacroRectangle_H_
-
-#include "SketchPlugin.h"
-#include <SketchPlugin_SketchEntity.h>
-#include <GeomAPI_IPresentable.h>
-
-class GeomAPI_Pnt2d;
-
-/**\class SketchPlugin_MacroRectangle
- * \ingroup Plugins
- * \brief Feature for creation of the new Rectangle in Sketch.
- */
-class SketchPlugin_MacroRectangle: public SketchPlugin_SketchEntity,
- public GeomAPI_IPresentable
-{
-public:
- /// Rectangle feature kind
- inline static const std::string& ID()
- {
- static const std::string ID("SketchMacroRectangle");
- return ID;
- }
-
- inline static const std::string& RECTANGLE_TYPE_ID()
- {
- static const std::string ID("rectangle_type");
- return ID;
- }
-
- inline static const std::string& EDIT_RECTANGLE_TYPE_ID()
- {
- static const std::string ID("edit_rectangle_type");
- return ID;
- }
-
- inline static const std::string& START_END_POINT_TYPE_ID()
- {
- static const std::string ID("rectangle_type_by_start_and_end_points");
- return ID;
- }
-
- inline static const std::string& CENTER_END_POINT_TYPE_ID()
- {
- static const std::string ID("rectangle_type_by_center_and_end_points");
- return ID;
- }
-
- /// 2D point - start point of the Rectangle
- inline static const std::string& START1_ID()
- {
- static const std::string ID("rectangle_start_point1");
- return ID;
- }
-
- inline static const std::string& START1_REF_ID()
- {
- static const std::string ID("rectangle_start_point1_ref");
- return ID;
- }
-
- /// 2D point - end point of the Rectangle
- inline static const std::string& END1_ID()
- {
- static const std::string ID("rectangle_end_point1");
- return ID;
- }
-
- inline static const std::string& END1_REF_ID()
- {
- static const std::string ID("rectangle_end_point1_ref");
- return ID;
- }
-
- /// 2D point - start point of the second Rectangle type
- inline static const std::string& END2_ID()
- {
- static const std::string ID("rectangle_end_point2");
- return ID;
- }
-
- inline static const std::string& END2_REF_ID()
- {
- static const std::string ID("rectangle_end_point2_ref");
- return ID;
- }
-
- /// 2D point - center point of the second Rectangle type
- inline static const std::string& CENTER_ID()
- {
- static const std::string ID("rectangle_center_point");
- return ID;
- }
- /// Reference for center point selection.
- inline static const std::string& CENTER_REF_ID()
- {
- static const std::string ID("rectangle_center_point_ref");
- return ID;
- }
-
- /// Returns the kind of a feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {
- static std::string MY_KIND = SketchPlugin_MacroRectangle::ID();
- return MY_KIND;
- }
-
- /// Called on change of any argument-attribute of this object
- SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
- /// Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
-
- /// Use plugin manager for features creation
- SketchPlugin_MacroRectangle();
-
- SKETCHPLUGIN_EXPORT virtual bool isMacro() const
- {return true;}
-
- SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
- SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;}
-
- /// Returns the AIS preview
- virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
-
-private:
-
- std::shared_ptr<GeomAPI_Pnt2d> myStartPoint;
- std::shared_ptr<GeomAPI_Pnt2d> myEndPoint;
- std::shared_ptr<GeomAPI_Pnt2d> myCenterPoint;
- bool myHasCenterPoint;
- void startPoint();
- void endPoint();
- FeaturePtr createRectangle();
-};
-
-#endif
#include <SketchPlugin_Point.h>
#include <SketchPlugin_IntersectionPoint.h>
#include <SketchPlugin_Circle.h>
-#include <SketchPlugin_Rectangle.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_BSpline.h>
#include <SketchPlugin_BSplinePeriodic.h>
#include <SketchPlugin_MacroArc.h>
#include <SketchPlugin_MacroBSpline.h>
#include <SketchPlugin_MacroCircle.h>
-#include <SketchPlugin_MacroRectangle.h>
#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Offset.h>
return FeaturePtr(new SketchPlugin_SketchCopy);
} else if (theFeatureID == SketchPlugin_Offset::ID()) {
return FeaturePtr(new SketchPlugin_Offset);
- }else if (theFeatureID == SketchPlugin_MacroRectangle::ID()) {
- return FeaturePtr(new SketchPlugin_MacroRectangle);
- }else if (theFeatureID == SketchPlugin_Rectangle::ID()) {
- return FeaturePtr(new SketchPlugin_Rectangle);
}
-
// feature of such kind is not found
return FeaturePtr();
}
aMsg->setState(SketchPlugin_ConstraintDistanceVertical::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_CurveFitting::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Offset::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_MacroRectangle::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_Rectangle::ID(), aHasSketchPlane);
// SketchRectangle is a python feature, so its ID is passed just as a string
- //aMsg->setState("SketchRectangle", aHasSketchPlane);
+ aMsg->setState("SketchRectangle", aHasSketchPlane);
}
}
return aMsg;
+++ /dev/null
-// Copyright (C) 2014-2020 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
-//
-
-#include "SketchPlugin_Rectangle.h"
-#include "SketchPlugin_Sketch.h"
-#include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_AttributeSelection.h>
-#include <ModelAPI_Validator.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_AttributeRefAttr.h>
-#include <GeomDataAPI_Point2D.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
-
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Point.h>
-#include <SketchPlugin_Tools.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_ConstraintHorizontal.h>
-#include <SketchPlugin_ConstraintVertical.h>
-
-#include <cmath>
-
-
-const double tolerance = 1e-7;
-
-
-SketchPlugin_Rectangle::SketchPlugin_Rectangle()
- : SketchPlugin_SketchEntity()
-{
-}
-
-
-void SketchPlugin_Rectangle::initDerivedClassAttributes()
-{
- data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
- data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_ID());
- data()->addAttribute(CENTER_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_REF_ID());
- data()->addAttribute(LINES_LIST_ID(), ModelAPI_AttributeRefList::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LINES_LIST_ID());
- data()->addAttribute(DIAGONAL_LIST_ID(), ModelAPI_AttributeRefList::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIAGONAL_LIST_ID());
- data()->addAttribute(ISHV_LIST_ID(), ModelAPI_AttributeIntArray::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ISHV_LIST_ID());
- data()->addAttribute(NOT_TO_DUMP_LIST_ID(), ModelAPI_AttributeRefList::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), NOT_TO_DUMP_LIST_ID());
-}
-
-namespace {
- static const std::pair<unsigned, std::string> cornerToDiagonalLinePoints[4]
- = {
- {0, SketchPlugin_Line::START_ID()},
- {1, SketchPlugin_Line::START_ID()},
- {0, SketchPlugin_Line::END_ID()},
- {1, SketchPlugin_Line::END_ID()}
- };
-}
-
-void SketchPlugin_Rectangle::updateLines()
-{
- // Retrieving list of already created lines
- AttributeRefListPtr aLinesList = reflist(LINES_LIST_ID());
- unsigned aNbLines = aLinesList->size();
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(END_ID()));
-
- double aXStart = aStartPoint->x();
- double aYStart = aStartPoint->y();
- double aXEnd = aEndPoint->x();
- double aYEnd = aEndPoint->y();
-
- std::vector<double> aX = {aXStart, aXStart, aXEnd, aXEnd};
- std::vector<double> aY = {aYStart, aYEnd, aYEnd, aYStart};
-
- bool anAuxiliary = data()->boolean(AUXILIARY_ID())->value();
- AttributeRefListPtr aDiagonalList = reflist(DIAGONAL_LIST_ID());
-
-
- /// Update coordinates of rectangle lines
- for(unsigned i = 0; i < aNbLines; i++)
- {
- FeaturePtr aLine = std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(i));
- std::shared_ptr<GeomDataAPI_Point2D> aLineStart =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aLine->attribute(SketchPlugin_Line::START_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aLineEnd =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aLine->attribute(SketchPlugin_Line::END_ID()));
- aLineStart->setValue(aX[(i+3)%4], aY[(i+3)%4]);
- aLineEnd->setValue(aX[i], aY[i]);
- aLine->data()->boolean(AUXILIARY_ID())->setValue(anAuxiliary);
- /// Cooordinates of diagonals
- if(aDiagonalList->size())
- {
- auto aDiagonalPoint = cornerToDiagonalLinePoints[i];
- FeaturePtr aDiagonal = std::dynamic_pointer_cast<ModelAPI_Feature>(
- aDiagonalList->object(aDiagonalPoint.first));
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aDiagonal->attribute(aDiagonalPoint.second))->setValue(aX[(i+3)%4], aY[(i+3)%4]);
- }
- }
-}
-
-void SketchPlugin_Rectangle::updateStartPoint()
-{
- /// Retrieving list of already created lines
- AttributeRefListPtr aLinesList = reflist(LINES_LIST_ID());
- unsigned aNbLines = aLinesList->size();
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START_ID()));
-
- double aXStart = aStartPoint->x();
- double aYStart = aStartPoint->y();
-
- /// Update coordinates of rectangle lines
- for(unsigned i = 0; i < aNbLines; i++)
- {
- FeaturePtr aLine = std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(i));
- std::shared_ptr<GeomDataAPI_Point2D> aLineStart =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aLine->attribute(SketchPlugin_Line::END_ID()));
- aLineStart->setValue(aXStart, aYStart);
- }
-}
-
-void SketchPlugin_Rectangle::execute()
-{
- SketchPlugin_Sketch* aSketch = sketch();
- if(!aSketch) {
- return;
- }
-
- // Compute a Rectangle in 3D view.
- std::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START_ID()));
-
- std::shared_ptr<GeomDataAPI_Point2D> aEndAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(END_ID()));
-
- if(!aStartAttr->isInitialized() || !aEndAttr->isInitialized()) {
- return;
- }
-
- AttributeRefListPtr aLinesList = reflist(LINES_LIST_ID());
- unsigned aNbLines = aLinesList->size();
- AttributeIntArrayPtr isHVList = intArray(ISHV_LIST_ID());
- AttributeRefListPtr aNotToDumpList = reflist(NOT_TO_DUMP_LIST_ID());
- AttributeRefListPtr aDiagonalList = reflist(DIAGONAL_LIST_ID());
-
- if(aNbLines == 1)
- {
- /// Create 1-4 lines to compose the rectangle
- for( unsigned i = 0; i < 3; i++)
- {
- FeaturePtr aLine = aSketch->addFeature(SketchPlugin_Line::ID());
- aLinesList->append(aLine);
- aNotToDumpList->append(aLine);
- }
-
- updateLines();
-
- aNbLines = aLinesList->size();
- FeaturePtr aCenterPointFeature;
-
- if(aDiagonalList->size())
- {
- /// compute diagonals intersection point
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
-
- aCenterPointFeature = aSketch->addFeature(SketchPlugin_Point::ID());
- aNotToDumpList->append(aCenterPointFeature);
- AttributePoint2DPtr aCoord = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aCenterPointFeature->attribute(SketchPlugin_Point::COORD_ID()));
- aCoord->setValue(aCenterAttr->x(), aCenterAttr->y());
- aCenterPointFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true);
- refattr(CENTER_REF_ID())->setObject(aCenterPointFeature);
-
- for(int i = 0; i < 2; i++)
- {
- FeaturePtr aDiagonal = std::dynamic_pointer_cast<ModelAPI_Feature>(
- aDiagonalList->object(i));
- FeaturePtr aConstraint = SketchPlugin_Tools::createConstraintAttrObject(
- aSketch, SketchPlugin_ConstraintCoincidence::ID(),
- aCoord, aDiagonal);
- aNotToDumpList->append(aConstraint);
- }
- }
-
- /// Create constraints to keep the rectangle
- for( unsigned i = 0; i < aNbLines; i++)
- {
- FeaturePtr aLine = std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(i));
- /// connect neighbor lines by coincidence
- unsigned iPrev = (i+3)%4;
- FeaturePtr aPrevLine = std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(iPrev));
- FeaturePtr aConstraint = SketchPlugin_Tools::createConstraintAttrAttr(
- aSketch, SketchPlugin_ConstraintCoincidence::ID(),
- aPrevLine->attribute(SketchPlugin_Line::END_ID()),
- aLine->attribute(SketchPlugin_Line::START_ID()));
- aNotToDumpList->append(aConstraint);
-
- /// case of rectangle created from its center
- if(aDiagonalList->size())
- {
- auto aDiagonalPoint = cornerToDiagonalLinePoints[i];
- FeaturePtr aDiagonal = std::dynamic_pointer_cast<ModelAPI_Feature>(
- aDiagonalList->object(aDiagonalPoint.first));
- FeaturePtr aConstraint = SketchPlugin_Tools::createConstraintAttrAttr(
- aSketch, SketchPlugin_ConstraintCoincidence::ID(),
- aDiagonal->attribute(aDiagonalPoint.second),
- aLine->attribute(SketchPlugin_Line::START_ID()));
- aNotToDumpList->append(aConstraint);
- }
- }
- /// Update coordinates of created lines
- updateLines();
- }
-
- /// Add horizontal and vertical constraint for the lines which already have result
- if(isHVList->size() == 0)
- {
- isHVList->setSize(4, false);
- for(int i = 0; i< 4;)
- isHVList->setValue(i++, 0, false);
- }
-
- for(unsigned i = 0; i< aNbLines; i++)
- {
- if(isHVList->value(i))
- continue;
- FeaturePtr aLine = std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(i));
- ResultPtr aLineResult = aLine->lastResult();
- if(!aLineResult.get())
- continue;
- std::string aHVName = SketchPlugin_ConstraintHorizontal::ID();
- if(i%2)
- aHVName = SketchPlugin_ConstraintVertical::ID();
- FeaturePtr aHVConstraint = aSketch->addFeature(aHVName);
- aNotToDumpList->append(aHVConstraint);
- AttributeRefAttrPtr aRefAttrA = aHVConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
- aRefAttrA->setObject(aLine->lastResult());
- isHVList->setValue(i, 1, false);
- }
-
- double aDiag = std::pow(aStartAttr->x() - aEndAttr->x(), 2.0);
- aDiag += std::pow(aStartAttr->y() - aEndAttr->y(), 2.0);
- aDiag = std::sqrt(aDiag);
- if(aDiag < tolerance) {
- return;
- }
-
- /// store results.
- GeomShapePtr aRectangleShape;
- ListOfShape aSubs;
-
- for(unsigned i = 0; i< aNbLines; i++)
- {
- FeaturePtr aLine = std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(i));
- ResultPtr aLineResult = aLine->lastResult();
- if(!aLineResult.get())
- continue;
- aSubs.push_back(aLineResult->shape());
- }
-
- for(int i = 0; i< aDiagonalList->size(); i++)
- {
- FeaturePtr aDiagonal = std::dynamic_pointer_cast<ModelAPI_Feature>(aDiagonalList->object(i));
- ResultPtr aDiagonalResult = aDiagonal->lastResult();
- if(!aDiagonalResult.get())
- continue;
- aSubs.push_back(aDiagonalResult->shape());
- }
-
- FeaturePtr aCenterPointFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
- refattr(CENTER_REF_ID())->object());
- if(aCenterPointFeature)
- {
- ResultPtr aCenterResult = aCenterPointFeature->lastResult();
- if(aCenterResult.get())
- aSubs.push_back(aCenterResult->shape());
- }
-
- aRectangleShape = aSubs.empty() ? GeomShapePtr() : GeomAlgoAPI_CompoundBuilder::compound(aSubs);
- std::shared_ptr<ModelAPI_ResultConstruction> aResult = document()->createConstruction(data(), 0);
- aResult->setShape(aRectangleShape);
- aResult->setIsInHistory(false);
- setResult(aResult, 1);
-}
-
-void SketchPlugin_Rectangle::attributeChanged(const std::string& theID)
-{
- if (theID == START_ID() || theID == END_ID())
- {
- AttributeRefListPtr aLinesList = reflist(LINES_LIST_ID());
- AttributeRefListPtr aNotToDumpList = reflist(NOT_TO_DUMP_LIST_ID());
- unsigned aNbLines = aLinesList->size();
- if(aNbLines == 0)
- {
- SketchPlugin_Sketch* aSketch = sketch();
- if(!aSketch) {
- return;
- }
- /// Create first line to be able to create a coincidence with selected point/feature
- FeaturePtr aLine = aSketch->addFeature(SketchPlugin_Line::ID());
- aLinesList->append(aLine);
- aNotToDumpList->append(aLine);
-
- /// if rectangle has center, add 2 iagonals
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
- if(aCenterAttr->isInitialized())
- {
- AttributeRefListPtr aDiagonalList = reflist(DIAGONAL_LIST_ID());
- for(int i = 0; i < 2; i++)
- {
- FeaturePtr aDiagonalLine = aSketch->addFeature(SketchPlugin_Line::ID());
- aDiagonalLine->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true);
- aDiagonalList->append(aDiagonalLine);
- aNotToDumpList->append(aDiagonalLine);
- }
- }
- }
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(END_ID()));
-
- if (aStartPoint->isInitialized() && aEndPoint->isInitialized())
- updateLines();
- else
- updateStartPoint();
- }
-
- if (theID == AUXILIARY_ID())
- {
- bool anAuxiliary = data()->boolean(AUXILIARY_ID())->value();
- AttributeRefListPtr aLinesList = reflist(LINES_LIST_ID());
- unsigned aNbLines = aLinesList->size();
-
- /// Update coordinates of rectangle lines
- for(unsigned i = 0; i < aNbLines; i++)
- {
- FeaturePtr aLine = std::dynamic_pointer_cast<ModelAPI_Feature>(aLinesList->object(i));
- aLine->data()->boolean(AUXILIARY_ID())->setValue(anAuxiliary);
- }
- }
-}
+++ /dev/null
-// Copyright (C) 2014-2020 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
-//
-
-#ifndef SketchPlugin_Rectangle_H_
-#define SketchPlugin_Rectangle_H_
-
-#include "SketchPlugin.h"
-#include "SketchPlugin_SketchEntity.h"
-
-/**\class SketchPlugin_Rectangle
- * \ingroup Plugins
- * \brief Feature for creation of the new Rectangle in Sketch.
- */
-class SketchPlugin_Rectangle: public SketchPlugin_SketchEntity
-{
- public:
- /// Rectangle feature kind
- inline static const std::string& ID()
- {
- static const std::string ID("SketchRectangle");
- return ID;
- }
-
- /// 2D point - start point of the Rectangle
- inline static const std::string& START_ID()
- {
- static const std::string ID("rectangle_start_point");
- return ID;
- }
-
- /// 2D point - end point of the Rectangle
- inline static const std::string& END_ID()
- {
- static const std::string ID("rectangle_end_point");
- return ID;
- }
-
- /// 2D point - center point of the Rectangle
- inline static const std::string& CENTER_ID()
- {
- static const std::string ID("rectangle_center_point");
- return ID;
- }
-
- /// 2D point - center point of the Rectangle
- inline static const std::string& CENTER_REF_ID()
- {
- static const std::string ID("rectangle_center_point_ref");
- return ID;
- }
-
- /// 2D point - list of Rectangle lines
- inline static const std::string& LINES_LIST_ID()
- {
- static const std::string ID("RectangleLinesList");
- return ID;
- }
-
- /// 2D point - list of Diagonal lines
- inline static const std::string& DIAGONAL_LIST_ID()
- {
- static const std::string ID("RectangleDiagonalLinesList");
- return ID;
- }
-
- inline static const std::string& ISHV_LIST_ID()
- {
- static const std::string ID("IsHVList");
- return ID;
- }
-
- inline static const std::string& NOT_TO_DUMP_LIST_ID()
- {
- static const std::string ID("NotToDumpList");
- return ID;
- }
-
- /// Returns the kind of a feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {
- static std::string MY_KIND = SketchPlugin_Rectangle::ID();
- return MY_KIND;
- }
-
- SKETCHPLUGIN_EXPORT virtual bool isMacro() const
- { return true;}
-
- /// Called on change of any argument-attribute of this object
- SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
- /// Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
-
- /// Use plugin manager for features creation
- SketchPlugin_Rectangle();
-
-protected:
- /// \brief Initializes attributes of derived class.
- virtual void initDerivedClassAttributes();
-
-private:
- /// \brief updateLines crates lines from start and en points
- void updateLines();
- void updateStartPoint();
-};
-
-
-#endif
from salome.shaper import model
+from salome.shaper import geom
model.begin()
partSet = model.moduleDocument()
Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
Rectangle_1 = Sketch_1.addRectangle(5.5, 8.5, 31.3, 78.9)
# rectangle from center and end points
-rectangle_2 = sketch.addRectangleCentered(10, 5, 25, 75)
+center = geom.Pnt2d(10, 5)
+corner = geom.Pnt2d(25, 75)
+rectangle_2 = sketch.addRectangleCentered(center, corner)
model.do()
model.end()
SketchCircle SketchMacroCircle SketchArc SketchMacroArc
SketchEllipse SketchMacroEllipse SketchEllipticArc SketchMacroEllipticArc
SketchBSpline SketchMacroBSpline SketchMacroBSplinePeriodic SketchBSplinePeriodic
- SketchRectangle SketchMacroRectangle
+ SketchRectangle
SketchProjection
SketchCurveFitting
SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintDistanceHorizontal SketchConstraintDistanceVertical
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0" change_visual_attributes="true"/>
<validator id="GeomValidators_Different" parameters="StartPoint,EndPoint"/>
</feature>
- <!-- SketchRectangle is a hidden feature. It is created inside SketchMacroRectangle. -->
- <feature
- id="SketchRectangle"
- title="Rectangle"
- tooltip="Create rectangle"
- icon="icons/Addons/rectangle.png"
- helpfile="rectangleFeature.html"
- internal="1">
- <sketch-2dpoint_selector id="rectangle_start_point"
- accept_expressions="0"
- title="Rectangle start point"
- tooltip="Start point coordinates"
- enable_value="enable_by_preferences"/>
- <sketch-2dpoint_selector id="rectangle_end_point"
- accept_expressions="0"
- title="Rectangle end point"
- tooltip="End point coordinates"
- enable_value="enable_by_preferences"/>
- <validator id="GeomValidators_Different" parameters="rectangle_start_point,rectangle_end_point"/>
- <boolvalue id="Auxiliary"
- label="Auxiliary"
- default="false"
- tooltip="Construction element"
- obligatory="0"
- change_visual_attributes="true"/>
- </feature>
- <!-- SketchMacroRectangle -->
- <feature
- id="SketchMacroRectangle"
- title="Rectangle"
- tooltip="Create rectangle"
- icon="icons/Addons/rectangle.png"
- helpfile="rectangleFeature.html">
- <toolbox id="rectangle_type" modified_in_edit="edit_rectangle_type">
- <box id="rectangle_type_by_start_and_end_points"
- icon="icons/Sketch/rectangle_start_end.png"
- title="Start and end points">
- <sketch-2dpoint_selector id="rectangle_start_point1"
- reference_attribute="rectangle_start_point1_ref"
- accept_expressions="0"
- title="Rectangle start point"
- tooltip="Start point coordinates"
- enable_value="enable_by_preferences"/>
- <sketch-2dpoint_selector id="rectangle_end_point1"
- accept_expressions="0"
- reference_attribute="rectangle_end_point1_ref"
- title="Rectangle end point"
- tooltip="End point coordinates"
- enable_value="enable_by_preferences"/>
- <validator id="GeomValidators_Different" parameters="rectangle_start_point1_ref,rectangle_end_point1_ref"/>
- </box>
- <box id="rectangle_type_by_center_and_end_points"
- icon="icons/Sketch/rectangle_center_end.png"
- title="Center and end points">
- <sketch-2dpoint_selector id="rectangle_center_point"
- accept_expressions="0"
- reference_attribute="rectangle_center_point_ref"
- title="Rectangle center point"
- tooltip="Center point coordinates"
- enable_value="enable_by_preferences"/>
- <sketch-2dpoint_selector id="rectangle_end_point2"
- accept_expressions="0"
- reference_attribute="rectangle_end_point2_ref"
- title="Rectangle end point"
- tooltip="End point coordinates"
- enable_value="enable_by_preferences"/>
- <validator id="GeomValidators_Different" parameters="rectangle_end_point2_ref,rectangle_center_point_ref"/>
- </box>
- </toolbox>
- <boolvalue id="Auxiliary"
- label="Auxiliary"
- default="false"
- tooltip="Construction element"
- obligatory="0"
- change_visual_attributes="true"/>
- </feature>
</group>
<group id="Conical geometry">
<!-- SketchCircle is a hidden feature. It is created inside SketchMacroCircle. -->