Add a rectangle feature from corner and center points.
Change rectangle feature dump into SketchRectangle instead of SketchLines.
--- /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
+#
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Top"), model.selection("FACE", "Box_1_1/Left")])
+Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Top")])
+GroupShape_1 = model.addGroupShape(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(GroupShape_1, 1)
+model.testNbSubShapes(GroupShape_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(GroupShape_1, GeomAPI_Shape.FACE, [3])
+model.testNbSubShapes(GroupShape_1, GeomAPI_Shape.EDGE, [12])
+model.testNbSubShapes(GroupShape_1, GeomAPI_Shape.VERTEX, [24])
+model.testResultsVolumes(GroupShape_1, [300])
+
+assert(model.checkPythonDump())
virtual void createFeatures();
/// add texture
- PARTSET_EXPORT static void setTexture(const std::string &theTextureFile, const AISObjectPtr& thePrs);
+ static void setTexture(const std::string &theTextureFile, const AISObjectPtr& thePrs);
public slots:
/// Slolt called on object display
// Acceptable features;
QStringList aList;
aList << "SketchLine" << "SketchMacroCircle" << "SketchMacroArc" <<
- "SketchMacroEllipse" << "SketchMacroEllipticArc" << "SketchRectangle";
+ "SketchMacroEllipse" << "SketchMacroEllipticArc" << "SketchMacroRectangle";
return aList.contains(aId);
}
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 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/rectangle/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
INSTALL(DIRECTORY macros/compoundVertices/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
INSTALL(DIRECTORY macros/importParameters/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
INCLUDE(UnitTest)
ADD_UNIT_TESTS(
- TestRectangle.py
+ #TestRectangle.py
TestcompoundVertices.py
TestimportParameters.py
)
"""
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__()
- elif theFeatureID == compoundVertices.ID():
+ #if theFeatureID == SketchPlugin_Rectangle.ID():
+ # aFeature = SketchPlugin_Rectangle().__disown__()
+ #el
+ if 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>
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 isSecondPointCenter):
+ SketchAPI_SketchEntity(theFeature)
+{
+ if(initialize()) {
+ if(isSecondPointCenter)
+ setByStartAndCenterPoints(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 isSecondPointCenter):
+ SketchAPI_SketchEntity(theFeature)
+{
+ if(initialize()) {
+ if(isSecondPointCenter)
+ setByStartAndCenterPoints(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::setByStartAndCenterPoints(double theStartX, double theStartY,
+ double theCenterX, double theCenterY)
+{
+ fillAttribute(SketchPlugin_MacroRectangle::START_CENTER_POINT_TYPE_ID(), rectangleType());
+ fillAttribute(startPoint2(), theStartX, theStartY);
+ fillAttribute(centerPoint(), theCenterX, theCenterY);
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroRectangle::setByStartAndCenterPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint){
+ fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
+ fillAttribute(theStartPoint, startPoint2());
+ 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 isSecondPointCenter = 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 isSecondPointCenter = false);
+
+
+ /// Destructor.
+ SKETCHAPI_EXPORT
+ virtual ~SketchAPI_MacroRectangle();
+
+ INTERFACE_5(SketchPlugin_MacroRectangle::ID(),
+ rectangleType, SketchPlugin_MacroRectangle::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 */,
+ startPoint2, SketchPlugin_MacroRectangle::START2_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 setByStartAndCenterPoints(double theStartX, double theStartY,
+ double theCenterX, double theCenterY);
+
+ /// Set by start and center points.
+ void setByStartAndCenterPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint);
+};
+
+/// Pointer on Rectangle object.
+typedef std::shared_ptr<SketchAPI_MacroRectangle> MacroRectanglePtr;
+
+#endif // SketchAPI_MacroRectangle_H_
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
+#include <ModelHighAPI_Dumper.h>
+
//--------------------------------------------------------------------------------------
SketchAPI_Rectangle::SketchAPI_Rectangle(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
-: SketchAPI_SketchEntity(theFeature)
+ : SketchAPI_SketchEntity(theFeature)
{
initialize();
}
SketchAPI_Rectangle::SketchAPI_Rectangle(
const std::shared_ptr<ModelAPI_Feature> & theFeature,
double theX1, double theY1, double theX2, double theY2)
-: SketchAPI_SketchEntity(theFeature)
+ : SketchAPI_SketchEntity(theFeature)
{
if (initialize()) {
setByCoordinates(theX1, theY1, theX2, theY2);
const std::shared_ptr<ModelAPI_Feature> & theFeature,
const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
-: SketchAPI_SketchEntity(theFeature)
+ : SketchAPI_SketchEntity(theFeature)
{
if (initialize()) {
setByPoints(theStartPoint, theEndPoint);
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);
+
+ AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+ if (anExternal->context()) {
+ // rectangle is external
+ theDumper << aBase << " = " << aSketchName << ".addRectangle(" << anExternal << ")" << 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;
//--------------------------------------------------------------------------------------
SKETCHAPI_EXPORT
virtual ~SketchAPI_Rectangle();
- INTERFACE_3("SketchRectangle",
- startPoint, "RectStartPoint", GeomDataAPI_Point2D, /** Start point */,
- endPoint, "RectEndPoint", GeomDataAPI_Point2D, /** End point */,
- linesList, "RectangleList", ModelAPI_AttributeRefList, /** Lines list */
+ INTERFACE_3(SketchPlugin_Rectangle::ID(),
+ startPoint, SketchPlugin_Rectangle::START_ID(), GeomDataAPI_Point2D, /** Start point */,
+ endPoint, SketchPlugin_Rectangle::END_ID(), GeomDataAPI_Point2D, /** End point */,
+ linesList, SketchPlugin_Rectangle::LINES_LIST_ID(), ModelAPI_AttributeRefList, /** Lines list */
)
/// Set by coordinates
/// 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;
#include "SketchAPI_MacroCircle.h"
#include "SketchAPI_MacroEllipse.h"
#include "SketchAPI_MacroEllipticArc.h"
+#include "SketchAPI_MacroRectangle.h"
#include "SketchAPI_Mirror.h"
#include "SketchAPI_Offset.h"
#include "SketchAPI_Point.h"
compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
}
-
+/*
+std::shared_ptr<SketchAPI_MacroRectangle> SketchAPI_Sketch::addRectangle(
+ double theX1, double theY1, double theX2, double theY2, bool thePoint2IsCenter)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchAPI_MacroRectangle::ID());
+ return MacroRectanglePtr(new SketchAPI_MacroRectangle(aFeature, theX1, theY1, theX2, theY2, thePoint2IsCenter));
+}
+std::shared_ptr<SketchAPI_MacroRectangle> SketchAPI_Sketch::addRectangle(
+ const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint, bool theEndPointIsCenter)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchAPI_MacroRectangle::ID());
+ return MacroRectanglePtr(new SketchAPI_MacroRectangle(aFeature, theStartPoint, theEndPoint, theEndPointIsCenter));
+}
+*/
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
double theCenterY,
std::list<std::list<ResultPtr> > aFaces;
edgesOfSketchFaces(aCompFeat, aFaces);
+ /// remove faces that must not be dumped
+ std::vector< std::list<std::list<ResultPtr>>::iterator> aFacesToRemove;
+ for(auto itFaces = aFaces.begin(); itFaces != aFaces.end(); ++itFaces)
+ {
+ auto & facesGroup = *itFaces;
+ std::vector<std::list<ResultPtr>::iterator> subFacestoRemove;
+ for(auto itGroup = facesGroup.begin(); itGroup != facesGroup.end(); ++itGroup)
+ {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*itGroup);
+ if(theDumper.isDumped(aFeature)){
+ subFacestoRemove.push_back(itGroup);
+ }
+ }
+ for(auto itGroup :subFacestoRemove){
+ facesGroup.erase(itGroup);
+ }
+
+ if(!facesGroup.size()){
+ aFacesToRemove.push_back(itFaces);
+ }
+ }
+ for(auto itFaces :aFacesToRemove){
+ aFaces.erase(itFaces);
+ }
+
+ if(!aFaces.size())
+ return;
+
const std::string& aSketchName = theDumper.name(aBase);
std::string aMethodName(".changeFacesOrder");
std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
class SketchAPI_Rectangle;
class SketchAPI_Rotation;
class SketchAPI_Translation;
+class SketchAPI_MacroRectangle;
//--------------------------------------------------------------------------------------
typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Rectangle> addRectangle(
const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
-
+ /// Add rectangle
+ /*SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_MacroRectangle> addRectangle(
+ double theX1, double theY1, double theX2, double theY2, bool thePoint2IsCenter);
+ /// Add rectangle
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_MacroRectangle> addRectangle(
+ const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint, bool theEndPointIsCenter);
+*/
/// 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
ADD_RESTRICTED_TESTS(
Test20204.py
-)
\ No newline at end of file
+)
--- /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 <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 <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()
+{
+}
+
+void SketchPlugin_MacroRectangle::initAttributes()
+{
+ data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
+
+ data()->addAttribute(START1_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(END1_ID(), GeomDataAPI_Point2D::typeId());
+
+ data()->addAttribute(START2_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
+
+ data()->addAttribute(TYPE_ID(), ModelAPI_AttributeString::typeId());
+ data()->addAttribute(EDIT_TYPE_ID(), ModelAPI_AttributeString::typeId());
+
+ string(EDIT_TYPE_ID())->setValue("");
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDIT_TYPE_ID());
+}
+
+void SketchPlugin_MacroRectangle::startPoint()
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint;
+ if(string(TYPE_ID())->value() == START_END_POINT_TYPE_ID())
+ aStartPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START1_ID()));
+ else
+ aStartPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START2_ID()));
+ if(aStartPoint->isInitialized())
+ myStartPoint = std::make_shared<GeomAPI_Pnt2d>(aStartPoint->x(), aStartPoint->y());
+ else
+ myStartPoint.reset();
+}
+
+void SketchPlugin_MacroRectangle::endPoint()
+{
+ if(string(TYPE_ID())->value() == START_END_POINT_TYPE_ID())
+ {
+ std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(END1_ID()));
+ if(aEndPoint->isInitialized())
+ myEndPoint = std::make_shared<GeomAPI_Pnt2d>(aEndPoint->x(), aEndPoint->y());
+ else
+ myEndPoint.reset();
+ }
+ else
+ {
+ /// Compute end point as the symmetric of start point w.r.t. center
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(START2_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+ double xEnd = 2.0*aCenterPoint->x() - aStartPoint->x();
+ double yEnd = 2.0*aCenterPoint->y() - aStartPoint->y();
+
+ if(aStartPoint ->isInitialized() && aCenterPoint->isInitialized())
+ myEndPoint = std::make_shared<GeomAPI_Pnt2d>(xEnd, yEnd);
+ else
+ myEndPoint.reset();
+ }
+}
+
+
+void SketchPlugin_MacroRectangle::execute()
+{
+ SketchPlugin_Sketch* aSketch = sketch();
+ if(!myStartPoint || !myEndPoint || !aSketch) {
+ return ;
+ }
+
+ /// create a rectangle sketch
+ FeaturePtr myRectangleFeature = aSketch->addFeature(SketchPlugin_Rectangle::ID());
+ if(!myRectangleFeature)
+ return;
+
+ 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();
+}
+
+void SketchPlugin_MacroRectangle::attributeChanged(const std::string& theID)
+{
+ if(theID == TYPE_ID()) {
+ SketchPlugin_Tools::resetAttribute(this, START1_ID());
+ SketchPlugin_Tools::resetAttribute(this, END1_ID());
+ SketchPlugin_Tools::resetAttribute(this, CENTER_ID());
+ SketchPlugin_Tools::resetAttribute(this, START2_ID());
+ }
+ else if (theID == START1_ID() || theID == END1_ID() ||
+ theID == START2_ID() || theID == CENTER_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(TYPE_ID())->value() == START_CENTER_POINT_TYPE_ID()){
+ /// draw a line start->center
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+
+ std::shared_ptr<GeomAPI_Pnt> theStart(aSketch->to3D(myStartPoint->x(), myStartPoint->y()));
+ std::shared_ptr<GeomAPI_Pnt> theEnd(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& TYPE_ID()
+ {
+ static const std::string ID("rectangle_type");
+ return ID;
+ }
+
+ inline static const std::string& EDIT_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& START_CENTER_POINT_TYPE_ID()
+ {
+ static const std::string ID("rectangle_type_by_start_and_center_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;
+ }
+ /// 2D point - end point of the Rectangle
+ inline static const std::string& END1_ID()
+ {
+ static const std::string ID("rectangle_end_point1");
+ return ID;
+ }
+ /// 2D point - start point of the second Rectangle type
+ inline static const std::string& START2_ID()
+ {
+ static const std::string ID("rectangle_start_point2");
+ 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;
+ }
+
+ /// 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;
+
+ 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_Data.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <SketchPlugin_Line.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(START_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
+ data()->addAttribute(LINES_LIST_ID(), ModelAPI_AttributeRefList::typeId());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LINES_LIST_ID());
+ data()->addAttribute(ISHV_LIST_ID(), ModelAPI_AttributeIntArray::typeId());
+
+ data()->addAttribute(NOT_TO_DUMP_LIST_ID(), ModelAPI_AttributeRefList::typeId());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), NOT_TO_DUMP_LIST_ID());
+
+ AttributeIntArrayPtr isHVList = intArray(ISHV_LIST_ID());
+ isHVList->setSize(4, false);
+ for(int i = 0; i< 4;)
+ isHVList->setValue(i++, 0, false);
+ }
+
+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 xMin = std::min(aStartPoint->x(), aEndPoint->x());
+ double xMax = std::max(aStartPoint->x(), aEndPoint->x());
+ double yMin = std::min(aStartPoint->y(), aEndPoint->y());
+ double yMax = std::max(aStartPoint->y(), aEndPoint->y());
+ std::vector<double> aX = {xMin, xMax, xMax, xMin};
+ std::vector<double> aY = {yMin, yMin, yMax, yMax};
+
+ bool anAuxiliary = data()->boolean(AUXILIARY_ID())->value();
+
+ /// 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], aY[i]);
+ aLineEnd->setValue(aX[(i+1)%4], aY[(i+1)%4]);
+ aLine->data()->boolean(AUXILIARY_ID())->setValue(anAuxiliary);
+ }
+}
+
+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());
+
+ 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();
+ /// 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 aCoincidence = aSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ aNotToDumpList->append(aCoincidence);
+ AttributeRefAttrPtr aRefAttrA = aCoincidence->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ AttributeRefAttrPtr aRefAttrB = aCoincidence->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ aRefAttrA->setAttr(aPrevLine->attribute(SketchPlugin_Line::END_ID()));
+ aRefAttrB->setAttr(aLine->attribute(SketchPlugin_Line::START_ID()));
+ }
+
+ /// Update coordinates of created lines
+ updateLines();
+ }
+
+ /// Add horizontal and vertical constraint for the lines which already have result
+ 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_ConstraintCoincidence::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());
+ }
+
+ 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);
+}
+
+
+bool SketchPlugin_Rectangle::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context().get() != NULL;
+}
+
+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);
+ }
+
+ 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();
+ }
+ 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"
+#include "SketchPlugin_Sketch.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 - list of Rectangle lines
+ inline static const std::string& LINES_LIST_ID()
+ {
+ static const std::string ID("RectangleList");
+ 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;
+ }
+
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
+ /// 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();
+};
+
+#endif
SketchCircle SketchMacroCircle SketchArc SketchMacroArc
SketchEllipse SketchMacroEllipse SketchEllipticArc SketchMacroEllipticArc
SketchBSpline SketchMacroBSpline SketchMacroBSplinePeriodic SketchBSplinePeriodic
- SketchRectangle
+ SketchRectangle SketchMacroRectangle
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_pt_rad_32x32.png"
+ title="Start and end points">
+ <sketch-2dpoint_selector id="rectangle_start_point1"
+ 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"
+ title="Rectangle end point"
+ tooltip="End point coordinates"
+ enable_value="enable_by_preferences"/>
+ <validator id="GeomValidators_Different" parameters="rectangle_start_point1,rectangle_end_point1"/>
+ </box>
+ <box id="rectangle_type_by_start_and_center_points"
+ icon="icons/Sketch/rectangle_pt_rad_32x32.png"
+ title="Start and center points">
+ <sketch-2dpoint_selector id="rectangle_start_point2"
+ accept_expressions="0"
+ title="Rectangle start point"
+ tooltip="Start point coordinates"
+ enable_value="enable_by_preferences"/>
+ <sketch-2dpoint_selector id="rectangle_center_point"
+ accept_expressions="0"
+ title="Rectangle center point"
+ tooltip="Center point coordinates"
+ enable_value="enable_by_preferences"/>
+ <validator id="GeomValidators_Different" parameters="rectangle_start_point2,rectangle_center_point"/>
+ </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. -->