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
<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"/>