+++ /dev/null
-@ECHO OFF
-
-REM Find absolute path to ROOT_DIR
-@SET PARENT_DIR=%~dp0..
-@SET ROOT_DIR=
-pushd %PARENT_DIR%
-@SET ROOT_DIR=%CD%
-popd
-
-@SET SRC_DIR=%ROOT_DIR%\sources
-@SET OCC_LIB_PREFIX=d
-
-call %SRC_DIR%\env_Salome.bat d
-mkdir %ROOT_DIR%\build
-cd %ROOT_DIR%\build
-
-cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
-
-start "" %MSVC_EXE% NewGEOM.sln
+++ /dev/null
-@ECHO OFF
-
-REM Find absolute path to ROOT_DIR
-@SET PARENT_DIR=%~dp0..
-@SET ROOT_DIR=
-pushd %PARENT_DIR%
-@SET ROOT_DIR=%CD%
-popd
-
-@SET SRC_DIR=%ROOT_DIR%\sources
-
-call %SRC_DIR%\env_Salome.bat
-mkdir %ROOT_DIR%\build
-cd %ROOT_DIR%\build
-
-cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
-
-start "" %MSVC_EXE% NewGEOM.sln
--- /dev/null
+@ECHO OFF
+
+REM Find absolute path to ROOT_DIR
+@SET PARENT_DIR=%~dp0..
+@SET ROOT_DIR=
+pushd %PARENT_DIR%
+@SET ROOT_DIR=%CD%
+popd
+
+@SET SRC_DIR=%ROOT_DIR%\sources
+@SET OCC_LIB_PREFIX=d
+
+call %SRC_DIR%\env_Salome.bat d
+mkdir %ROOT_DIR%\build
+cd %ROOT_DIR%\build
+
+cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
+
+start "" %MSVC_EXE% NewGEOM.sln
--- /dev/null
+@ECHO OFF
+
+REM Find absolute path to ROOT_DIR
+@SET PARENT_DIR=%~dp0..
+@SET ROOT_DIR=
+pushd %PARENT_DIR%
+@SET ROOT_DIR=%CD%
+popd
+
+@SET SRC_DIR=%ROOT_DIR%\sources
+
+call %SRC_DIR%\env_Salome.bat
+mkdir %ROOT_DIR%\build
+cd %ROOT_DIR%\build
+
+cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
+
+start "" %MSVC_EXE% NewGEOM.sln
if (anAttr) {
myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
anAttr->setObject(myObject);
+ anAttr->setID(theID);
} else {
Events_Error::send("Can not create unknown type of attribute " + theAttrType);
}
static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
if (myObject) {
- myObject->attributeChanged();
+ myObject->attributeChanged(theAttr->id());
}
}
}
{
///< needed here to emit signal that feature changed on change of the attribute
std::shared_ptr<ModelAPI_Object> myObject;
+ std::string myID; ///< identifier of this attribute in Data class
protected:
// accessible from the attributes
- bool myIsInitialized;
- bool myIsArgument;
- bool myIsImmutable;
+ bool myIsInitialized; ///< is some value assigned to this attribute
+ bool myIsArgument; ///< is this attribute used as an argument for execution
+ bool myIsImmutable; ///< is this attribute can be changed programmatically (e.g. by constraint)
public:
return myIsImmutable;
}
+ /// ID of the attribute in Data
+ MODELAPI_EXPORT const std::string& id() const
+ {
+ return myID;
+ }
+
protected:
/// Objects are created for features automatically
ModelAPI_Attribute()
myIsImmutable = false;
}
+ /// Sets the ID of the attribute in Data (called from Data)
+ MODELAPI_EXPORT void setID(const std::string theID)
+ {
+ myID = theID;
+ }
+
+ friend class Model_Data;
};
//! Pointer on attribute object
virtual std::string groupName() = 0;
/// Called on change of any argument-attribute of this object
- MODELAPI_EXPORT virtual void attributeChanged()
+ /// \param theID identifier of changed attribute
+ MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID)
{}
/// To use virtuality for destructors
ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
if (aBody) {
AttributePtr aAttr = aData->attribute(attributeID());
- std::shared_ptr<ModelAPI_AttributeSelection> aSelectAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
+ AttributeSelectionPtr aSelectAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
if (aSelectAttr)
aSelectAttr->setValue(aBody, myShape);
updateObject(myFeature);
DataPtr aData = myFeature->data();
bool isBlocked = this->blockSignals(true);
if (myUseSubShapes) {
- std::shared_ptr<ModelAPI_AttributeSelection> aSelect = aData->selection(attributeID());
+ AttributeSelectionPtr aSelect = aData->selection(attributeID());
if (aSelect) {
mySelectedObject = aSelect->context();
myShape = aSelect->value();
virtual ~ModuleBase_WidgetShapeSelector();
/// Saves the internal parameters to the given feature
- /// \param theObject a model feature to be changed
virtual bool storeValue() const;
virtual bool restoreValue();
void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
//----------- Class members -------------
- private:
+ protected:
QWidget* myContainer;
QLabel* myLabel;
QLineEdit* myTextLine;
PartSet.h
PartSet_Constants.h
PartSet_EditLine.h
-# PartSet_Listener.h
PartSet_Module.h
-# PartSet_OperationFeatureCreate.h
-# PartSet_OperationFeatureEdit.h
-# PartSet_OperationSketchBase.h
-# PartSet_OperationSketch.h
-# PartSet_OperationFeatureBase.h
PartSet_Tools.h
PartSet_WidgetSketchLabel.h
PartSet_Validators.h
PartSet_WidgetPoint2d.h
PartSet_WidgetPoint2dDistance.h
-# PartSet_Operation.h
+ PartSet_WidgetShapeSelector.h
)
SET(PROJECT_SOURCES
PartSet_EditLine.cpp
-# PartSet_Listener.cpp
PartSet_Module.cpp
-# PartSet_OperationFeatureCreate.cpp
-# PartSet_OperationFeatureEdit.cpp
-# PartSet_OperationSketchBase.cpp
-# PartSet_OperationSketch.cpp
-# PartSet_OperationFeatureBase.cpp
PartSet_Tools.cpp
PartSet_WidgetSketchLabel.cpp
PartSet_Validators.cpp
PartSet_WidgetPoint2d.cpp
PartSet_WidgetPoint2dDistance.cpp
-# PartSet_Operation.cpp
+ PartSet_WidgetShapeSelector.cpp
)
SET(PROJECT_RESOURCES
#include "PartSet_Tools.h"
#include "PartSet_WidgetPoint2D.h"
#include "PartSet_WidgetPoint2dDistance.h"
-//#include "PartSet_Operation.h"
+#include "PartSet_WidgetShapeSelector.h"
#include <ModuleBase_Operation.h>
#include <ModuleBase_IViewer.h>
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
//#include <Config_PointerMessage.h>
//#include <Config_ModuleReader.h>
QStringList PartSet_Module::sketchOperationIdList() const
{
QStringList aIds;
- aIds << SketchPlugin_Sketch::ID().c_str();
aIds << SketchPlugin_Line::ID().c_str();
aIds << SketchPlugin_Point::ID().c_str();
aIds << SketchPlugin_Arc::ID().c_str();
aIds << SketchPlugin_Circle::ID().c_str();
+ aIds << SketchPlugin_ConstraintLength::ID().c_str();
+ aIds << SketchPlugin_ConstraintDistance::ID().c_str();
+ aIds << SketchPlugin_ConstraintRigid::ID().c_str();
+ aIds << SketchPlugin_ConstraintRadius::ID().c_str();
+ aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
+ aIds << SketchPlugin_ConstraintParallel::ID().c_str();
return aIds;
}
aWgt->setWorkshop(aWorkshop);
theModelWidgets.append(aWgt);
return aWgt->getControl();
+
} else if (theType == "sketch-2dpoint_selector") {
PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
aWgt->setWorkshop(aWorkshop);
theModelWidgets.append(aWgt);
return aWgt->getControl();
+
} if (theType == "point2ddistance") {
PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
aWgt->setWorkshop(aWorkshop);
theModelWidgets.append(aWgt);
return aWgt->getControl();
+
+ } if (theType == "sketch_shape_selector") {
+ PartSet_WidgetShapeSelector* aWgt =
+ new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
+ aWgt->setSketcher(myCurrentSketch);
+
+ theModelWidgets.append(aWgt);
+ return aWgt->getControl();
+
}else
return 0;
}
theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
}
-void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
- gp_Pnt& thePoint)
+std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch)
{
- if (!theSketch)
- return;
-
std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
- std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
- ->added(aY->dir()->xyz()->multiplied(theY));
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d =
+ std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
- std::shared_ptr<GeomAPI_Pnt> aPoint = std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
- thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z());
+ return aPnt2d->to3D(aC->pnt(), aX->dir(), aY->dir());
}
ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
return aHasVertex;
}
+
+AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
+ const TopoDS_Shape theShape,
+ FeaturePtr theSketch)
+{
+
+ AttributePtr anAttribute;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
+ if (aFeature) {
+ if (theShape.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
+ if (!aVertex.IsNull()) {
+ gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+ std::shared_ptr<GeomAPI_Pnt> aValue = std::shared_ptr<GeomAPI_Pnt>(
+ new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
+
+ // find the given point in the feature attributes
+ std::list<AttributePtr> anAttiributes =
+ aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+ std::list<AttributePtr>::const_iterator anIt = anAttiributes.begin(),
+ aLast = anAttiributes.end();
+ for (; anIt != aLast && !anAttribute; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+
+ std::shared_ptr<GeomAPI_Pnt> aPnt = convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch);
+ if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) {
+ anAttribute = aCurPoint;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return anAttribute;
+}
#include <QList>
#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
+
+#include <TopoDS_Shape.hxx>
#include <memory>
/// \param theY the Y coordinate
/// \param theSketch the sketch feature
/// \param thePoint the 3D point in the viewer
- static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
- gp_Pnt& thePoint);
+ static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
/// Returns an object that is under the mouse point. Firstly it checks the highlighting,
/// if it exists, the first object is returned. Secondly, there is an iteration on
/// \param theY the output vertical coordinate of the point
static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
Handle_V3d_View theView, double& theX, double& theY);
+
+
+ /**
+ * Find attribute of object which corresponds to the given shape
+ * \param theObj - an object
+ * \param theShape - a Shape
+ * \param theSketch - a Sketch to get a plane of converting to 2d
+ */
+ static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
+
protected:
/// Returns an object that is under the mouse point. Firstly it checks the highlighting,
/// if it exists, the first object is returned. Secondly, there is an iteration on
--- /dev/null
+// File: PartSet_WidgetShapeSelector.cpp
+// Created: 27 Nov 2014
+// Author: Vitaly Smetannikov
+
+#include "PartSet_WidgetShapeSelector.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <PartSet_Tools.h>
+
+
+bool PartSet_WidgetShapeSelector::storeValue() const
+{
+ if (!mySelectedObject)
+ return false;
+
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
+ if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
+ return false;
+
+ DataPtr aData = myFeature->data();
+ if (myUseSubShapes && myShape) {
+ AttributePtr aAttr = aData->attribute(attributeID());
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+ if (aRefAttr) {
+ TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
+ AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
+ if (mySelectedObject)
+ aRefAttr->setObject(mySelectedObject);
+ if (aPntAttr)
+ aRefAttr->setAttr(aPntAttr);
+
+ updateObject(myFeature);
+ return true;
+ }
+ }
+ return ModuleBase_WidgetShapeSelector::storeValue();
+}
--- /dev/null
+// File: PartSet_WidgetShapeSelector.h
+// Created: 27 Nov 2014
+// Author: Vitaly Smetannikov
+
+
+#ifndef PartSet_WidgetShapeSelector_H
+#define PartSet_WidgetShapeSelector_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_WidgetShapeSelector.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+class PARTSET_EXPORT PartSet_WidgetShapeSelector: public ModuleBase_WidgetShapeSelector
+{
+Q_OBJECT
+ public:
+ PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData, const std::string& theParentId)
+ : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
+
+ virtual ~PartSet_WidgetShapeSelector() {}
+
+ /// Saves the internal parameters to the given feature
+ virtual bool storeValue() const;
+
+ void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+ CompositeFeaturePtr sketch() const { return mySketch; }
+
+private:
+ CompositeFeaturePtr mySketch;
+};
+
+#endif
\ No newline at end of file
return data()->selection(EXTERNAL_ID())->context();
}
-void SketchPlugin_Circle::attributeChanged() {
- static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change
- std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
- // update arguments due to the selection value
- if (aSelection && !aSelection->isNull() && aSelection->isEdge() && !myIsUpdated) {
- myIsUpdated = true;
- std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
- std::shared_ptr<GeomAPI_Circ> aCirc = anEdge->circle();
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
- aCenterAttr->setValue(sketch()->to2D(aCirc->center()));
- real(RADIUS_ID())->setValue(aCirc->radius());
- myIsUpdated = false;
+void SketchPlugin_Circle::attributeChanged(const std::string& theID) {
+ if (theID == EXTERNAL_ID()) {
+ std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
+ // update arguments due to the selection value
+ if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
+ std::shared_ptr<GeomAPI_Circ> aCirc = anEdge->circle();
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
+ aCenterAttr->setValue(sketch()->to2D(aCirc->center()));
+ real(RADIUS_ID())->setValue(aCirc->radius());
+ }
}
}
virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
/// Called on change of any argument-attribute of this object
- SKETCHPLUGIN_EXPORT virtual void attributeChanged();
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
/// Use plugin manager for features creation
SketchPlugin_Circle();
// value calculation
std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
- // TODO: has to be calculated on definition of reference object
- double aValue;
+ double aValue = 0;
// Issue #196: checking the positivity of the distance constraint
// there is a validator for a distance constraint, that the value should be positive
// in case if an invalid value is set, the current distance value is shown
if (aValueAttr->isInitialized())
aValue = aValueAttr->value();
- else {
- aValue = calculateCurrentDistance();
- aValueAttr->setValue(aValue);
- }
- // End TODO
AISObjectPtr anAIS = thePrevious;
if (!anAIS)
return aDistance;
}
+void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_Constraint::ENTITY_A() ||
+ theID == SketchPlugin_Constraint::ENTITY_B())
+ {
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+ if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+ double aDistance = calculateCurrentDistance();
+ if (aDistance > 0) { // set as value the length of updated references
+ aValueAttr->setValue(aDistance);
+ }
+ }
+ }
+}
//*************************************************************************************
std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ /// 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);
+
/// Returns the current distance between the feature attributes
double calculateCurrentDistance() const;
}
}
-AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePrevious)
+bool SketchPlugin_ConstraintLength::getPoints(
+ std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
+ std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
+ std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint)
{
if (!sketch())
- return thePrevious;
-
+ return false;
std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
-
std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
if (!anAttr)
- return thePrevious;
+ return false;
FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID())
- return thePrevious;
-
- std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-
+ return false;
DataPtr aData = aFeature->data();
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint = std::dynamic_pointer_cast<
+ theStartPoint = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> anEndPoint = std::dynamic_pointer_cast<
+ theEndPoint = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
+ thePoint1 = sketch()->to3D(theStartPoint->x(), theStartPoint->y());
+ thePoint2 = sketch()->to3D(theEndPoint->x(), theEndPoint->y());
+ return true;
+}
- std::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aStartPoint->x(), aStartPoint->y());
- std::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(anEndPoint->x(), anEndPoint->y());
+AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePrevious)
+{
+ std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
+ if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint))
+ return thePrevious; // not possible to show length because points are not defined
+
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = std::shared_ptr<GeomAPI_Pnt>();
if (aFlyOutAttr->isInitialized()) {
aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
// Set color from preferences
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR);
+ std::vector<int> aRGB =
+ Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR);
anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
aPoint->move(theDeltaX, theDeltaY);
}
+void SketchPlugin_ConstraintLength::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_Constraint::ENTITY_A())
+ {
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+ if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+ std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
+ if (getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) {
+ double aLength = aPoint1->distance(aPoint2);
+ aValueAttr->setValue(aLength);
+ }
+ }
+ }
+}
#include <SketchPlugin_Sketch.h>
#include <list>
+class GeomDataAPI_Point2D;
+
#define LENGTH_COLOR "#ff00ff"
/** \class SketchPlugin_ConstraintLength
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ /// 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_ConstraintLength();
+
+private:
+ // retrns the points-base of length, returns false if it is not possible
+ bool getPoints(
+ std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
+ std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
+ std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint);
};
#endif
}
}
-AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePrevious)
+double SketchPlugin_ConstraintRadius::circleRadius(std::shared_ptr<ModelAPI_Feature>& theCirc)
{
+ static const double kErrorResult = -1.;
if (!sketch())
- return thePrevious;
+ return kErrorResult;
std::shared_ptr<ModelAPI_Data> aData = data();
std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
if (!anAttr)
- return thePrevious;
- FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
- std::string aKind = aFeature ? aFeature->getKind() : "";
+ return kErrorResult;
+ theCirc = ModelAPI_Feature::feature(anAttr->object());
+ std::string aKind = theCirc ? theCirc->getKind() : "";
if (aKind != SketchPlugin_Circle::ID() && aKind != SketchPlugin_Arc::ID())
- return thePrevious;
+ return kErrorResult;
+
+ DataPtr aCircData = theCirc->data();
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
+ if (aKind == SketchPlugin_Circle::ID()) {
+ AttributeDoublePtr aCircRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ aCircData->attribute(SketchPlugin_Circle::RADIUS_ID()));
+ return aCircRadius->value();
+ } else {
+ aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aCircData->attribute(SketchPlugin_Arc::CENTER_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(aCircData->attribute(SketchPlugin_Arc::START_ID()));
+ return aCenterAttr->pnt()->distance(aStartAttr->pnt());
+ }
+ return kErrorResult;
+}
+
+AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePrevious)
+{
+ std::shared_ptr<ModelAPI_Feature> aCyrcFeature;
+ double aRadius = circleRadius(aCyrcFeature);
+ if (aRadius < 0)
+ return thePrevious; // can not create a good presentation
// Flyout point
std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt;
if (aFlyoutAttr->isInitialized()) {
aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
}
// Prepare a circle
- std::shared_ptr<ModelAPI_Data> aCyrcData = aFeature->data();
std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
- double aRadius;
- if (aKind == SketchPlugin_Circle::ID()) {
+ if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle
aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aCyrcData->attribute(SketchPlugin_Circle::CENTER_ID()));
- AttributeDoublePtr aCircRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- aCyrcData->attribute(SketchPlugin_Circle::RADIUS_ID()));
- aRadius = aCircRadius->value();
+ aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
if (!aFlyoutPnt) {
double aShift = aRadius * 1.1;
std::shared_ptr<GeomAPI_Pnt2d> aPnt = aCenterAttr->pnt();
aFlyoutAttr->setValue(aFPnt);
aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y());
}
- } else if (aKind == SketchPlugin_Arc::ID()) {
+ } else { // arc
aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aCyrcData->attribute(SketchPlugin_Arc::CENTER_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aCyrcData->attribute(SketchPlugin_Arc::START_ID()));
- aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+ aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
if (!aFlyoutPnt) {
std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aCyrcData->attribute(SketchPlugin_Arc::START_ID()));
+ GeomDataAPI_Point2D>(aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
aFlyoutAttr->setValue(aStartAttr->pnt());
aFlyoutPnt = sketch()->to3D(aStartAttr->pnt()->x(), aStartAttr->pnt()->y());
}
std::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
// Value
- // TODO: has to be calculated on definition of reference object
std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
- double aValue = aRadius;
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
if (aValueAttr->isInitialized())
- aValue = aValueAttr->value();
- else {
- aValueAttr->setValue(aValue);
- }
- // End TODO
+ aRadius = aValueAttr->value();
AISObjectPtr anAIS = thePrevious;
if (!anAIS)
anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createRadius(aCircle, aFlyoutPnt, aValue);
+ anAIS->createRadius(aCircle, aFlyoutPnt, aRadius);
// Set color from preferences
std::vector<int> aRGB = Config_PropManager::color("Visualization", "radius_color", RADIUS_COLOR);
aFlyoutAttr->setValue(aFlyout->x(), aFlyout->y());
}
+
+void SketchPlugin_ConstraintRadius::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_Constraint::ENTITY_A()) {
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+ if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+ std::shared_ptr<ModelAPI_Feature> aCyrcFeature;
+ double aRadius = circleRadius(aCyrcFeature);
+ if (aRadius > 0) { // set as value the radius of updated reference to another circle
+ aValueAttr->setValue(aRadius);
+ }
+ }
+ }
+}
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ /// 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_ConstraintRadius();
+
+private:
+ /// Checks and gets the radius of referenced circle (or arc) otherwise returns -1.
+ /// \param theCircData the found referenced circle returned by this method
+ double circleRadius(std::shared_ptr<ModelAPI_Feature>& theCirc);
};
#endif
return data()->selection(EXTERNAL_ID())->context();
}
-void SketchPlugin_Line::attributeChanged() {
- static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change
- std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
- // update arguments due to the selection value
- if (aSelection && !aSelection->isNull() && aSelection->isEdge() && !myIsUpdated) {
- myIsUpdated = true;
- std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
- std::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_ID()));
- aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint()));
- std::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_ID()));
- anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
- myIsUpdated = false;
+void SketchPlugin_Line::attributeChanged(const std::string& theID) {
+ if (theID == EXTERNAL_ID()) {
+ std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
+ // update arguments due to the selection value
+ if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
+ std::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_ID()));
+ aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint()));
+ std::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_ID()));
+ anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
+ }
}
}
virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
/// Called on change of any argument-attribute of this object
- SKETCHPLUGIN_EXPORT virtual void attributeChanged();
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
/// Use plugin manager for features creation
SketchPlugin_Line();
ModelAPI_CompositeFeature::erase();
}
-void SketchPlugin_Sketch::attributeChanged() {
- static bool kIsUpdated = false; // to avoid infinitive cycle on attrubtes change
- static bool kIsAttrChanged = false;
- std::shared_ptr<GeomAPI_Shape> aSelection =
- data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
- if (aSelection && !kIsUpdated) { // update arguments due to the selection value
- kIsUpdated = true;
- // update the sketch plane
- std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
- if (aPlane) {
- double anA, aB, aC, aD;
- aPlane->coefficients(anA, aB, aC, aD);
-
- // calculate attributes of the sketch
- std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
- std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
- std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
- aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
- std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
- // X axis is preferable to be dirX on the sketch
- static const double tol = 1.e-7;
- bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
- std::shared_ptr<GeomAPI_Dir> aTempDir(
- isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
- std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
- std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
-
- kIsAttrChanged = false; // track the attributes were really changed during the plane update
- std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast
- <GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- anOrigin->setValue(anOrigPnt);
- std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- aNormal->setValue(aNormDir);
- std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- aDirX->setValue(aXDir);
- std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
- aDirY->setValue(aYDir);
- std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
-
- if (kIsAttrChanged) {
- /* now it is in updater
- // the plane was changed, so reexecute sub-elements to update shapes (located in new plane)
- ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
- list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
- for(list<ObjectPtr>::iterator aSubIt = aSubs.begin(); aSubIt != aSubs.end(); aSubIt++) {
- std::shared_ptr<SketchPlugin_Feature> aFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(*aSubIt);
- if (aFeature && aFactory->validate(aFeature)) {
- aFeature->execute();
- }
- }
- */
- kIsAttrChanged = false;
+void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_Feature::EXTERNAL_ID()) {
+ std::shared_ptr<GeomAPI_Shape> aSelection =
+ data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
+ if (aSelection) { // update arguments due to the selection value
+ // update the sketch plane
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
+ if (aPlane) {
+ double anA, aB, aC, aD;
+ aPlane->coefficients(anA, aB, aC, aD);
+
+ // calculate attributes of the sketch
+ std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+ std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+ aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+ std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
+ // X axis is preferable to be dirX on the sketch
+ static const double tol = 1.e-7;
+ bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
+ std::shared_ptr<GeomAPI_Dir> aTempDir(
+ isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
+ std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
+ std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
+
+ // update position of the sketch
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast
+ <GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ anOrigin->setValue(anOrigPnt);
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aNormal->setValue(aNormDir);
+ std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ aDirX->setValue(aXDir);
+ std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+ aDirY->setValue(aYDir);
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
}
}
- kIsUpdated = false;
- } else if (kIsUpdated) { // other attributes are updated during the selection comupation
- kIsAttrChanged = true;
}
}
/// Returns the point projected into the sketch plane
std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt);
- SKETCHPLUGIN_EXPORT virtual void attributeChanged();
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
protected:
/// Creates a plane and append it to the list
/// \param theX the X normal value
<feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object" icon=":icons/distance.png">
<label title="Select objects for distance definition. Following objects can be accepted: point, line or arc end point, center of circle or arc."/>
- <shape_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc."
- shape_types="edge vertex"/>
- <shape_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc."
- shape_types="edge vertex"/>
+ <sketch_shape_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc."
+ shape_types="edge vertex" use_subshapes="true"/>
+ <sketch_shape_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc."
+ shape_types="edge vertex" use_subshapes="true"/>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed" min="0">
<validator id="GeomValidators_Positive"/>
//if (aPointWidget)
// connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
// SIGNAL(storedPoint2D(ObjectPtr, const std::string&)))
+ //}
if (!isEnableStretch) continue;
foreach(QWidget* eachWidget, (*anIt)->getControls()) {