Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
}
-/*std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
- findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
- double theTolerance, const QList<FeaturePtr>& theIgnore)
-{
- std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
- new GeomAPI_Pnt2d(theX, theY));
-
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
- for (int i = 0; i < theSketch->numberOfSubs(); i++) {
- FeaturePtr aFeature = theSketch->subFeature(i);
- if (!theIgnore.contains(aFeature)) {
- anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
-
- std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
- for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
- std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
- double x = aCurPoint->x();
- double y = aCurPoint->y();
- if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
- return aCurPoint;
- }
- }
- }
- }
- return std::shared_ptr<GeomDataAPI_Point2D>();
-}*/
-
-
-std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findFirstEqualPointInArgumentFeatures(
- const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
-
- // may be feature is not updated yet, execute is not performed and references features
- // are not created. Case: rectangle macro feature
- ModuleBase_Tools::flushUpdated(theFeature);
-
- std::list<AttributePtr> anAttributes = theFeature->data()->attributes(
- ModelAPI_AttributeRefList::typeId());
- std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
- for (; anIt != aLast && !aFeaturePoint.get(); anIt++) {
- std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIt);
- for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFeaturePoint.get(); i++) {
- ObjectPtr anObject = aCurSelList->object(i);
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
- if (aFeature.get())
- aFeaturePoint = PartSet_Tools::findFirstEqualPoint(aFeature, thePoint);
- }
- }
- return aFeaturePoint;
-}
-
-std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findFirstEqualPoint(
- const FeaturePtr& theFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
-
- // find the given point in the feature attributes
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes =
- theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
- std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
- aLast = anAttiributes.end();
- ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
-
- for (; anIt != aLast && !aFPoint; anIt++) {
- std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
- if (aCurPoint && aCurPoint->isInitialized() &&
- aValidators->isCase(theFeature, aCurPoint->id()) &&
- (aCurPoint->pnt()->distance(thePoint) < Precision::Confusion())) {
- aFPoint = aCurPoint;
- break;
- }
- }
- return aFPoint;
-}
-
-std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findFirstEqualPointInSketch(
- const CompositeFeaturePtr& theSketch,
- const std::shared_ptr<GeomDataAPI_Point2D>& theFeaturePoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- // get all sketch features. If the point with the given coordinates belong to any sketch feature,
- // the constraint is created between the feature point and the found sketch point
- std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
-
- std::list<ObjectPtr> aFeatures = aRefList->list();
- std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
-
- FeaturePtr aFeatureOfPoint = ModelAPI_Feature::feature(theFeaturePoint->owner());
- std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
- for (; anIt != aLast; anIt++) {
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
- if (!aFeature.get() || aFeatureOfPoint == aFeature)
- continue;
- aFPoint = PartSet_Tools::findFirstEqualPoint(aFeature, thePoint);
- if (aFPoint.get())
- break;
- }
- return aFPoint;
-}
-
std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
{
std::shared_ptr<GeomAPI_Pln> aPlane;
#include <ModelAPI_Events.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Data.h>
/// analysis of AIS
std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(attributeID()));
std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
if (anAISShape.get())
const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
if (getPoint2d(aView, aTDShape, aX, aY)) {
isDone = setPoint(aX, aY);
- setConstraintTo(aX, aY);
- //PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
+ setConstraintToPoint(aX, aY);
}
}
return isDone;
std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
if (!aData) // can be on abort of sketcher element
return false;
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(attributeID()));
PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
bool PartSet_WidgetPoint2D::restoreValueCustom()
{
std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(attributeID()));
double aValueX = aPoint->isInitialized() ? aPoint->x() : 0.;
double aValueY = aPoint->isInitialized() ? aPoint->y() : 0.;
return false;
}
-bool PartSet_WidgetPoint2D::setConstraintTo(double theClickedX, double theClickedY)
+bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY)
{
FeaturePtr aFeature = feature();
std::string anAttribute = attributeID();
std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
new GeomAPI_Pnt2d(theClickedX, theClickedY));
-
- // find a feature point by the selection mode
- std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
- if (aFeature->isMacro()) {
- // the macro feature will be removed after the operation is stopped, so we need to build
- // coicidence to possible sub-features
- aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(aFeature, aClickedPoint);
- }
- else {
- aFeaturePoint = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aFeature->data()->attribute(anAttribute));
- }
- if (!aFeaturePoint.get())
- return false;
-
- std::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findFirstEqualPointInSketch(
- mySketch, aFeaturePoint, aClickedPoint);
- if (!aFPoint.get())
+ AttributePoint2DPtr aClickedFeaturePoint = findFirstEqualPointInSketch(mySketch,
+ aFeature, aClickedPoint);
+ if (!aClickedFeaturePoint.get())
return false;
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
if (aRefAttr.get())
- aRefAttr->setAttr(aFPoint);
- else
- PartSet_Tools::createConstraint(mySketch, aFPoint, aFeaturePoint);
-
- return true;
-}
-
-bool PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
-{
- std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
-
- if (feature()->isMacro()) {
- AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
- std::shared_ptr<GeomDataAPI_Point2D> anAttrPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
- if (anAttrPoint.get()) {
+ aRefAttr->setAttr(aClickedFeaturePoint);
+ else {
+ // find a feature point by the selection mode
+ AttributePoint2DPtr aFeaturePoint;
+ if (aFeature->isMacro()) {
// the macro feature will be removed after the operation is stopped, so we need to build
// coicidence to possible sub-features
- aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(feature(),
- anAttrPoint->pnt());
+ aFeaturePoint = findFirstEqualPointInArgumentFeatures(aFeature, aClickedPoint);
}
+ else {
+ aFeaturePoint = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(aFeature->data()->attribute(anAttribute));
+ }
+ if (!aFeaturePoint.get())
+ return false;
+
+ PartSet_Tools::createConstraint(mySketch, aClickedFeaturePoint, aFeaturePoint);
}
- else {
- AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
- aFeaturePoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
- }
- if (!aFeaturePoint.get())
- return false;
+ return true;
+}
+bool PartSet_WidgetPoint2D::setConstraintToObject(const ObjectPtr& theObject)
+{
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
- if (aRefAttr.get())
+ if (aRefAttr.get()) {
aRefAttr->setObject(theObject);
+ }
else {
+ AttributePoint2DPtr aFeaturePoint;
+
+ if (feature()->isMacro()) {
+ AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
+ AttributePoint2DPtr anAttrPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
+ if (anAttrPoint.get()) {
+ // the macro feature will be removed after the operation is stopped, so we need to build
+ // coicidence to possible sub-features
+ aFeaturePoint = findFirstEqualPointInArgumentFeatures(feature(),
+ anAttrPoint->pnt());
+ }
+ }
+ else {
+ AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
+ aFeaturePoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
+ }
+ if (!aFeaturePoint.get())
+ return false;
+
// Create point-edge coincedence
FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
}
}
if (aFixedObject.get())
- setConstraintWith(aFixedObject);
+ setConstraintToObject(aFixedObject);
// fignal updated should be flushed in order to visualize possible created
// external objects e.g. selection of trihedron axis when input end arc point
updateObject(feature());
setPoint(aX, aY);
feature()->execute();
- setConstraintTo(aX, aY);
- //PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
+ setConstraintToPoint(aX, aY);
}
else if (aShape.ShapeType() == TopAbs_EDGE) {
// point is taken from mouse event and set in attribute. It should be done before setting
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
setPoint(aX, aY);
- setConstraintWith(aObject);
+ setConstraintToObject(aObject);
setValueState(Stored); // in case of edge selection, Apply state should also be updated
isAuxiliaryFeature = PartSet_Tools::isAuxiliarySketchEntity(aObject);
}
if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
return;
- /// Start alternative code
- //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
- // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
- //QList<FeaturePtr> aIgnore;
- //aIgnore.append(feature());
-
- //double aTolerance = aView->Convert(7);
- //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
- // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
- //if (aAttrPnt.get() != NULL) {
- // aFeaturePoint->setValue(aAttrPnt->pnt());
- // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
- // emit vertexSelected();
- //}
- /// End alternative code
emit focusOutWidget(this);
}
}
{
bool anOrphanPoint = false;
if (theFeature.get()) {
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+ AttributePoint2DPtr aPointAttr;
std::string aFeatureKind = theFeature->getKind();
if (aFeatureKind == SketchPlugin_Point::ID())
aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
return std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttributeRef);
}
+
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPointInArgumentFeatures(
+ const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
+
+ // may be feature is not updated yet, execute is not performed and references features
+ // are not created. Case: rectangle macro feature
+ ModuleBase_Tools::flushUpdated(theFeature);
+
+ std::list<AttributePtr> anAttributes = theFeature->data()->attributes(
+ ModelAPI_AttributeRefList::typeId());
+ std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
+ for (; anIt != aLast && !aFeaturePoint.get(); anIt++) {
+ std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIt);
+ for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFeaturePoint.get(); i++) {
+ ObjectPtr anObject = aCurSelList->object(i);
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+ if (aFeature.get())
+ aFeaturePoint = findFirstEqualPoint(aFeature, thePoint);
+ }
+ }
+ return aFeaturePoint;
+}
+
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPoint(
+ const FeaturePtr& theFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
+
+ // find the given point in the feature attributes
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes =
+ theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
+ aLast = anAttiributes.end();
+ ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+
+ for (; anIt != aLast && !aFPoint; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ if (aCurPoint && aCurPoint->isInitialized() &&
+ aValidators->isCase(theFeature, aCurPoint->id()) &&
+ (aCurPoint->pnt()->distance(thePoint) < Precision::Confusion())) {
+ aFPoint = aCurPoint;
+ break;
+ }
+ }
+ return aFPoint;
+}
+
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPointInSketch(
+ const CompositeFeaturePtr& theSketch,
+ const FeaturePtr& theSkipFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ // get all sketch features. If the point with the given coordinates belong to any sketch feature,
+ // the constraint is created between the feature point and the found sketch point
+ std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+ std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
+
+ std::list<ObjectPtr> aFeatures = aRefList->list();
+ std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
+
+ std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+ if (!aFeature.get() || (theSkipFeature.get() && theSkipFeature == aFeature))
+ continue;
+ aFPoint = PartSet_WidgetPoint2D::findFirstEqualPoint(aFeature, thePoint);
+ if (aFPoint.get())
+ break;
+ }
+ return aFPoint;
+}
class ModelAPI_Feature;
class ModelAPI_AttributeRefAttr;
+class GeomDataAPI_Point2D;
class ModuleBase_IWorkshop;
class ModuleBase_ParamSpinBox;
class ModuleBase_IViewWindow;
/// Creates constrains of the clicked point
/// \param theClickedX the horizontal coordnate of the point
/// \param theClickedY the vertical coordnate of the point
- bool setConstraintTo(double theClickedX, double theClickedY);
+ bool setConstraintToPoint(double theClickedX, double theClickedY);
/// Create a coincidence constraint between the attribute and the parameter object
/// \theObject a result object
/// \return true if succed
- bool setConstraintWith(const ObjectPtr& theObject);
+ bool setConstraintToObject(const ObjectPtr& theObject);
/// Returns if the feature is an orphan point, circle or an arc. Returns true if it
/// has no a coincident to other lines. It processes point, circle and arc features
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
const CompositeFeaturePtr& theSketch);
- std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
+ /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates
+ /// \param theFeature a feature with sub-feature attributes
+ /// \param thePoint a point to provided searched coordinates
+ /// \return found point or null
+ static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
+ const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+ /// Finds in the feature first Point2D attribute with the given point coordinates
+ /// \param theFeature a feature with point attributes
+ /// \param thePoint a point to provided searched coordinates
+ /// \return found point or null
+ static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+ /// Finds in the sketch attribute point of any feature that is nearest to the given point
+ /// \param theSketch a sketch, that is a container of features
+ /// \param theSkipFeature a feature that do not participate in the search
+ /// \param thePoint a point to provided searched coordinates
+ /// \return found point or null
+ static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInSketch(
+ const CompositeFeaturePtr& theSketch,
+ const FeaturePtr& theSkipFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+ /// Returns attribute reference if the key is defined in XML definition of this control
+ /// \return found attribute or null
+ std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
protected:
ModuleBase_IWorkshop* myWorkshop; ///< workshop