From f7fec0e59ee28ac393cce1143c881b9995ae000f Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 26 Nov 2015 11:05:01 +0300 Subject: [PATCH] Plugin for the folowing task: 3.4 Construction of vertices, edges and faces from a sketch --- CMakeLists.txt | 1 + src/Config/plugins.xml | 1 + src/ModuleBase/CMakeLists.txt | 2 + src/ModuleBase/ModuleBase_IWidgetCreator.cpp | 13 ++ src/ModuleBase/ModuleBase_IWidgetCreator.h | 40 ++++++ src/PartSet/PartSet_icons.qrc | 1 + src/PartSet/icons/sketch_shape.png | Bin 0 -> 643 bytes src/SketchShapePlugin/CMakeLists.txt | 56 ++++++++ src/SketchShapePlugin/SketchShapePlugin.h | 20 +++ .../SketchShapePlugin_Feature.cpp | 30 ++++ .../SketchShapePlugin_Feature.h | 67 +++++++++ .../SketchShapePlugin_PageGroupBox.cpp | 16 +++ .../SketchShapePlugin_PageGroupBox.h | 28 ++++ .../SketchShapePlugin_Plugin.cpp | 56 ++++++++ .../SketchShapePlugin_Plugin.h | 40 ++++++ .../SketchShapePlugin_Tools.cpp | 11 ++ .../SketchShapePlugin_Tools.h | 15 ++ .../SketchShapePlugin_Validators.cpp | 21 +++ .../SketchShapePlugin_Validators.h | 31 +++++ src/SketchShapePlugin/Test/TestSketchShape.py | 129 ++++++++++++++++++ src/SketchShapePlugin/plugin-SketchShape.xml | 22 +++ 21 files changed, 600 insertions(+) create mode 100755 src/ModuleBase/ModuleBase_IWidgetCreator.cpp create mode 100755 src/ModuleBase/ModuleBase_IWidgetCreator.h create mode 100755 src/PartSet/icons/sketch_shape.png create mode 100755 src/SketchShapePlugin/CMakeLists.txt create mode 100755 src/SketchShapePlugin/SketchShapePlugin.h create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Feature.cpp create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Feature.h create mode 100755 src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp create mode 100755 src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Plugin.h create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Tools.cpp create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Tools.h create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Validators.cpp create mode 100755 src/SketchShapePlugin/SketchShapePlugin_Validators.h create mode 100755 src/SketchShapePlugin/Test/TestSketchShape.py create mode 100755 src/SketchShapePlugin/plugin-SketchShape.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index bd81e2107..6f7f7a8f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ ADD_SUBDIRECTORY (src/ConstructionPlugin) ADD_SUBDIRECTORY (src/FeaturesPlugin) ADD_SUBDIRECTORY (src/SketcherPrs) ADD_SUBDIRECTORY (src/SketchPlugin) +ADD_SUBDIRECTORY (src/SketchShapePlugin) ADD_SUBDIRECTORY (src/SketchSolver) ADD_SUBDIRECTORY (src/ModuleBase) ADD_SUBDIRECTORY (src/PartSet) diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml index 70c0311a6..a8b4b2315 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml @@ -5,6 +5,7 @@ + diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index aa6a72b63..ea029d5bd 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -19,6 +19,7 @@ SET(PROJECT_HEADERS ModuleBase_ISelection.h ModuleBase_IViewWindow.h ModuleBase_IViewer.h + ModuleBase_IWidgetCreator.h ModuleBase_IWorkshop.h ModuleBase_ModelWidget.h ModuleBase_Operation.h @@ -71,6 +72,7 @@ SET(PROJECT_SOURCES ModuleBase_ISelection.cpp ModuleBase_IViewWindow.cpp ModuleBase_IViewer.cpp + ModuleBase_IWidgetCreator.cpp ModuleBase_IWorkshop.cpp ModuleBase_ModelWidget.cpp ModuleBase_Operation.cpp diff --git a/src/ModuleBase/ModuleBase_IWidgetCreator.cpp b/src/ModuleBase/ModuleBase_IWidgetCreator.cpp new file mode 100755 index 000000000..e0f86d63d --- /dev/null +++ b/src/ModuleBase/ModuleBase_IWidgetCreator.cpp @@ -0,0 +1,13 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "ModuleBase_IWidgetCreator.h" + +ModuleBase_IWidgetCreator::ModuleBase_IWidgetCreator() +{ + +} + +ModuleBase_IWidgetCreator::~ModuleBase_IWidgetCreator() +{ + +} diff --git a/src/ModuleBase/ModuleBase_IWidgetCreator.h b/src/ModuleBase/ModuleBase_IWidgetCreator.h new file mode 100755 index 000000000..4f1e040de --- /dev/null +++ b/src/ModuleBase/ModuleBase_IWidgetCreator.h @@ -0,0 +1,40 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef ModuleBase_IWidgetCreator_H +#define ModuleBase_IWidgetCreator_H + +#include "ModuleBase.h" + +#include +#include + +class ModuleBase_ModelWidget; + +class QWidget; + +/** +* \ingroup GUI +* Interface to WidgetCreator which can create specific widgets by type +*/ +class MODULEBASE_EXPORT ModuleBase_IWidgetCreator +{ +public: + /// Default constructor + ModuleBase_IWidgetCreator(); + + /// Virtual destructor + ~ModuleBase_IWidgetCreator(); + + /// Returns a list of possible widget types, which this creator can process + /// \param theTypes + virtual void widgetTypes(std::list& theTypes) = 0; + + /// Create widget by its type + /// \param theType a type + /// \param theParent a parent widget + virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, + QWidget* theParent = NULL) = 0; +}; + + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 13a0a428f..7fac03ac4 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -29,6 +29,7 @@ icons/export.png icons/line.png icons/sketch.png + icons/sketch_shape.png icons/hand_point.png icons/dimension_up.png icons/dimension_up_32x32.png diff --git a/src/PartSet/icons/sketch_shape.png b/src/PartSet/icons/sketch_shape.png new file mode 100755 index 0000000000000000000000000000000000000000..d55e89c1e93ec57e4cb496a367aead0b53629633 GIT binary patch literal 643 zcmV-}0(||6P)7b*dnbiaD z<@tXKLP;s&Ao~d21I$1 zKn_j~56_yoDX?{0M@PeEkebpWNiO9_avvf3M!@xgn+nZ!3#q*0o!q%maZ{V$Y`_$r z4t|L=vuaD*@+?~n)z*ywl~8;{b8&5Tg^(L4b3h?!Qn}x%mzo4svDSL3y7KInwniu8 zPsTM>#m)Ms-HiXi$@t~eMXhr3cCT@$#xxz*I2BJYI45E zs??3UnXcJV%ijC;_&Zl%Zs}fGNLH(pYnF;mIUe@W<4p;%t|J@ + +#ifndef SKETCHSHAPEPLUGIN_H +#define SKETCHSHAPEPLUGIN_H + +#if defined SKETCHSHAPEPLUGIN_EXPORTS +#if defined WIN32 +#define SKETCHSHAPEPLUGIN_EXPORT __declspec( dllexport ) +#else +#define SKETCHSHAPEPLUGIN_EXPORT +#endif +#else +#if defined WIN32 +#define SKETCHSHAPEPLUGIN_EXPORT __declspec( dllimport ) +#else +#define SKETCHSHAPEPLUGIN_EXPORT +#endif +#endif + +#endif diff --git a/src/SketchShapePlugin/SketchShapePlugin_Feature.cpp b/src/SketchShapePlugin/SketchShapePlugin_Feature.cpp new file mode 100755 index 000000000..0b45548c4 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Feature.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_Feature.cpp +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#include "SketchShapePlugin_Feature.h" + +#include +#include + +SketchShapePlugin_Feature::SketchShapePlugin_Feature() +: ModelAPI_Feature() +{ +} + +void SketchShapePlugin_Feature::initAttributes() +{ + data()->addAttribute(VERTEX_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + data()->addAttribute(VERTEX_CHOICE_ID(), ModelAPI_AttributeBoolean::typeId()); +} + +void SketchShapePlugin_Feature::execute() +{ +} + +void SketchShapePlugin_Feature::attributeChanged(const std::string& theID) +{ +} + diff --git a/src/SketchShapePlugin/SketchShapePlugin_Feature.h b/src/SketchShapePlugin/SketchShapePlugin_Feature.h new file mode 100755 index 000000000..6e38662a2 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Feature.h @@ -0,0 +1,67 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_Feature.h +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SKETCHSHAPEPLUGIN_FEATURE_H_ +#define SKETCHSHAPEPLUGIN_FEATURE_H_ + +#include "SketchShapePlugin.h" + +#include + +/**\class SketchShapePlugin_Feature + * \ingroup Plugins + * \brief Feature for extraction shapes from the sketch. + * The visualization of this object is a result and + * it is calculated if all attributes are initialized. + * It is possible to extract simultaneously vertices, edges and faces. + * + */ +class SketchShapePlugin_Feature : public ModelAPI_Feature +{ + public: + /// SketchShape feature kind + inline static const std::string& ID() + { + static const std::string MY_SKETCH_SHAPE_ID("SketchShape"); + return MY_SKETCH_SHAPE_ID; + } + + /// List of vertices to be extracted + inline static const std::string& VERTEX_LIST_ID() + { + static const std::string MY_VERTEX_LIST_ID("VertexList"); + return MY_VERTEX_LIST_ID; + } + + /// State whether the vertices are selectable + inline static const std::string& VERTEX_CHOICE_ID() + { + static const std::string MY_VERTEX_CHOICE_ID("VertexChoice"); + return MY_VERTEX_CHOICE_ID; + } + + /// Returns the kind of a feature + SKETCHSHAPEPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = SketchShapePlugin_Feature::ID(); + return MY_KIND; + } + + /// Creates an arc-shape + SKETCHSHAPEPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + SKETCHSHAPEPLUGIN_EXPORT virtual void initAttributes(); + + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + SKETCHSHAPEPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + + /// Use plugin manager for features creation + SketchShapePlugin_Feature(); +}; + +#endif diff --git a/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp new file mode 100755 index 000000000..e8f9334e1 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp @@ -0,0 +1,16 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_PageGroupBox.h +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +//#include + +//#include + +/*SketchShapePlugin_PageGroupBox::SketchShapePlugin_PageGroupBox(QWidget* theParent) +: ModuleBase_PageGroupBox(theParent) +{ + setTitle("SketchShapePlugin_PageGroupBox"); +}*/ + diff --git a/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h new file mode 100755 index 000000000..4a3666c65 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h @@ -0,0 +1,28 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_PageGroupBox.h +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SKETCHSHAPEPLUGIN_PAGEGROUPBOX_H_ +#define SKETCHSHAPEPLUGIN_PAGEGROUPBOX_H_ + +#include + +class QWidget; + +/*! + * \ingroup GUI + * Represent a property panel's list of ModuleBase_ModelWidgets. + */ +class SketchShapePlugin_PageGroupBox// : public ModuleBase_PageGroupBox +{ + //Q_OBJECT + public: + /// Constructs a page that looks like a QGroupBox + SketchShapePlugin_PageGroupBox(QWidget* theParent = 0) {}; + /// Destructs the page + virtual ~SketchShapePlugin_PageGroupBox() {}; +}; + +#endif /* SKETCHSHAPEPLUGIN_PAGEGROUPBOX_H_ */ diff --git a/src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp b/src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp new file mode 100755 index 000000000..00c5a3604 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp @@ -0,0 +1,56 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_Plugin.cpp +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#include +#include +#include +/* +#include + +#include +*/ +#include +#include +#include +/*#include + +#include +#include + +#include */ + +// the only created instance of this plugin +//static SketchShapePlugin_Plugin* MY_SKETCH_SHAPE_INSTANCE = new SketchShapePlugin_Plugin(); + +SketchShapePlugin_Plugin::SketchShapePlugin_Plugin() +{ + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + aFactory->registerValidator("SketchShapePlugin_FeatureValidator", + new SketchShapePlugin_FeatureValidator); + + // register this plugin + ModelAPI_Session::get()->registerPlugin(this); +} + +FeaturePtr SketchShapePlugin_Plugin::createFeature(std::string theFeatureID) +{ + if (theFeatureID == SketchShapePlugin_Feature::ID()) { + return FeaturePtr(new SketchShapePlugin_Feature); + } + // feature of such kind is not found + return FeaturePtr(); +} + +/*ModuleBase_ModelWidget* SketchShapePlugin_Plugin::createWidgetByType(const std::string& theType, + QWidget* theParent) +{ + ModuleBase_ModelWidget* aWidget = 0; + if (theType == "sketchshape_groupbox") + aWidget = new SketchShapePlugin_PageGroupBox(theParent); + return aWidget; +}*/ + diff --git a/src/SketchShapePlugin/SketchShapePlugin_Plugin.h b/src/SketchShapePlugin/SketchShapePlugin_Plugin.h new file mode 100755 index 000000000..3c037c965 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Plugin.h @@ -0,0 +1,40 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_Plugin.hxx +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SKETCHSHAPEPLUGIN_PLUGIN_H_ +#define SKETCHSHAPEPLUGIN_PLUGIN_H_ + +#include +#include +//#include + +#include +#include + +class ModuleBase_ModelWidget; +class QWidget; + +/**\class SketchShapePlugin_Plugin + * \ingroup Plugins + * \brief Interface common for any plugin: allows to use plugin by the plugins manager. + */ +//, public ModuleBase_IWidgetCreator +class SketchShapePlugin_Plugin : public ModelAPI_Plugin +{ +public: + /// Creates the feature object of this plugin by the feature string ID + virtual FeaturePtr createFeature(std::string theFeatureID); + + /// Create widget by its type + /// \param theType a type + /// \param theParent a parent widget + //virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, + // QWidget* theParent = NULL); + public: + SketchShapePlugin_Plugin(); +}; + +#endif diff --git a/src/SketchShapePlugin/SketchShapePlugin_Tools.cpp b/src/SketchShapePlugin/SketchShapePlugin_Tools.cpp new file mode 100755 index 000000000..dc2fecd6f --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Tools.cpp @@ -0,0 +1,11 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_Tools.cpp +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#include "SketchShapePlugin_Tools.h" + +namespace SketchShapePlugin_Tools { + +} // namespace SketchShapePlugin_Tools diff --git a/src/SketchShapePlugin/SketchShapePlugin_Tools.h b/src/SketchShapePlugin/SketchShapePlugin_Tools.h new file mode 100755 index 000000000..412cf9cfb --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Tools.h @@ -0,0 +1,15 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchPlugin_Tools.h +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SKETCHSHAPEPLUGIN_TOOLS_H_ +#define SKETCHSHAPEPLUGIN_TOOLS_H_ + +namespace SketchShapePlugin_Tools { + + +}; // namespace SketchPlugin_Tools + +#endif // SKETCHSHAPEPLUGIN_TOOLS_H_ diff --git a/src/SketchShapePlugin/SketchShapePlugin_Validators.cpp b/src/SketchShapePlugin/SketchShapePlugin_Validators.cpp new file mode 100755 index 000000000..0609e53ce --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Validators.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_Validators.cpp +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#include "SketchShapePlugin_Validators.h" + +//#include "SketchShapePlugin_Feature.h" + +bool SketchShapePlugin_FeatureValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + /*if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) { + theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed"; + return false; + }*/ + + return true; +} diff --git a/src/SketchShapePlugin/SketchShapePlugin_Validators.h b/src/SketchShapePlugin/SketchShapePlugin_Validators.h new file mode 100755 index 000000000..b883fc7c8 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_Validators.h @@ -0,0 +1,31 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_Validators.h +// Created: 25 Nov 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SKETCHSHAPEPLUGIN_VALIDATORS_H +#define SKETCHSHAPEPLUGIN_VALIDATORS_H + +#include "SketchShapePlugin.h" +#include + +/**\class SketchShapePlugin_FeatureValidator + * \ingroup Validators + * \brief Validator for an attribute of sketch shape feature. + * + * It is empty. + */ +class SketchShapePlugin_FeatureValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + //! \param theError error message + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/SketchShapePlugin/Test/TestSketchShape.py b/src/SketchShapePlugin/Test/TestSketchShape.py new file mode 100755 index 000000000..43b8ff000 --- /dev/null +++ b/src/SketchShapePlugin/Test/TestSketchShape.py @@ -0,0 +1,129 @@ +""" + TestConstraintAngle.py + Unit test of SketchPlugin_ConstraintAngle class + + SketchPlugin_ConstraintAngle + static const std::string MY_CONSTRAINT_ANGLE_ID("SketchConstraintAngle"); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); + + +""" +from GeomDataAPI import * +from ModelAPI import * +import os +import math + +#========================================================================= +# Auxiliary functions +#========================================================================= + +def angle(theLine1, theLine2): + # subroutine to angle between two lines + aStartPoint1 = geomDataAPI_Point2D(theLine1.attribute("StartPoint")) + aEndPoint1 = geomDataAPI_Point2D(theLine1.attribute("EndPoint")) + aStartPoint2 = geomDataAPI_Point2D(theLine2.attribute("StartPoint")) + aEndPoint2 = geomDataAPI_Point2D(theLine2.attribute("EndPoint")) + + aDirX1 = aEndPoint1.x() - aStartPoint1.x() + aDirY1 = aEndPoint1.y() - aStartPoint1.y() + aLen1 = math.hypot(aDirX1, aDirY1) + aDirX2 = aEndPoint2.x() - aStartPoint2.x() + aDirY2 = aEndPoint2.y() - aStartPoint2.y() + aLen2 = math.hypot(aDirX2, aDirY2) + + aDot = aDirX1 * aDirX2 + aDirY1 * aDirY2 + + anAngle = math.acos(aDot / aLen1 / aLen2) + return round(anAngle * 180. / math.pi, 6) + + +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2015-09-18" + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Create two lines +#========================================================================= +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aStartPoint.setValue(-10., 25.) +aEndPoint.setValue(100., 25.) + +aSketchLineB = aSketchFeature.addFeature("SketchLine") +aStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aStartPoint.setValue(-20., 15.) +aEndPoint.setValue(80., 50.) +aSession.finishOperation() +#========================================================================= +# Make a constraint to keep the angle +#========================================================================= +ANGLE_DEGREE = 30. +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintAngle") +anAngleVal = aConstraint.real("ConstraintValue") +refattrA = aConstraint.refattr("ConstraintEntityA") +refattrB = aConstraint.refattr("ConstraintEntityB") +assert (not anAngleVal.isInitialized()) +assert (not refattrA.isInitialized()) +assert (not refattrB.isInitialized()) +anAngleVal.setValue(ANGLE_DEGREE) +refattrA.setObject(aSketchLineA.firstResult()) +refattrB.setObject(aSketchLineB.firstResult()) +aConstraint.execute() +aSession.finishOperation() +assert (anAngleVal.isInitialized()) +assert (refattrA.isInitialized()) +assert (refattrB.isInitialized()) +assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE) +#========================================================================= +# Move line, check that angle is constant +#========================================================================= +aSession.startOperation() +aStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aStartPoint.setValue(0., 30.) +aConstraint.execute() +aSession.finishOperation() +assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE) +#========================================================================= +# Change angle value and check the lines are moved +#========================================================================= +NEW_ANGLE_DEGREE = 60. +aSession.startOperation() +anAngleVal.setValue(NEW_ANGLE_DEGREE) +aConstraint.execute() +aSession.finishOperation() +assert (angle(aSketchLineA, aSketchLineB) == NEW_ANGLE_DEGREE) +#========================================================================= +# TODO: improve test +# 1. remove constraint, move line's start point to +# check that constraint are not applied +# 2. check constrained distance between: +# * point and line +# * two lines +#========================================================================= +#========================================================================= +# End of test +#========================================================================= diff --git a/src/SketchShapePlugin/plugin-SketchShape.xml b/src/SketchShapePlugin/plugin-SketchShape.xml new file mode 100755 index 000000000..4dca7052f --- /dev/null +++ b/src/SketchShapePlugin/plugin-SketchShape.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + -- 2.39.2