From 84c85d67943a16b0cbf90127bf117beb8cc5f4d6 Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 16 Mar 2015 14:44:23 +0300 Subject: [PATCH] Constraints for equality of lengths and radii --- src/SketchPlugin/CMakeLists.txt | 2 + .../SketchPlugin_ConstraintEqual.cpp | 44 ++++++++++++++++ .../SketchPlugin_ConstraintEqual.h | 51 +++++++++++++++++++ src/SketchPlugin/SketchPlugin_Plugin.cpp | 4 ++ src/SketchPlugin/plugin-Sketch.xml | 12 ++++- src/SketchSolver/SketchSolver_Constraint.cpp | 27 ++++++++++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp create mode 100644 src/SketchPlugin/SketchPlugin_ConstraintEqual.h diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 21b0cfbec..5167dd28c 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -24,6 +24,7 @@ SET(PROJECT_HEADERS SketchPlugin_ConstraintRigid.h SketchPlugin_ConstraintHorizontal.h SketchPlugin_ConstraintVertical.h + SketchPlugin_ConstraintEqual.h SketchPlugin_ShapeValidator.h SketchPlugin_Validators.h SketchPlugin_ResultValidators.h @@ -48,6 +49,7 @@ SET(PROJECT_SOURCES SketchPlugin_ConstraintRigid.cpp SketchPlugin_ConstraintHorizontal.cpp SketchPlugin_ConstraintVertical.cpp + SketchPlugin_ConstraintEqual.cpp SketchPlugin_ShapeValidator.cpp SketchPlugin_Validators.cpp SketchPlugin_ResultValidators.cpp diff --git a/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp b/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp new file mode 100644 index 000000000..00531acde --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp @@ -0,0 +1,44 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchPlugin_ConstraintEqual.cpp +// Created: 16 Mar 2015 +// Author: Artem ZHIDKOV + +#include "SketchPlugin_ConstraintEqual.h" + +#include +#include +#include + +#include +#include + +#include + +#include + +SketchPlugin_ConstraintEqual::SketchPlugin_ConstraintEqual() +{ +} + +void SketchPlugin_ConstraintEqual::initAttributes() +{ + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); +} + +void SketchPlugin_ConstraintEqual::execute() +{ +} + +AISObjectPtr SketchPlugin_ConstraintEqual::getAISObject(AISObjectPtr thePrevious) +{ + if (!sketch()) + return thePrevious; + + AISObjectPtr anAIS = thePrevious; + /// TODO: Equal constraint presentation should be put here + return anAIS; +} + + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintEqual.h b/src/SketchPlugin/SketchPlugin_ConstraintEqual.h new file mode 100644 index 000000000..b19e98989 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintEqual.h @@ -0,0 +1,51 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchPlugin_ConstraintEqual.h +// Created: 16 Mar 2015 +// Author: Artem ZHIDKOV + +#ifndef SketchPlugin_ConstraintEqual_H_ +#define SketchPlugin_ConstraintEqual_H_ + +#include "SketchPlugin.h" +#include +#include "SketchPlugin_ConstraintBase.h" + +/** \class SketchPlugin_ConstraintEqual + * \ingroup Plugins + * \brief Feature for creation of a new constraint specifying equality of lengths of two lines + * or equality of radii of two circular arcs (full circles) + * + * This constraint has two attributes: + * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() + */ +class SketchPlugin_ConstraintEqual : public SketchPlugin_ConstraintBase +{ + public: + /// Equal constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_EQUAL_ID("SketchConstraintEqual"); + return MY_CONSTRAINT_EQUAL_ID; + } + /// \brief Returns the kind of a feature + SKETCHPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = SketchPlugin_ConstraintEqual::ID(); + return MY_KIND; + } + + /// \brief Creates a new part document if needed + SKETCHPLUGIN_EXPORT virtual void execute(); + + /// \brief Request for initialization of data model of the feature: adding all attributes + SKETCHPLUGIN_EXPORT virtual void initAttributes(); + + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + + /// \brief Use plugin manager for features creation + SketchPlugin_ConstraintEqual(); +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 6aa24717d..5e1ac512c 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -115,6 +116,8 @@ FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID) return FeaturePtr(new SketchPlugin_ConstraintHorizontal); } else if (theFeatureID == SketchPlugin_ConstraintVertical::ID()) { return FeaturePtr(new SketchPlugin_ConstraintVertical); + } else if (theFeatureID == SketchPlugin_ConstraintEqual::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintEqual); } // feature of such kind is not found return FeaturePtr(); @@ -161,6 +164,7 @@ std::shared_ptr SketchPlugin_Plugin aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintHorizontal::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintVertical::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintEqual::ID(), aHasSketchPlane); } } return aMsg; diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 894e3a88f..0b98b3328 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -5,7 +5,7 @@ + + + + + + + + diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index b2c7185d7..980c51879 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -215,6 +216,32 @@ const int& SketchSolver_Constraint::getType( return getType(); } + if (aConstraintKind.compare(SketchPlugin_ConstraintEqual::ID()) == 0) + { + static const int aConstrType[3] = { + SLVS_C_EQUAL_RADIUS, + SLVS_C_EQUAL_LINE_ARC_LEN, + SLVS_C_EQUAL_LENGTH_LINES + }; + int aNbLines = 0; + int aNbEntities = 2; // lines and circles in SolveSpace constraints should start from SketchPlugin_Constraint::ENTITY_C() attribute + for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + AttrType aType = typeOfAttribute(anAttr); + if (aType == LINE) + { + myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + aNbLines++; + } + else if (aType == CIRCLE || aType == ARC) + myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + } + if (aNbEntities == 4) + myType = aConstrType[aNbLines]; + return getType(); + } + /// \todo Implement other kind of constraints return getType(); -- 2.39.2