}
}
-/// Returns point of coincidence feature
-/// \param theFeature the coincidence feature
-/// \param theAttribute the attribute name
-std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::string& theAttribute)
-{
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
-
- if (!theFeature->data())
- return std::shared_ptr<GeomAPI_Pnt2d>();
-
- FeaturePtr aFeature;
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
- if (anAttr)
- aFeature = ModelAPI_Feature::feature(anAttr->object());
-
- if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
-
- else if (anAttr->attr()) {
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
- }
- if (aPointAttr.get() != NULL)
- return aPointAttr->pnt();
- return std::shared_ptr<GeomAPI_Pnt2d>();
-}
-
-/// Returns list of features connected in a councedence feature point
-/// \param theStartCoin the coincidence feature
-/// \param theList a list which collects lines features
-/// \param theAttr the attribute name
-void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList, std::string theAttr)
-{
- AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
- FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object());
- if (!theList.contains(aObj)) {
- std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
- if (aOrig.get() == NULL)
- return;
- theList.append(aObj);
- const std::set<AttributePtr>& aRefsList = aObj->data()->refsToMe();
- std::set<AttributePtr>::const_iterator aIt;
- for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- std::shared_ptr<GeomAPI_Pnt2d> aPnt = getPoint(aConstrFeature, theAttr);
- if (aPnt.get() && aOrig->isEqual(aPnt)) {
- findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A());
- findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B());
- }
- }
- }
- }
-}
-
-
bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
{
ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
std::shared_ptr<GeomAPI_Pnt2d> a2dPnt =
- getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) {
aCoincident = aConstrFeature;
break;
} else {
- a2dPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ a2dPnt = PartSet_Tools::getPoint(aConstrFeature,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) {
aCoincident = aConstrFeature;
break;
// If we have coincidence then add Detach menu
if (aCoincident.get() != NULL) {
mySelectedFeature = aCoincident;
- findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_A());
- findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
if (myCoinsideLines.size() > 0) {
aIsDetach = true;
QMenu* aSubMenu = theMenu->addMenu(tr("Detach"));
{
int aId = theAction->data().toInt();
FeaturePtr aLine = myCoinsideLines.at(aId);
- std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(mySelectedFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ std::shared_ptr<GeomAPI_Pnt2d> aOrig = PartSet_Tools::getPoint(mySelectedFeature,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A());
if (aOrig.get() == NULL)
- aOrig = getPoint(mySelectedFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ aOrig = PartSet_Tools::getPoint(mySelectedFeature,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
gp_Pnt aOr = aOrig->impl<gp_Pnt>();
const std::set<AttributePtr>& aRefsList = aLine->data()->refsToMe();
std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- std::shared_ptr<GeomAPI_Pnt2d> aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = PartSet_Tools::getPoint(aConstrFeature,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A());
if (aPnt.get() == NULL)
- aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ aPnt = PartSet_Tools::getPoint(aConstrFeature,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
if (aPnt.get() == NULL)
return;
gp_Pnt aP = aPnt->impl<gp_Pnt>();
if (aOrig->isEqual(aPnt)) {
aToDelFeatures.append(aConstrFeature);
} else {
- aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ aPnt = PartSet_Tools::getPoint(aConstrFeature,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
aP = aPnt->impl<gp_Pnt>();
if (aOrig->isEqual(aPnt)) {
aToDelFeatures.append(aConstrFeature);
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
+ aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
+
aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
return aShape;
}
+std::shared_ptr<GeomAPI_Pnt2d> PartSet_Tools::getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::string& theAttribute)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+ if (!theFeature->data())
+ return std::shared_ptr<GeomAPI_Pnt2d>();
+
+ FeaturePtr aFeature;
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
+ if (anAttr)
+ aFeature = ModelAPI_Feature::feature(anAttr->object());
+
+ if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+
+ else if (anAttr->attr()) {
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
+ if (aPointAttr.get() != NULL)
+ return aPointAttr->pnt();
+ return std::shared_ptr<GeomAPI_Pnt2d>();
+}
+
+void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
+ std::string theAttr)
+{
+ AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
+ FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object());
+ if (!theList.contains(aObj)) {
+ std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
+ if (aOrig.get() == NULL)
+ return;
+ theList.append(aObj);
+ const std::set<AttributePtr>& aRefsList = aObj->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = getPoint(aConstrFeature, theAttr);
+ if (aPnt.get() && aOrig->isEqual(aPnt)) {
+ findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ }
+ }
+ }
+ }
+}
+
AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
const TopoDS_Shape theShape,
FeaturePtr theSketch)
static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
ModuleBase_IWorkshop* theWorkshop);
+ /* Returns point of coincidence feature
+ * \param theFeature the coincidence feature
+ * \param theAttribute the attribute name
+ */
+ static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::string& theAttribute);
+
+ /**
+ * Returns list of features connected in a councedence feature point
+ * \param theStartCoin the coincidence feature
+ * \param theList a list which collects lines features
+ * \param theAttr the attribute name
+ */
+ static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
+ std::string theAttr);
+
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
#include "PartSet_Validators.h"
+#include "PartSet_Tools.h"
+
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <BRep_Tool.hxx>
#include <ModelAPI_Session.h>
#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Arc.h>
#include <GeomAPI_Edge.h>
#include <list>
return false;
}
+bool PartSet_CoincidentAttr::isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+ // there is a check whether the feature contains a point and a linear edge or two point values
+ std::string aParamA = theArguments.front();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (!aRefAttr)
+ return false;
+
+ QList<FeaturePtr> aCoinsideLines;
+
+ bool isObject = aRefAttr->isObject();
+ ObjectPtr anObject = aRefAttr->object();
+ if (isObject && anObject) {
+ FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
+ AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
+ ObjectPtr aOtherObject = aOtherAttr->object();
+ // if the other attribute is not filled still, the result is true
+ if (!aOtherObject.get())
+ return true;
+ FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
+
+ // check that both have coincidence
+ FeaturePtr aConstrFeature;
+ std::set<FeaturePtr> aCoinList;
+ const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefsList = aRefFea->data()->refsToMe();
+ std::set<std::shared_ptr<ModelAPI_Attribute>>::const_iterator aIt;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+ AttributePtr aAR = aRAttr->attr();
+ if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc
+ aCoinList.insert(aConstrFeature);
+ PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ }
+ }
+ // if there is no coincidence then it is not valid
+ if (aCoinList.size() == 0)
+ return false;
+
+ QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(), aLast = aCoinsideLines.end();
+ bool aValid = false;
+ for (; anIt != aLast && !aValid; anIt++) {
+ aValid = *anIt == aOtherFea;
+ }
+ if (aValid)
+ return true;
+ }
+ return false;
+}
+
const std::list<std::string>& theArguments) const;
};
+/**\class PartSet_CoincidentAttr
+ * \ingroup Validators
+ * \brief Validator to check whether there is a coincident constraint between
+ * the attribute and attribute of argument.
+ */
+class PartSet_CoincidentAttr : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
#endif
new SketchPlugin_ExternalValidator);
aFactory->registerValidator("SketchPlugin_TangentAttr",
new SketchPlugin_TangentAttrValidator);
- aFactory->registerValidator("SketchPlugin_CoincidentAttr",
- new SketchPlugin_CoincidentAttr);
aFactory->registerValidator("SketchPlugin_NotFixed",
new SketchPlugin_NotFixedValidator);
aFactory->registerValidator("SketchPlugin_EqualAttr",
return false;
}
-bool SketchPlugin_CoincidentAttr::isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
-{
- // there is a check whether the feature contains a point and a linear edge or two point values
- std::string aParamA = theArguments.front();
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (!aRefAttr)
- return false;
-
- bool isObject = aRefAttr->isObject();
- ObjectPtr anObject = aRefAttr->object();
- if (isObject && anObject) {
- FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
- AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
- ObjectPtr aOtherObject = aOtherAttr->object();
- // if the other attribute is not filled still, the result is true
- if (!aOtherObject.get())
- return true;
- FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
-
- // check that both have coincidence
- FeaturePtr aConstrFeature;
- std::set<FeaturePtr> aCoinList;
- const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefsList = aRefFea->data()->refsToMe();
- std::set<std::shared_ptr<ModelAPI_Attribute>>::const_iterator aIt;
- for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
- AttributePtr aAR = aRAttr->attr();
- if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc
- aCoinList.insert(aConstrFeature);
- }
- }
- // if there is no coincidence then it is not valid
- if (aCoinList.size() == 0)
- return false;
-
- // find that coincedence is the same
- const std::set<std::shared_ptr<ModelAPI_Attribute>>& aOtherList = aOtherFea->data()->refsToMe();
- std::set<FeaturePtr>::const_iterator aCoinsIt;
- for (aIt = aOtherList.cbegin(); aIt != aOtherList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- aCoinsIt = aCoinList.find(aConstrFeature);
- if (aCoinsIt != aCoinList.end()) {
- AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
- AttributePtr aAR = aRAttr->attr();
- if (aAR->id() != SketchPlugin_Arc::CENTER_ID())
- return true;
- }
- }
- }
- return false;
-}
-
bool SketchPlugin_TangentAttrValidator::isValid(
const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
{
const std::list<std::string>& theArguments) const;
};
-/**\class SketchPlugin_CoincidentAttr
- * \ingroup Validators
- * \brief Validator to check whether there is a coincident constraint between
- * the attribute and attribute of argument.
- */
-class SketchPlugin_CoincidentAttr : public ModelAPI_AttributeValidator
-{
- public:
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-};
-
/**\class SketchPlugin_TangentAttrValidator
* \ingroup Validators
* \brief Validator for the tangent constraint input.
<feature id="SketchConstraintTangent" title="Tangent" tooltip="Create constraint defining tangency of two objects" icon=":icons/tangent.png">
<sketch_shape_selector id="ConstraintEntityA"
label="First object" tooltip="Select line or arc" shape_types="edge">
- <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityB"/>
+ <validator id="PartSet_CoincidentAttr" parameters="ConstraintEntityB"/>
<validator id="PartSet_DifferentObjects"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityB"
label="Second object" tooltip="Select line or arc" shape_types="edge">
- <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityA"/>
+ <validator id="PartSet_CoincidentAttr" parameters="ConstraintEntityA"/>
<validator id="SketchPlugin_TangentAttr" parameters="ConstraintEntityA"/>
<validator id="PartSet_DifferentObjects"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityA"
label="First object" tooltip="Select line or arc" shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
- <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityB"/>
+ <validator id="PartSet_CoincidentAttr" parameters="ConstraintEntityB"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityB"
label="Second object" tooltip="Select line or arc" shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
- <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityA"/>
+ <validator id="PartSet_CoincidentAttr" parameters="ConstraintEntityA"/>
</sketch_shape_selector>
<doublevalue label="Value" tooltip="Fillet radius" id="ConstraintValue" min="0" default="1" use_reset="false">