X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintDistance.h;h=ed2dfed6cd568e2991de88e80f14d36b1f1aa79f;hb=e8b0963c64ad81be042fffe660ce874ae4d3abd5;hp=48b59e1ed02b442988f7dc1acc836c7804d23455;hpb=d56fb361cb3725fbf72b3d6c5a152652b83ab463;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 48b59e1ed..ed2dfed6c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -1,132 +1,113 @@ -// File: SketchPlugin_ConstraintDistance.h -// Created: 08 May 2014 -// Author: Artem ZHIDKOV +// 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_ConstraintDistance_HeaderFile -#define SketchPlugin_ConstraintDistance_HeaderFile +#ifndef SketchPlugin_ConstraintDistance_H_ +#define SketchPlugin_ConstraintDistance_H_ #include "SketchPlugin.h" -#include "SketchPlugin_Constraint.h" -#include +#include "SketchPlugin_ConstraintBase.h" +#include "SketchPlugin_Sketch.h" +#include "ModelAPI_Data.h" + +#include -/// The distance value -const std::string CONSTRAINT_ATTR_DISTANCE(CONSTRAINT_ATTR_VALUE); +#include +class SketchPlugin_Line; +class GeomDataAPI_Point2D; /** \class SketchPlugin_ConstraintDistance - * \ingroup DataModel - * \brief Feature for creation of a new constraint which fixes the distance - * between two other features. - * - * There are allowed several kinds of distances: - * \li The next constraints use "valA", "ptA" and "entityA" parameters: - * point-point, point-line, point-plane, point-face; - * \li The distance between two points projected on a line (or vector) - * uses "valA", "ptA", "ptB", "entityA"; - * \li The diameter of a circle is defined by "valA" and "entityA"; - * \li The angle between two lines (or vectors) uses "valA", "entityA", "entityB". + * \ingroup Plugins + * \brief Feature for creation of a new constraint which defines a distance + * between a point and another feature (point, line, plane or face) * - * The default list of attributes contains only CONSTRAINT_ATTR_DISTANCE. - * - * \remark As far as the constraint may have different attributes, - * it is strongly recommended to use setAttibutes() methods - * instead of direct intialization of the attributes + * This constraint has three attributes: + * SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ -class SketchPlugin_ConstraintDistance: public SketchPlugin_Constraint +class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase { -public: + public: + /// Distance constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistance"); + return MY_CONSTRAINT_DISTANCE_ID; + } + /// \brief Returns the kind of a feature - SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraintDistance"; return MY_KIND;} + SKETCHPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = SketchPlugin_ConstraintDistance::ID(); + return MY_KIND; + } + + /// \brief Shows whether the point-line distance should keep its sign + inline static const std::string& SIGNED() + { + static const std::string MY_SIGNED("SignedDistance"); + return MY_SIGNED; + } - /// \brief Returns to which group in the document must be added feature - SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = "Sketch"; return MY_GROUP;} + /// \brief The direction from the first object to the second. + /// To change distance value from zero to non-zero correctly. + inline static const std::string& DIRECTION_ID() + { + static const std::string MY_DIRECTION_ID("DistanceDirection"); + return MY_DIRECTION_ID; + } + + /// attribute name of dimension location type + inline static const std::string& LOCATION_TYPE_ID() + { + static const std::string MY_LOCATION_TYPE_ID("LocationType"); + return MY_LOCATION_TYPE_ID; + } /// \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 - * - * The setAttributes() methods should be used instead. - */ - SKETCHPLUGIN_EXPORT virtual void initAttributes() - { /* do nothing */ } + /// \brief Request for initialization of data model of the feature: adding all attributes + SKETCHPLUGIN_EXPORT virtual void initAttributes(); + + /// Retuns the parameters of color definition in the resources config manager + SKETCHPLUGIN_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); /// \brief Use plugin manager for features creation - SKETCHPLUGIN_EXPORT SketchPlugin_ConstraintDistance(); - - /** \brief Initializes the attributes of the constraint - * - * Defines the distance between a point and another entity, - * or defines the angle between two vectors. - * - * \param[in] theDistance distance (or angle) between two entities - * \param[in] theEntityA first parameter of the constraint - * \param[in] theEntityB second parameter of the constraint - */ - SKETCHPLUGIN_EXPORT void setAttributes( - const double theDistance, - const boost::shared_ptr theEntityA, - const boost::shared_ptr theEntityB); - /** \brief Initializes the attributes of the constraint - * - * Defines the distance between a point defined by reference and another entity. - * - * \param[in] theDistance distance between the point and other entity - * \param[in] thePoint reference to the point attribute - * \param[in] theEntity other parameter of the constraint - */ - SKETCHPLUGIN_EXPORT void setAttributes( - const double theDistance, - const boost::shared_ptr thePoint, - const boost::shared_ptr theEntity); - /** \brief Initializes the attributes of the constraint - * - * Defines the distance between two points which defined by references. - * - * \param[in] theDistance distance between the points - * \param[in] thePointA reference to the first point attribute - * \param[in] thePointB reference to the second point attribute - */ - SKETCHPLUGIN_EXPORT void setAttributes( - const double theDistance, - const boost::shared_ptr thePointA, - const boost::shared_ptr thePointB); - /** \brief Initializes the attributes of the constraint - * - * Defines radius of a circle. - * - * \param[in] theRadius radius of the circle - * \param[in] theCircle the circle which has specified radius - */ - SKETCHPLUGIN_EXPORT void setAttributes( - const double theRadius, - const boost::shared_ptr theCircle); - /** \brief Initializes the attributes of the constraint - * - * Defines the distance between two points projected on specified vector (or line). - * - * \param[in] theDistance distance between projected points - * \param[in] thePointA first point for the projection - * \param[in] thePointB second point for the projection - * \param[in] theEntity direction of the line which the points projected on - */ - SKETCHPLUGIN_EXPORT void setAttributes( - const double theDistance, - const boost::shared_ptr thePointA, - const boost::shared_ptr thePointB, - const boost::shared_ptr theEntity); - -private: - /** \brief Returns the list of attributes for the certain type of constraint. - * \return names of attributes - */ - const std::list& getAttributesList() const - { return myAttrList; } - -private: - std::list myAttrList; ///< List of attributes for current constraint + SketchPlugin_ConstraintDistance(); + +protected: + /// Returns the current distance between the feature attributes + virtual double calculateCurrentDistance(); + + /// Check the attributes related to distanced points/features are initialized + bool areAttributesInitialized(); + +protected: + bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point }; #endif