if (theObject.get() != NULL) {
aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
myRef->Remove(aData->label().Father());
+ REMOVE_BACK_REF(theObject);
}
else { // in case of empty object remove, the first empty object is removed from the list
std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
myIsInitialized = myRef.isInitialized();
}
+void Model_AttributeSelection::setID(const std::string theID)
+{
+ myRef.setID(theID);
+ ModelAPI_AttributeSelection::setID(theID);
+}
+
ResultPtr Model_AttributeSelection::context() {
return std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
}
/// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
TDF_LabelMap& scope();
+ /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
+ MODELAPI_EXPORT virtual void setID(const std::string theID);
+
friend class Model_Data;
friend class Model_AttributeSelectionList;
};
if (owner()) {
aNewAttr->setObject(owner());
}
+ aNewAttr->setID(id());
mySize->Set(aNewTag);
aNewAttr->setValue(theContext, theSubShape);
owner()->data()->sendAttributeUpdated(this);
myDoc->Undo();
myDoc->ClearRedos();
}
- // references may be changed because they are set in attributes on the fly
- synchronizeFeatures(true, true, isRoot());
- // abort for all subs
+ // abort for all subs, flushes will be later, in the end of root abort
const std::set<std::string> aSubs = subDocuments(true);
std::set<std::string>::iterator aSubIter = aSubs.begin();
for (; aSubIter != aSubs.end(); aSubIter++)
subDoc(*aSubIter)->abortOperation();
+ // references may be changed because they are set in attributes on the fly
+ synchronizeFeatures(true, true, isRoot());
}
bool Model_Document::isOperation() const
MODELAPI_EXPORT ModelAPI_Attribute();
/// Sets the ID of the attribute in Data (called from Data)
- MODELAPI_EXPORT void setID(const std::string theID);
+ MODELAPI_EXPORT virtual void setID(const std::string theID);
friend class Model_Data;
};
Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
{
ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
- ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
+ if (!anOperation)
+ return true;
+ ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
(anActiveWidget);
#include "PartSet_MenuMgr.h"
#include "PartSet_Module.h"
#include "PartSet_SketcherMgr.h"
+#include "PartSet_Tools.h"
#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Sketch.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_Operation.h>
#include <QAction>
#include <QMenu>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+
PartSet_MenuMgr::PartSet_MenuMgr(PartSet_Module* theModule)
: QObject(theModule), myModule(theModule), myPrevId(-1)
{
if (!theList.contains(aObj)) {
std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
theList.append(aObj);
- const std::set<AttributePtr> aRefsList = aObj->data()->refsToMe();
+ 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);
myCoinsideLines.clear();
ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
- QObjectPtrList aObjects = aSelection->selectedPresentations();
- if (aObjects.size() > 0) {
+
+ NCollection_List<TopoDS_Shape> aShapeList;
+ std::list<ObjectPtr> aObjectsList;
+ aSelection->selectedShapes(aShapeList, aObjectsList);
+ bool aIsDetach = false;
+
+ if (aShapeList.Extent() == 1) {
+ TopoDS_Shape aShape = aShapeList.First();
+ if (aShape.ShapeType() == TopAbs_VERTEX) {
+ // Find 2d coordinates
+ FeaturePtr aSketchFea = myModule->sketchMgr()->activeSketch();
+ std::shared_ptr<SketchPlugin_Sketch> aSketch =
+ std::dynamic_pointer_cast<SketchPlugin_Sketch>(aSketchFea);
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt3d(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+ std::shared_ptr<GeomAPI_Pnt2d> aSelPnt = aSketch->to2D(aPnt3d);
+
+ // Find coincident in these coordinates
+ ObjectPtr aObj = aObjectsList.front();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+ const std::set<AttributePtr>& aRefsList = aFeature->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ FeaturePtr aCoincident;
+ 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> a2dPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ if (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());
+ if (myCoinsideLines.size() > 0) {
+ aIsDetach = true;
+ QMenu* aSubMenu = theMenu->addMenu(tr("Detach"));
+ QAction* aAction;
+ int i = 0;
+ foreach (FeaturePtr aCoins, myCoinsideLines) {
+ aAction = aSubMenu->addAction(aCoins->data()->name().c_str());
+ aAction->setData(QVariant(i));
+ i++;
+ }
+ connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*)));
+ connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide()));
+ connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*)));
+ }
+ }
+ }
+ }
+ if ((!aIsDetach) && (aObjectsList.size() > 0)) {
bool hasFeature = false;
FeaturePtr aFeature;
- foreach(ObjectPtr aObject, aObjects) {
+ std::list<ObjectPtr>::const_iterator aIt;
+ ObjectPtr aObject;
+ for (aIt = aObjectsList.cbegin(); aIt != aObjectsList.cend(); ++aIt) {
+ aObject = (*aIt);
aFeature = ModelAPI_Feature::feature(aObject);
if (aFeature.get() != NULL) {
hasFeature = true;
}
}
- if (hasFeature) {
- bool aIsDetach = false;
- if (aObjects.size() == 1) {
- if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- /// If the feature is coincident then we use Detach command instead Delete
- mySelectedFeature = aFeature;
- findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_A());
- findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_B());
- if (myCoinsideLines.size() > 0) {
- aIsDetach = true;
- QMenu* aSubMenu = theMenu->addMenu(tr("Detach"));
- QAction* aAction;
- int i = 0;
- foreach (FeaturePtr aCoins, myCoinsideLines) {
- aAction = aSubMenu->addAction(aCoins->data()->name().c_str());
- aAction->setData(QVariant(i));
- i++;
- }
- connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*)));
- connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide()));
- connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*)));
- }
- }
- }
- if (!aIsDetach)
+ if (hasFeature)
theMenu->addAction(theStdActions["DELETE_CMD"]);
- }
}
bool isAuxiliary;
if (canSetAuxiliary(isAuxiliary)) {
//Registering of validators
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
- aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
- aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
- aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
- aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
- aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
+ aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
+ aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
+ aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
+ aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
+ aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
+ aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
+ aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
+ aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
+ aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
+ aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
+
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
void PartSet_SketcherMgr::onEnterViewPort()
{
- if (!isNestedCreateOperation(getCurrentOperation()))
- return;
// 1. if the mouse over window, update the next flag. Do not perform update visibility of
// created feature because it should be done in onMouseMove(). Some widgets watch
// the mouse move and use the cursor position to update own values. If the presentaion is
// redisplayed before this update, the feature presentation jumps from reset value to current.
myIsMouseOverWindow = true;
myIsPropertyPanelValueChanged = false;
+
+ if (!isNestedCreateOperation(getCurrentOperation()))
+ return;
}
void PartSet_SketcherMgr::onLeaveViewPort()
{
+ myIsMouseOverViewProcessed = false;
+ myIsMouseOverWindow = false;
+ myIsPropertyPanelValueChanged = false;
+
if (!isNestedCreateOperation(getCurrentOperation()))
return;
// the method should be performed if the popup menu is called,
if (myIsPopupMenuActive)
return;
- myIsMouseOverViewProcessed = false;
- myIsMouseOverWindow = false;
-
// 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
// hides the presentation of the current operation feature
- myIsPropertyPanelValueChanged = false;
+ //myIsPropertyPanelValueChanged = false;
// the feature is to be erased here, but it is correct to call canDisplayObject because
// there can be additional check (e.g. editor widget in distance constraint)
FeaturePtr aFeature = getCurrentOperation()->feature();
void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
{
myIsMouseOverWindow = false;
+ myIsConstraintsShown = true;
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
aDisplayer->updateViewer();
}
-void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* )
+void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
{
+ if (constraintsIdList().contains(theOperation->id())) {
+ // Show constraints if a constraint was created
+ onShowConstraintsToggle(true);
+ }
connectToPropertyPanel(true);
}
if (isNestedCreateOperation(theOperation))
visualizeFeature(theOperation, true);
- if (constraintsIdList().contains(theOperation->id())) {
- // Show constraints if a constraint was created
- onShowConstraintsToggle(true);
- }
}
bool PartSet_SketcherMgr::canUndo() const
// Create line
aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID());
} else if (aAdaptor.GetType() == GeomAbs_Circle) {
- if (aAdaptor.IsClosed()) {
- // Create circle
- aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
- } else {
+ std::shared_ptr<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge);
+ anEdge->setImpl(new TopoDS_Shape(theShape));
+ if (anEdge->isArc()) {
// Create arc
aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
}
+ else {
+ // Create circle
+ aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
+ }
}
if (aMyFeature) {
DataPtr aData = aMyFeature->data();
#include <ModelAPI_Session.h>
#include <SketchPlugin_Sketch.h>
+#include <GeomAPI_Edge.h>
#include <list>
#ifdef _DEBUG
return aCount;
}
-bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection) const
{
int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
}
-bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection) const
{
int aCount = shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 2);
+ return (aCount == 1);
}
-bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSelection) const
{
int aCount = shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
}
-bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelection) const
{
int aCount = shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
}
-bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection) const
{
QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
ModuleBase_ViewerPrs aPrs;
}
}
}
- return (aCount > 0) && (aCount < 2);
+ return (aCount == 1);
}
-bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+ return (aList.count() == 1);
+}
+
+
+bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ int aCount = shapesNbPoints(theSelection);
+ return (aCount > 0) && (aCount < 3);
+}
+
+bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ int aCount = shapesNbLines(theSelection);
+ return (aCount == 1);
+}
+
+bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection) const
{
int aCount = shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 2);
+ return (aCount > 0) && (aCount < 3);
+}
+
+bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+ if ((aList.size() == 0) || (aList.size() > 2))
+ return false;
+
+ ModuleBase_ViewerPrs aPrs = aList.first();
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (aShape.IsNull())
+ return false;
+
+ if (aShape.ShapeType() != TopAbs_EDGE)
+ return false;
+
+ std::shared_ptr<GeomAPI_Shape> aShapePtr(new GeomAPI_Shape);
+ aShapePtr->setImpl(new TopoDS_Shape(aShape));
+ GeomAPI_Edge aEdge1(aShapePtr);
+
+ if (aEdge1.isLine() || aEdge1.isArc()) {
+ if (aList.size() == 2) {
+ // Check second selection
+ aPrs = aList.last();
+ const TopoDS_Shape& aShape2 = aPrs.shape();
+ if (aShape2.IsNull())
+ return false;
+
+ if (aShape2.ShapeType() != TopAbs_EDGE)
+ return false;
+
+ std::shared_ptr<GeomAPI_Shape> aShapePtr2(new GeomAPI_Shape);
+ aShapePtr2->setImpl(new TopoDS_Shape(aShape2));
+ GeomAPI_Edge aEdge2(aShapePtr2);
+ if (aEdge1.isLine() && aEdge2.isArc())
+ return true;
+ else if (aEdge1.isArc() && aEdge2.isLine())
+ return true;
+ else
+ return false;
+ } else
+ return true;
+ }
+ return false;
}
+
bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
{
//! \ingroup Validators
//! A class to validate a selection for Distance constraint operation
-class PartSet_DistanceValidator : public ModuleBase_SelectionValidator
+class PartSet_DistanceSelection : public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
//! \ingroup Validators
//! A class to validate a selection for Length constraint operation
-class PartSet_LengthValidator : public ModuleBase_SelectionValidator
+class PartSet_LengthSelection : public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
//! \ingroup Validators
//! A class to validate a selection for Perpendicular constraint operation
-class PartSet_PerpendicularValidator : public ModuleBase_SelectionValidator
+class PartSet_PerpendicularSelection : public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
//! \ingroup Validators
-//! A class to validate a selection for Perpendicular constraint operation
-class PartSet_ParallelValidator : public ModuleBase_SelectionValidator
+//! A class to validate a selection for Parallel constraint operation
+class PartSet_ParallelSelection : public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
//! \ingroup Validators
-//! A class to validate a selection for Perpendicular constraint operation
-class PartSet_RadiusValidator : public ModuleBase_SelectionValidator
+//! A class to validate a selection for Radius constraint operation
+class PartSet_RadiusSelection : public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
//! \ingroup Validators
-//! A class to validate a selection for Perpendicular constraint operation
-class PartSet_RigidValidator : public ModuleBase_SelectionValidator
+//! A class to validate a selection for Rigid constraint operation
+class PartSet_RigidSelection : public ModuleBase_SelectionValidator
+{
+ public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+
+//! \ingroup Validators
+//! A class to validate a selection for coincedence constraint operation
+class PartSet_CoincidentSelection : public ModuleBase_SelectionValidator
+{
+ public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+//! \ingroup Validators
+//! A class to validate a selection for Horizontal and Vertical constraints operation
+class PartSet_HVDirSelection : public ModuleBase_SelectionValidator
+{
+ public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+//! \ingroup Validators
+//! A class to validate a selection for Tangential constraints operation
+class PartSet_TangentSelection : public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
+//! \ingroup Validators
+//! A class to validate a selection for Fillet constraints operation
+class PartSet_FilletSelection : public ModuleBase_SelectionValidator
+{
+ public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+////////////// Attribute validators ////////////////
+
+
/**
* \ingroup Validators
* A validator which checks that objects selected for feature attributes are different (not the same)
{
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
if (aModule->isMouseOverWindow())
- return ModuleBase_WidgetDoubleValue::focusTo();
+ return ModuleBase_WidgetEditor::focusTo();
else {
- ModuleBase_WidgetEditor::focusTo();
+ return ModuleBase_WidgetDoubleValue::focusTo();
}
}
//XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->closeLocalContexts();
erasePreviewPlanes();
+ activateFilters(myWorkshop->module()->workshop(), false);
}
void PartSet_WidgetSketchLabel::erasePreviewPlanes()
<file>icons/tangent.png</file>
<file>icons/fillet.png</file>
<file>icons/coincedence.png</file>
+ <file>icons/mirror.png</file>
</qresource>
</RCC>
return thePrevious;
AISObjectPtr anAIS = thePrevious;
- /// TODO: Equal constraint presentation should be put here
+ if (!anAIS) {
+ anAIS = SketcherPrs_Factory::mirrorConstraint(this, sketch()->coordinatePlane());
+ }
return anAIS;
}
new SketchPlugin_NotFixedValidator);
aFactory->registerValidator("SketchPlugin_EqualAttr",
new SketchPlugin_EqualAttrValidator);
+ aFactory->registerValidator("SketchPlugin_MirrorAttr",
+ new SketchPlugin_MirrorAttrValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
#include <GeomAPI_AISObject.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_PlanarEdges.h>
-#include <GeomAPI_XYZ.h>
-#include <GeomDataAPI_Dir.h>
-#include <GeomDataAPI_Point.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <ModelAPI_AttributeRefList.h>
return false;
}
-std::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
-{
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
-
- std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
- ->added(aY->xyz()->multiplied(theY));
-
- return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
-}
-
-std::shared_ptr<GeomAPI_Pnt2d> SketchPlugin_Sketch::to2D(
- const std::shared_ptr<GeomAPI_Pnt>& thePnt)
-{
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
- return thePnt->to2D(aC->pnt(), aX->dir(), aY);
-}
-
-
-bool SketchPlugin_Sketch::isPlaneSet()
-{
- std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
- return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
-}
-
-std::shared_ptr<GeomAPI_Pln> SketchPlugin_Sketch::plane()
-{
- std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
- if (!anOrigin || !aNorm)
- return std::shared_ptr<GeomAPI_Pln>();
-
- return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
-}
-
-std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::coordinatePlane() const
-{
- DataPtr aData = data();
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-
- return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
-}
void SketchPlugin_Sketch::erase()
{
#include <GeomAPI_Pln.h>
#include <GeomAPI_IPresentable.h>
#include <GeomAPI_Ax3.h>
+#include <GeomAPI_XYZ.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <list>
#define YZ_PLANE_COLOR "#ff0000"
}
/// Converts a 2D sketch space point into point in 3D space
- SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY);
+ /// \param theX an X coordinate
+ /// \param theY an Y coordinate
+ std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY) const
+ {
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ data()->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(DIRX_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+
+ std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
+ ->added(aY->xyz()->multiplied(theY));
+
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+ }
+
+ /// Returns the point projected into the sketch plane
+ /// \param thePnt a source 3d point
+ std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt) const
+ {
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ data()->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(DIRX_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+ return thePnt->to2D(aC->pnt(), aX->dir(), aY);
+ }
/// Returns true if this feature must be displayed in the history (top level of Part tree)
SKETCHPLUGIN_EXPORT virtual bool isInHistory()
SketchPlugin_Sketch();
/// Returns the basis plane for the sketch
- std::shared_ptr<GeomAPI_Pln> plane();
+ std::shared_ptr<GeomAPI_Pln> plane() const
+ {
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ data()->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
- SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const;
+ if (!anOrigin || !aNorm)
+ return std::shared_ptr<GeomAPI_Pln>();
+
+ return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
+ }
+
+ /// Returns currently defined plane as an object of Ax3
+ std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const
+ {
+ DataPtr aData = data();
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(DIRX_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(NORM_ID()));
+
+ return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
+ }
+
+ /// Checks whether the plane is set in the sketch.
+ /// \returns the boolean state
+ bool isPlaneSet() const
+ {
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
+
+ return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+ }
- //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
/// removes also all sub-sketch elements
SKETCHPLUGIN_EXPORT virtual void erase();
/// Construction result is allways recomuted on the fly
SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
- /// 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(const std::string& theID);
-protected:
- /// Checks whether the plane is set in the sketch.
- /// \returns the boolean state
- bool isPlaneSet();
};
#endif
#include <ModelAPI_Validator.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Session.h>
#include <GeomValidators_Edge.h>
return true;
}
+bool SketchPlugin_MirrorAttrValidator::isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeSelectionListPtr aSelAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if (!aSelAttr)
+ return false;
+
+ AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+ aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
+ std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
+
+ for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aSelect = aSelAttr->value(anInd);
+ std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
+ for (; aMirIter != aMirroredObjects.end(); aMirIter++)
+ if (aSelect->context() == *aMirIter)
+ return false;
+ }
+ return true;
+}
+
const std::list<std::string>& theArguments) const;
};
+/**\class SketchPlugin_MirrorAttrValidator
+ * \ingroup Validators
+ * \brief Validator for the mirror constraint input.
+ *
+ * It checks that attributes of the Mirror constraint are correct.
+ */
+class SketchPlugin_MirrorAttrValidator : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute (not used)
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
#endif
<validator id="GeomValidators_Positive"/>
</doublevalue_editor>
- <validator id="PartSet_DistanceValidator"/>
+ <validator id="PartSet_DistanceSelection"/>
</feature>
<!-- SketchConstraintLength -->
<doublevalue_editor label="Value" tooltip="Length" id="ConstraintValue" default="computed">
<validator id="GeomValidators_Positive"/>
</doublevalue_editor>
- <validator id="PartSet_LengthValidator"/>
+ <validator id="PartSet_LengthSelection"/>
</feature>
<!-- SketchConstraintRadius -->
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Radius" id="ConstraintValue" default="computed"/>
- <validator id="PartSet_RadiusValidator"/>
+ <validator id="PartSet_RadiusSelection"/>
</feature>
<!-- SketchConstraintParallel -->
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
</sketch_constraint_shape_selector>
- <validator id="PartSet_ParallelValidator"/>
+ <validator id="PartSet_ParallelSelection"/>
</feature>
<!-- SketchConstraintPerpendicular -->
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
<validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
- <validator id="PartSet_PerpendicularValidator"/>
+ <validator id="PartSet_PerpendicularSelection"/>
</feature>
<!-- SketchConstraintCoincedence -->
<sketch_shape_selector id="ConstraintEntityB" label="Second point" tooltip="Select a second point" shape_types="vertex">
<validator id="PartSet_DifferentObjects"/>
</sketch_shape_selector>
+ <validator id="PartSet_CoincidentSelection"/>
</feature>
<!-- SketchConstraintRigid -->
<validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
<validator id="SketchPlugin_NotFixed"/>
</shape_selector>
- <validator id="PartSet_RigidValidator"/>
+ <validator id="PartSet_RigidSelection"/>
</feature>
<!-- SketchConstraintHorizontal -->
label="Line" tooltip="Select a line" shape_types="edge">
<validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
+ <validator id="PartSet_HVDirSelection"/>
</feature>
<!-- SketchConstraintVertical -->
label="Line" tooltip="Select a line" shape_types="edge">
<validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
+ <validator id="PartSet_HVDirSelection"/>
</feature>
<!-- SketchConstraintEqual -->
<sketch_constraint_shape_selector id="ConstraintEntityB"
label="Last object" tooltip="Select line or arc" shape_types="edge">
<validator id="SketchPlugin_TangentAttr" parameters="ConstraintEntityA"/>
+ <validator id="PartSet_DifferentObjects"/>
</sketch_constraint_shape_selector>
+ <validator id="PartSet_TangentSelection"/>
</feature>
- <!-- SketchConstraintMirror -->
- <feature
- id="SketchConstraintMirror"
- title="Mirror"
- tooltip="Create constraint, mirroring group of objects">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
- label="Mirror line" tooltip="Select mirror line" shape_types="edge">
- <validator id="GeomValidators_Edge" parameters="line"/>
- </sketch_constraint_shape_selector>
- <multi_selector id="ConstraintMirrorList"
- label="List of objects"
- tooltip="Select list of mirroring objects"
- type_choice="Edges">
- </multi_selector>
- </feature>
+
</group>
<group id="Edit">
<doublevalue_editor label="Value" tooltip="Fillet radius" id="ConstraintValue" min="0">
<validator id="GeomValidators_Positive"/>
</doublevalue_editor>
+ <validator id="PartSet_FilletSelection"/>
+ </feature>
+
+ <!-- SketchConstraintMirror -->
+ <feature
+ id="SketchConstraintMirror"
+ title="Mirror" icon=":icons/mirror.png"
+ tooltip="Create constraint, mirroring group of objects">
+ <sketch_constraint_shape_selector id="ConstraintEntityA"
+ label="Mirror line" tooltip="Select mirror line" shape_types="edge">
+ <validator id="GeomValidators_Edge" parameters="line"/>
+ </sketch_constraint_shape_selector>
+ <multi_selector id="ConstraintMirrorList"
+ label="List of objects"
+ tooltip="Select list of mirroring objects"
+ type_choice="Edges">
+ <validator id="SketchPlugin_MirrorAttr" />
+ </multi_selector>
</feature>
</group>
</workbench>
Slvs_hEntity SketchSolver_Constraint::changeEntity(AttributePtr theEntity, int& theType)
{
Slvs_hEntity aResult = SLVS_E_UNKNOWN;
- if (!isInitialized(theEntity))
+ if (!theEntity || !isInitialized(theEntity))
return SLVS_E_UNKNOWN;
// If the entity is already in the group, try to find it
Slvs_hEntity SketchSolver_Constraint::changeEntity(FeaturePtr theEntity, int& theType)
{
Slvs_hEntity aResult = SLVS_E_UNKNOWN;
- if (!theEntity->data() || !theEntity->data()->isValid())
+ if (!theEntity || !theEntity->data() || !theEntity->data()->isValid())
return SLVS_E_UNKNOWN;
// If the entity is already in the group, try to find it
std::map<FeaturePtr, Slvs_hEntity>::const_iterator anEntIter = myFeatureMap.find(theEntity);
}
anExtraIt++;
}
- return isFullyRemoved;
+ return mySlvsConstraints.empty();
}
myFeatureMap[myBaseFeature] = anEntityID;
}
+ if (anEntityID == SLVS_E_UNKNOWN) {
+ myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
+ return;
+ }
+
// Check the entity is complex
Slvs_Entity anEntity = myStorage->getEntity(anEntityID);
if (anEntity.point[0] != SLVS_E_UNKNOWN) {
while (aFeatIter != myFeatures.end()) {
aCIter = aFeatIter->second.find(theConstraint);
if (aCIter != aFeatIter->second.end()) {
- aFeatIter->second.erase(aCIter);
- if (aFeatIter->second.empty()) {
- MapFeatureConstraint::iterator aTmpIter = aFeatIter; // stores iterator for the next element, while the current is deleting
- aTmpIter++;
- myFeatures.erase(aFeatIter);
- aFeatIter = aTmpIter;
- continue;
- }
+ FeaturePtr aFeature = aFeatIter->first;
+ aFeatIter++;
+ removeFeature(aFeature, theConstraint);
+ continue;
}
aFeatIter++;
}
void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature)
{
MapFeatureConstraint::iterator aFeatIter = myFeatures.find(theFeature);
- if (aFeatIter != myFeatures.end())
+ if (aFeatIter == myFeatures.end())
return; // no such feature
std::set<ConstraintPtr> aConstraints = aFeatIter->second;
void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature, ConstraintPtr theConstraint)
{
MapFeatureConstraint::iterator aFeatIter = myFeatures.find(theFeature);
- if (aFeatIter != myFeatures.end())
+ if (aFeatIter == myFeatures.end())
return; // no such feature
- std::list<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());
- std::list<AttributePtr>::iterator anIter = anAttributes.begin();
- for (; anIter != anAttributes.end(); anIter++) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
- if (aRefAttr) {
- if (!aRefAttr->isObject())
- removeAttribute(aRefAttr->attr(), theFeature);
- continue;
+ if (theFeature->data()) {
+ std::list<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());
+ std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+ for (; anIter != anAttributes.end(); anIter++) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
+ if (aRefAttr) {
+ if (!aRefAttr->isObject())
+ removeAttribute(aRefAttr->attr(), theFeature);
+ continue;
+ }
+ removeAttribute(*anIter, theFeature);
+ }
+ } else {
+ // iterate on attributes to find items refered to theFeature
+ MapAttributeFeature::iterator anIter = myAttributes.begin();
+ while (anIter != myAttributes.end()) {
+ if (anIter->second.find(theFeature) != anIter->second.end()) {
+ anIter->second.erase(theFeature);
+ if (anIter->second.empty()) {
+ MapAttributeFeature::iterator aDeadIter = anIter++;
+ myAttributes.erase(aDeadIter);
+ continue;
+ }
+ }
+ anIter++;
}
- removeAttribute(*anIter, theFeature);
}
aFeatIter->second.erase(theConstraint);
void SketchSolver_FeatureStorage::removeAttribute(AttributePtr theAttribute, FeaturePtr theFeature)
{
MapAttributeFeature::iterator anAttrIter = myAttributes.find(theAttribute);
- if (anAttrIter != myAttributes.end())
+ if (anAttrIter == myAttributes.end())
return; // no such attribute
anAttrIter->second.erase(theFeature);
anUnusedConstraints.push_back(*anIter);
}
- std::vector<SketchSolver_Group*>::iterator aCutsIter;
+ // Check the unused constraints once again, because they may become interacted with new storage since adding constraints
std::vector<ConstraintPtr>::iterator aUnuseIt = anUnusedConstraints.begin();
+ while (aUnuseIt != anUnusedConstraints.end()) {
+ if (aNewFeatStorage->isInteract(*aUnuseIt)) {
+ size_t aShift = aUnuseIt - anUnusedConstraints.begin();
+ anUnusedConstraints.erase(aUnuseIt);
+ aUnuseIt = anUnusedConstraints.begin() + aShift;
+ continue;
+ }
+ aUnuseIt++;
+ }
+
+ std::vector<SketchSolver_Group*>::iterator aCutsIter;
+ aUnuseIt = anUnusedConstraints.begin();
for ( ; aUnuseIt != anUnusedConstraints.end(); aUnuseIt++) {
// Remove unused constraints
removeConstraint(*aUnuseIt);
if (anEntIter->distance == theEntityID)
return false;
}
+ std::set<Slvs_hEntity> anEntAndSubs;
+ anEntAndSubs.insert(theEntityID);
+ for (int i = 0; i < 4; i++)
+ if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
+ anEntAndSubs.insert(myEntities[aPos].point[i]);
+
std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
for (; aConstrIter != myConstraints.end(); aConstrIter++) {
Slvs_hEntity anEntIDs[6] = {aConstrIter->ptA, aConstrIter->ptB,
aConstrIter->entityA, aConstrIter->entityB,
aConstrIter->entityC, aConstrIter->entityD};
for (int i = 0; i < 6; i++)
- if (anEntIDs[i] == theEntityID)
+ if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
return false;
}
// The entity is not used, remove it and its parameters
SketcherPrs_SensitivePoint.h
SketcherPrs_Radius.h
SketcherPrs_LengthDimension.h
+ SketcherPrs_Mirror.h
)
SET(PROJECT_SOURCES
SketcherPrs_SensitivePoint.cpp
SketcherPrs_Radius.cpp
SketcherPrs_LengthDimension.cpp
+ SketcherPrs_Mirror.cpp
)
SET(PROJECT_LIBRARIES
icons/vertical.png
icons/equal.png
icons/tangent.png
+ icons/mirror.png
)
ADD_DEFINITIONS(-DSKETCHERPRS_EXPORTS ${CAS_DEFINITIONS})
void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode)
{
- if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
- Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
- Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
- aSelection->Add(aSp);
- }
+// if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
+// Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
+// Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
+// aSelection->Add(aSp);
+// }
}
void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
aGroup->SetPrimitivesAspect(aLineAspect);
- addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
- addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
+ if (aLine.get() == NULL)
+ return;
+ drawShape(aLine, thePrs);
+
+ aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ aLine = SketcherPrs_Tools::getShape(aObj);
+ if (aLine.get() == NULL)
+ return;
+ drawShape(aLine, thePrs);
}
#include "SketcherPrs_Tangent.h"
#include "SketcherPrs_Radius.h"
#include "SketcherPrs_LengthDimension.h"
+#include "SketcherPrs_Mirror.h"
#define CONSTRAINT_PRS_IMPL(NAME, CLASS) \
AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent);
CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
+CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror);
AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint,
/// \param theConstraint the constraint
/// \param thePlane the current sketch plane
GET_CONSTRAINT_PRS(lengthDimensionConstraint)
+
+ /// Creates coincedent perpendicular presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ GET_CONSTRAINT_PRS(mirrorConstraint)
};
#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Mirror.cpp
+// Created: 6 April 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Mirror.h"
+#include "SketcherPrs_Tools.h"
+#include "SketcherPrs_PositionMgr.h"
+
+#include <SketchPlugin_Constraint.h>
+
+#include <ModelAPI_AttributeRefList.h>
+
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Prs3d_Root.hxx>
+
+
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
+
+static Handle(Image_AlienPixMap) MyPixMap;
+
+SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+ : SketcherPrs_SymbolPrs(theConstraint, thePlane)
+{
+}
+
+
+bool SketcherPrs_Mirror::updatePoints(double theStep) const
+{
+ ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
+ return false;
+
+ std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
+ std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
+ if (anAttrB.get() == NULL)
+ return false;
+ std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
+ if (anAttrC.get() == NULL)
+ return false;
+
+ SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
+ int aNb = anAttrB->size();
+ if (aNb != anAttrC->size())
+ return false;
+
+ myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
+ int i;
+ ObjectPtr aObj;
+ gp_Pnt aP1;
+ for (i = 0; i < aNb; i++) {
+ aObj = anAttrB->object(i);
+ aP1 = aMgr->getPosition(aObj, this, theStep);
+ myPntArray->SetVertice(i + 1, aP1);
+ }
+ for (i = 0; i < aNb; i++) {
+ aObj = anAttrC->object(i);
+ aP1 = aMgr->getPosition(aObj, this, theStep);
+ myPntArray->SetVertice(aNb + i + 1, aP1);
+ }
+ return true;
+}
+
+
+void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
+{
+ std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
+ std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
+ if (anAttrB.get() == NULL)
+ return;
+ std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
+ if (anAttrC.get() == NULL)
+ return;
+
+ SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
+ int aNb = anAttrB->size();
+ if (aNb != anAttrC->size())
+ return;
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
+
+ Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
+ aGroup->SetPrimitivesAspect(aLineAspect);
+
+ // Draw axis line
+ addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+
+ // Draw source objects
+ int i;
+ ObjectPtr aObj;
+ for (i = 0; i < aNb; i++) {
+ aObj = anAttrB->object(i);
+ std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+ if (aShape.get() != NULL)
+ drawShape(aShape, thePrs);
+ }
+ // draw mirrored objects
+ for (i = 0; i < aNb; i++) {
+ aObj = anAttrC->object(i);
+ std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+ if (aShape.get() != NULL)
+ drawShape(aShape, thePrs);
+ }
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Mirror.h
+// Created: 6 April 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Mirror_H
+#define SketcherPrs_Mirror_H
+
+#include "SketcherPrs_SymbolPrs.h"
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_Mirror, SketcherPrs_SymbolPrs)
+
+/**
+* \ingroup GUI
+* A redefinition of standard AIS Interactive Object in order to provide
+* presentation of mirror constraint
+*/
+class SketcherPrs_Mirror: public SketcherPrs_SymbolPrs
+{
+public:
+ /// Constructor
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ Standard_EXPORT SketcherPrs_Mirror(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+ DEFINE_STANDARD_RTTI(SketcherPrs_Mirror)
+protected:
+ virtual const char* iconName() const { return "mirror.png"; }
+
+ virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const;
+};
+
+#endif
\ No newline at end of file
return;
Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
- if (aShape->isEdge()) {
- Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
- aGroup->SetPrimitivesAspect(aLineAspect);
- std::shared_ptr<GeomAPI_Curve> aCurve = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
- if (aCurve->isLine()) {
- addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
- } else {
- GeomAdaptor_Curve aAdaptor(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
- StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
- }
- } else {
- // This is a point
- Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
- myDrawer->SetPointAspect(aPntAspect);
-
- std::shared_ptr<GeomAPI_Vertex> aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
- std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
- Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
- StdPrs_Point::Add(thePrs, aPoint, myDrawer);
- }
+ Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
+ aGroup->SetPrimitivesAspect(aLineAspect);
+
+ Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
+ myDrawer->SetPointAspect(aPntAspect);
+ drawShape(aShape, thePrs);
}
#include "SketcherPrs_PositionMgr.h"
#include <GeomAPI_Edge.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Curve.h>
#include <Graphic3d_ArrayOfSegments.hxx>
#include <Graphic3d_BndBox4f.hxx>
#include <AIS_InteractiveContext.hxx>
#include <V3d_Viewer.hxx>
#include <Prs3d_Root.hxx>
+#include <Geom_CartesianPoint.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <StdPrs_DeflectionCurve.hxx>
+#include <StdPrs_Point.hxx>
+#include <StdPrs_Curve.hxx>
#include <OpenGl_Element.hxx>
#include <OpenGl_GraphicDriver.hxx>
}
}
+void SketcherPrs_SymbolPrs::drawShape(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const Handle(Prs3d_Presentation)& thePrs) const
+{
+ if (theShape->isEdge()) {
+ std::shared_ptr<GeomAPI_Curve> aCurve =
+ std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(theShape));
+ if (aCurve->isLine()) {
+ GeomAdaptor_Curve aCurv(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
+ StdPrs_Curve::Add(thePrs, aCurv, myDrawer);
+ } else {
+ GeomAdaptor_Curve aAdaptor(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
+ StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
+ }
+ } else if (theShape->isVertex()) {
+ std::shared_ptr<GeomAPI_Vertex> aVertex =
+ std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(theShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
+ StdPrs_Point::Add(thePrs, aPoint, myDrawer);
+ }
+}
/// \return true in case of success
virtual bool updatePoints(double theStep) const { return true; }
+ void drawShape(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const Handle(Prs3d_Presentation)& thePrs) const;
+
+
protected:
/// Constraint feature
ModelAPI_Feature* myConstraint;
if ((aShape1.get() == NULL) || (aShape2.get() == NULL))
return;
-
- std::shared_ptr<GeomAPI_Curve> aCurve1 = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape1));
- std::shared_ptr<GeomAPI_Curve> aCurve2 = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape2));
- if (aCurve1->isCircle() && aCurve2->isLine()) {
- addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
- GeomAdaptor_Curve aAdaptor(aCurve1->impl<Handle(Geom_Curve)>(), aCurve1->startParam(), aCurve1->endParam());
- StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
- } else if (aCurve1->isLine() && aCurve2->isCircle()) {
- addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
- GeomAdaptor_Curve aAdaptor(aCurve2->impl<Handle(Geom_Curve)>(), aCurve2->startParam(), aCurve2->endParam());
- StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
- } else {
- // Both curves are arcs
- GeomAdaptor_Curve aAdaptor1(aCurve1->impl<Handle(Geom_Curve)>(), aCurve1->startParam(), aCurve1->endParam());
- StdPrs_DeflectionCurve::Add(thePrs, aAdaptor1, myDrawer);
- GeomAdaptor_Curve aAdaptor2(aCurve2->impl<Handle(Geom_Curve)>(), aCurve2->startParam(), aCurve2->endParam());
- StdPrs_DeflectionCurve::Add(thePrs, aAdaptor2, myDrawer);
- }
+ drawShape(aShape1, thePrs);
+ drawShape(aShape2, thePrs);
}
ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName)
{
std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(theAttrName));
-
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = aData->refattr(theAttrName);
return anAttr->object();
}
if (!myOperationMgr->hasOperation())
return;
- ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
- FeaturePtr anActiveFeature = anOperation->feature();
- if(!anActiveFeature.get())
+ QStringList aIdList = myOperationMgr->operationList();
+ //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
+ //FeaturePtr anActiveFeature = anOperation->feature();
+ //if(!anActiveFeature.get())
+ if (aIdList.isEmpty())
return;
- QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
+ //QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
XGUI_Selection* aSelection = myWorkshop->selector()->selection();
if (aSelection->getSelected().size() == 0) {
- foreach(QString aId, nestedCommands(aFeatureId)) {
- setActionEnabled(aId, true);
+ foreach(QString aFeatureId, aIdList) {
+ foreach(QString aId, nestedCommands(aFeatureId)) {
+ setActionEnabled(aId, true);
+ }
}
} else {
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- foreach(QString aId, nestedCommands(aFeatureId)) {
- std::list<ModelAPI_Validator*> aValidators;
- std::list<std::list<std::string> > anArguments;
- aFactory->validators(aId.toStdString(), aValidators, anArguments);
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- std::list<std::list<std::string> >::iterator aValidatorArgs = anArguments.begin();
- for (; aValidator != aValidators.end(); aValidator++, aValidatorArgs++) {
- if (!(*aValidator))
- continue;
- const ModuleBase_SelectionValidator* aSelValidator =
- dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
- if (!aSelValidator)
- continue;
- setActionEnabled(aId, aSelValidator->isValid(aSelection, *aValidatorArgs));
+ foreach(QString aFeatureId, aIdList) {
+ foreach(QString aId, nestedCommands(aFeatureId)) {
+ std::list<ModelAPI_Validator*> aValidators;
+ std::list<std::list<std::string> > anArguments;
+ aFactory->validators(aId.toStdString(), aValidators, anArguments);
+ std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+ std::list<std::list<std::string> >::iterator aValidatorArgs = anArguments.begin();
+ for (; aValidator != aValidators.end(); aValidator++, aValidatorArgs++) {
+ if (!(*aValidator))
+ continue;
+ const ModuleBase_SelectionValidator* aSelValidator =
+ dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
+ if (!aSelValidator)
+ continue;
+ setActionEnabled(aId, aSelValidator->isValid(aSelection, *aValidatorArgs));
+ }
}
}
}
theMenu->addAction(action("SHOW_CMD"));
//theMenu->addAction(action("DELETE_CMD"));
}
- if (myWorkshop->canChangeColor())
- theMenu->addAction(action("COLOR_CMD"));
if (myWorkshop->displayer()->objectsCount() > 0)
theMenu->addAction(action("HIDEALL_CMD"));
+ if (myWorkshop->canChangeColor())
+ theMenu->addAction(action("COLOR_CMD"));
}
if (!myWorkshop->isSalomeMode()) {
theMenu->addSeparator();
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
- GetFilter()->Remove(theFilter);
+ Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
+ if (aCompositeFilter->IsIn(theFilter))
+ aCompositeFilter->Remove(theFilter);
}
void XGUI_Displayer::removeFilters()