const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
BRepBuilderAPI_MakeEdge anEdgeBuilder;
- if (aStart.IsEqual(anEnd, Precision::Confusion()))
- anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
- else
- anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
+ anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
anEdgeBuilder.Build();
void ModuleBase_WidgetValidated::clearValidatedCash()
{
#ifdef DEBUG_VALID_STATE
- qDebug("clearValidatedState");
+ qDebug("clearValidatedCash");
#endif
myValidPrs.clear();
myInvalidPrs.clear();
//********************************************************************
bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
{
- return myModelWidget->isValidSelectionCustom(theValue);
-}
+ bool aValid = false;
+ if (getValidState(theValue, aValid))
+ return aValid;
-bool ModuleBase_WidgetValidator::isFilterActivated() const
-{
- bool isActivated = false;
+ aValid = myModelWidget->isValidSelectionCustom(theValue);
- Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
- ModuleBase_IViewer* aViewer = myWorkshop->viewer();
-
- return aViewer->hasSelectionFilter(aSelFilter);
+ storeValidState(theValue, aValid);
+ return aValid;
}
bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
aViewer->addSelectionFilter(aSelFilter);
else {
aViewer->removeSelectionFilter(aSelFilter);
- //clearValidatedCash();
+ clearValidatedCash();
}
return aHasSelectionFilter;
}
+
+bool ModuleBase_WidgetValidator::isFilterActivated() const
+{
+ bool isActivated = false;
+
+ Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
+ ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+
+ return aViewer->hasSelectionFilter(aSelFilter);
+}
+
+void ModuleBase_WidgetValidator::clearValidatedCash()
+{
+ myValidPrs.clear();
+ myInvalidPrs.clear();
+}
+
+bool ModuleBase_WidgetValidator::getValidState(const ModuleBase_ViewerPrsPtr& theValue, bool& theValid)
+{
+ bool aValidPrs = myValidPrs.contains(theValue);
+ bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+ if (aValidPrs)
+ theValid = true;
+ else if (anInvalidPrs)
+ theValid = false;
+
+ return aValidPrs || anInvalidPrs;
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidator::storeValidState(const ModuleBase_ViewerPrsPtr& theValue, const bool theValid)
+{
+ bool aValidPrs = myInvalidPrs.contains(theValue);
+ bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+ if (theValid) {
+ if (!aValidPrs)
+ myValidPrs.append(theValue);
+ // the commented code will be useful when the valid state of the presentation
+ // will be changable between activate/deactivate. Currently it does not happen.
+ //if (anInvalidPrs)
+ // myInvalidPrs.removeOne(theValue);
+ }
+ else { // !theValid
+ if (!anInvalidPrs)
+ myInvalidPrs.append(theValue);
+ //if (!aValidPrs)
+ // myValidPrs.removeOne(theValue);
+ }
+#ifdef DEBUG_VALID_STATE
+ qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2").arg(myValidPrs.count())
+ .arg(myInvalidPrs.count()).toStdString().c_str());
+#endif
+}
#include <ModuleBase.h>
+#include <QList>
#include <memory>
class ModuleBase_ModelWidget;
/// \return boolean value
bool isFilterActivated() const;
+ //! Clear all validated cash in the widget
+ void clearValidatedCash();
+
+ /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
+ /// \param theValue a viewer presentation
+ /// \param theValid a valid state
+ bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
+
+ /// Store the validity state of the presentation in an internal map
+ /// \param theValue a viewer presentation
+ /// \param theValid a valid state
+ void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
+
protected:
/// Reference to workshop
ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
+
+ QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; /// cash of valid selection presentations
+ QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; /// cash of invalid selection presentations
};
#endif /* ModuleBase_WidgetValidator_H_ */
#include "PartSet_WidgetPoint2d.h"
#include <PartSet_Tools.h>
#include <PartSet_Module.h>
+#include <PartSet_SketcherReetntrantMgr.h>
#include <XGUI_Tools.h>
#include <XGUI_Workshop.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Vertex.h>
+
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_Line.h>
bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
{
bool aValid = true;
- /*if (getValidState(theValue, aValid)) {
- return aValid;
- }
- aValid = isValidSelectionCustom(theValue);
- if (aValid)
- aValid = isValidSelectionForAttribute(theValue, attribute());
- storeValidState(theValue, aValid);
- */return aValid;
+ PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+ if (aModule->sketchReentranceMgr()->isInternalEditActive())
+ return true; /// when internal edit is started a new feature is created. I has not results, AIS
+
+ // workaround for feature, where there is no results
+ //if (myFeature->getKind() == "SketchRectangle")
+ // return true;
+
+ /// the selection is not possible if the current feature has no presentation for the current
+ /// attribute not in AIS not in results. If so, no object in current feature where make
+ /// coincidence, so selection is not necessary
+ std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aData->attribute(attributeID()));
+ std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
+
+ bool aFoundPoint = false;
+ GeomShapePtr anAISShape;
+ GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(myFeature);
+ if (aPrs.get()) {
+ AISObjectPtr anAIS;
+ anAIS = aPrs->getAISObject(anAIS);
+ if (anAIS.get()) {
+ anAISShape = anAIS->getShape();
+ }
+ }
+ const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = myFeature->results();
+ if (!anAISShape.get() && aResults.empty())
+ return true;
+
+ /// analysis of AIS
+ if (anAISShape.get())
+ aFoundPoint = shapeContainsPoint(anAISShape, aPoint, mySketch);
+
+ /// analysis of results
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
+ for (; aRIter != aResults.cend() && !aFoundPoint; aRIter++) {
+ ResultPtr aResult = *aRIter;
+ if (aResult.get() && aResult->shape().get()) {
+ GeomShapePtr aShape = aResult->shape();
+ aFoundPoint = shapeContainsPoint(aShape, aPoint, mySketch);
+ }
+ }
+ return aFoundPoint;
}
bool PartSet_WidgetPoint2D::resetCustom()
ModuleBase_ISelection* aSelection = myWorkshop->selection();
Handle(V3d_View) aView = theWnd->v3dView();
- // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
- NCollection_List<TopoDS_Shape> aShapes;
- std::list<ObjectPtr> aObjects;
- aSelection->selectedShapes(aShapes, aObjects);
+
+ QList<ModuleBase_ViewerPrsPtr> aList = aSelection->getSelected(ModuleBase_ISelection::Viewer);
+ ModuleBase_ViewerPrsPtr aFirstValue = aList.size() > 0 ? aList.first() : ModuleBase_ViewerPrsPtr();
+ //NCollection_List<TopoDS_Shape> aShapes;
+ //std::list<ObjectPtr> aObjects;
+ //aSelection->selectedShapes(aShapes, aObjects);
// if we have selection and use it
- if (aShapes.Extent() > 0 && useSelectedShapes()) {
- TopoDS_Shape aShape = aShapes.First();
- ObjectPtr aObject = aObjects.front();
+ //if (/*aShapes.Extent() > 0 && useSelectedShapes() &&*/ isValidSelectionCustom() {
+ if (aFirstValue.get() && isValidSelectionCustom(aFirstValue)) {
+ //TopoDS_Shape aShape = aShapes.First();
+ //ObjectPtr aObject = aObjects.front();
+
+ GeomShapePtr aGeomShape = aFirstValue->shape();
+ TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>(); /// to find axis shape
+ ObjectPtr aObject = aFirstValue->object(); /// to find owner
+
FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
bool anExternal = false;
std::shared_ptr<SketchPlugin_Feature> aSPFeature;
}
return anOrphanPoint;
}
+
+bool PartSet_WidgetPoint2D::shapeContainsPoint(const GeomShapePtr& theShape,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
+ const CompositeFeaturePtr& theSketch)
+{
+ std::shared_ptr<GeomAPI_Pnt> aPoint = PartSet_Tools::point3D(thePoint, theSketch);
+
+ bool aContainPoint = false;
+ GeomAPI_ShapeExplorer anExp(theShape, GeomAPI_Shape::VERTEX);
+ for(; anExp.more() && !aContainPoint; anExp.next()) {
+ std::shared_ptr<GeomAPI_Shape> aVertexInCompSolid = anExp.current();
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aVertexInCompSolid));
+ if (aVertex.get())
+ aContainPoint = aPoint->isEqual(aVertex->point());
+ }
+ return aContainPoint;
+}
static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
double theX, double theY);
+ /// Explode the given shape by vertices and found closed to the point vertes
+ /// \param theShape a shape to be exploded
+ /// \param thePoint a point
+ /// \return boolean value
+ static bool shapeContainsPoint(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
+ const CompositeFeaturePtr& theSketch);
+
protected:
ModuleBase_IWorkshop* myWorkshop; ///< workshop
// compute a circle point in 3D view
std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+
+ std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
if (aCenterAttr->isInitialized()) {
std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+ // make a visible point
+ std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+ aShapes.push_back(aCenterPointShape);
std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
aTypeAttr->value() == ARC_TYPE_THREE_POINTS() && aEndAttr->isInitialized())
aEndPoint = aSketch->to3D(aEndAttr->x(), aEndAttr->y());
- std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
- // make a visible point
- std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
- aShapes.push_back(aCenterPointShape);
-
std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
aCenter, aStartPoint, aEndPoint, aNormal);
if (aCircleShape)
aShapes.push_back(aCircleShape);
-
- if (!aShapes.empty()) {
- std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createShape(aCompound);
- anAIS->setWidth(3);
- return anAIS;
- }
}
}
}
+ if (!aShapes.empty()) {
+ std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+ AISObjectPtr anAIS = thePrevious;
+ if (!anAIS)
+ anAIS = AISObjectPtr(new GeomAPI_AISObject);
+ anAIS->createShape(aCompound);
+ anAIS->setWidth(3);
+ return anAIS;
+ }
}
}
return AISObjectPtr();