// return;
ObjectPtr aValue = value();
if (!myIsInitialized || aValue != theObject) {
+ myIsInitialized = true;
REMOVE_BACK_REF(aValue);
TDF_Label anObjLab;
#include <GeomAPI_Dir.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_Circ.h>
namespace ModelGeomAlgo_Point2D {
std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(ModelAPI_Feature* theFeature,
const std::string& theReferenceFeatureKind,
std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::string& theObjectFeatureKind,
- const std::string& theObjectFeatureAttribute)
+ const std::string& theObjectFeatureAttribute,
+ const bool isSkipFeatureAttributes)
{
// find by feature
+ FeaturePtr aSourceFeature = ModelAPI_Feature::feature(theObject);
+
const std::set<AttributePtr>& aRefsList = theObject->data()->refsToMe();
std::set<AttributePtr>::const_iterator aIt;
for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
if (aRefFeature->getKind() == theReferenceFeatureKind) {
std::list<AttributePtr> anAttributes =
aRefFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
- std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+ std::list<AttributePtr>::iterator anIter = anAttributes.begin(), aLast = anAttributes.end();
+ bool isSkippedAttribute = false;
+ if (isSkipFeatureAttributes) {
+ for(anIter = anAttributes.begin(); anIter != aLast && !isSkippedAttribute; anIter++) {
+ AttributeRefAttrPtr aRefAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
+ if (aRefAttribute.get() && !aRefAttribute->isObject()) {
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttribute->attr());
+ FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(aPointAttr->owner());
+ isSkippedAttribute = aSourceFeature == anAttributeFeature;
+ }
+ }
+ }
+ if (isSkippedAttribute)
+ continue;
+
// it searches the first point of AttributeRefAtt
std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
- for(; anIter != anAttributes.end() && !aPointAttr.get(); anIter++) {
+ for(anIter = anAttributes.begin(); anIter != aLast && !aPointAttr.get(); anIter++) {
AttributeRefAttrPtr aRefAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
- if (aRefAttribute.get())
+ if (aRefAttribute.get()) {
aPointAttr = getPointOfRefAttr(aRefFeature.get(), aRefAttribute->id(),
- theObjectFeatureKind, theObjectFeatureAttribute);
+ theObjectFeatureKind, theObjectFeatureAttribute);
+ }
}
if (aPointAttr.get()) {
theAttributes.insert(aPointAttr);
{
bool isInside = false;
if (theBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
- std::shared_ptr<GeomAPI_Edge> aLineEdge(new GeomAPI_Edge(theBaseShape));
- std::shared_ptr<GeomAPI_Lin> aLine = aLineEdge->line();
- theProjectedPoint = aLine->project(thePoint);
-
- std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
- theProjectedPoint->y(), theProjectedPoint->z()));
- isInside = GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape);
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theBaseShape));
+ if (anEdge->isLine()) {
+ std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
+ theProjectedPoint = aLine->project(thePoint);
+ }
+ else if (anEdge->isCircle() || anEdge->isArc()) {
+ std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
+ theProjectedPoint = aCircle->project(thePoint);
+ }
+ if (theProjectedPoint.get()) {
+ std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
+ theProjectedPoint->y(), theProjectedPoint->z()));
+ isInside = GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape);
+ }
}
return isInside;
}
#define ModelGeomAlgo_Point2D_H
#include "ModelGeomAlgo.h"
+#include "ModelAPI_Feature.h"
class ModelAPI_Feature;
class ModelAPI_Object;
/// \param theAttribute a name of AttributeRefAttr on the given feature
/// \param theObjectFeatureKind a feature kind in object of attribute that satisfies the search
/// \param theObjectFeatureAttribute a feature attribute in object that satisfies the search
+ /// \param isSkipFeatureAttributes a boolean value if coincidences to the feature attributes
/// \returns found point attribute or NULL
MODELGEOMALGO_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(
- ModelAPI_Feature* theFeature,
- const std::string& theAttribute,
- const std::string& theObjectFeatureKind = "",
- const std::string& theObjectFeatureAttribute = "");
+ ModelAPI_Feature* theFeature,
+ const std::string& theAttribute,
+ const std::string& theObjectFeatureKind = "",
+ const std::string& theObjectFeatureAttribute = "");
/// Fills container of point 2D attributes, which refer to the feature through the references
/// features with the given kind
/// \param theAttributes a container of found point 2D attributes
/// \param theObjectFeatureKind a feature kind in object of attribute that satisfies the search
/// \param theObjectFeatureAttribute a feature attribute in object that satisfies the search
+ /// \param isSkipFeatureAttributes a boolean value if coincidences to the feature attributes
+ /// should be skipped
/// \returns found point attribute or NULL
MODELGEOMALGO_EXPORT void getPointsOfReference(const std::shared_ptr<ModelAPI_Object>& theObject,
const std::string& theReferenceFeatureKind,
std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::string& theObjectFeatureKind = "",
- const std::string& theObjectFeatureAttribute = "");
+ const std::string& theObjectFeatureAttribute = "",
+ const bool isSkipFeatureAttributes = true);
/// Removes attributes which points are out of the base shape
/// \param theBaseShape a shape of check
PartSet_WidgetSubShapeSelector::PartSet_WidgetSubShapeSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData)
-: PartSet_WidgetShapeSelector(theParent, theWorkshop, theData)
+: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
{
myCurrentSubShape = std::shared_ptr<ModuleBase_ViewerPrs>(new ModuleBase_ViewerPrs());
-
- //myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
- //myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
}
PartSet_WidgetSubShapeSelector::~PartSet_WidgetSubShapeSelector()
{
+ myCashedShapes.clear();
}
//********************************************************************
void PartSet_WidgetSubShapeSelector::activateCustom()
{
- PartSet_WidgetShapeSelector::activateCustom();
+ ModuleBase_WidgetShapeSelector::activateCustom();
myWorkshop->module()->activateCustomPrs(myFeature,
ModuleBase_IModule::CustomizeHighlightedObjects, true);
//********************************************************************
void PartSet_WidgetSubShapeSelector::deactivate()
{
- PartSet_WidgetShapeSelector::deactivate();
+ ModuleBase_WidgetShapeSelector::deactivate();
myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true);
}
#include "PartSet.h"
-#include <PartSet_WidgetShapeSelector.h>
+#include <ModuleBase_WidgetShapeSelector.h>
#include <PartSet_MouseProcessor.h>
+#include <ModelAPI_CompositeFeature.h>
+
#include <QObject>
#include <set>
* by mouse move over shape in the viewer. Split of the object is performed by
* coincident points to the object. Segment between nearest coincidence is highlighted
*/
-class PARTSET_EXPORT PartSet_WidgetSubShapeSelector: public PartSet_WidgetShapeSelector,
+class PARTSET_EXPORT PartSet_WidgetSubShapeSelector: public ModuleBase_WidgetShapeSelector,
public PartSet_MouseProcessor
{
Q_OBJECT
virtual ~PartSet_WidgetSubShapeSelector();
+ /// Set sketcher
+ /// \param theSketch a sketcher object
+ void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+
+ /// Retrurns installed sketcher
+ CompositeFeaturePtr sketch() const { return mySketch; }
+
/// The methiod called when widget is deactivated
virtual void deactivate();
protected:
std::shared_ptr<ModuleBase_ViewerPrs> myCurrentSubShape;
std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
+
+ /// Pointer to a sketch
+ CompositeFeaturePtr mySketch;
};
#endif
\ No newline at end of file
//#include <GeomAPI_XY.h>
//#include <GeomDataAPI_Point2D.h>
//#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeReference.h>
//#include <ModelAPI_AttributeRefList.h>
//#include <ModelAPI_AttributeRefAttrList.h>
//#include <ModelAPI_Data.h>
void SketchPlugin_ConstraintSplit::initAttributes()
{
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeReference::typeId());
//data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
//data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
{
bool aValid = false;
- if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
+ if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
theError = "The attribute with the %1 type is not processed";
theError.arg(theAttribute->attributeType());
return aValid;
}
- AttributeSelectionPtr aFeatureAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ AttributeReferencePtr aFeatureAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
- ObjectPtr anAttrObject = aFeatureAttr->context();
+ ObjectPtr anAttrObject = aFeatureAttr->value();
FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
if (!anAttrFeature)
return aValid;
std::set<GeomShapePtr> anEdgeShapes;
ModelAPI_Tools::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
- if (anEdgeShapes.empty())
+ if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
return aValid;
- GeomShapePtr anAttrShape = *anEdgeShapes.begin();
-
- //std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = ModelGeomAlgo_Point2D::getPointOfRefAttr(
- // anAttrFeature, theAttribute, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
-
+ // coincidences to the feature
std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
- //ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature.get(), SketchPlugin_ConstraintCoincidence::ID(),
- // aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
-
- //ModelGeomAlgo_Point2D::filterPointsToBeInsideShape(anAttrShape, aRefAttributes, );
+ ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature, SketchPlugin_ConstraintCoincidence::ID(),
+ aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
- int aCoincidentToFeature = aRefAttributes.size();
+ GeomShapePtr anAttrShape = *anEdgeShapes.begin();
+ std::shared_ptr<SketchPlugin_Feature> aSFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
+ SketchPlugin_Sketch* aSketch = aSFeature->sketch();
+ std::shared_ptr<ModelAPI_Data> aData = aSketch->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()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+ std::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+ ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
+ aX->dir(), aY, aPoints);
+
+ int aCoincidentToFeature = aPoints.size();
if (aKind == SketchPlugin_Circle::ID())
- aValid = aCoincidentToFeature > 2;
+ aValid = aCoincidentToFeature >= 2;
else
- aValid = aCoincidentToFeature > 1;
+ aValid = aCoincidentToFeature >= 1;
}
- return true;
+ return aValid;
}
bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,