std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
{
- std::shared_ptr<GeomAPI_Pln> aPlane;
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- if (aData) {
- std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- if (aNormal.get() && aNormal->isInitialized() &&
- anOrigin.get() && anOrigin->isInitialized()) {
- double adX = aNormal->x();
- double adY = aNormal->y();
- double adZ = aNormal->z();
-
- if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
- double aX = anOrigin->x();
- double aY = anOrigin->y();
- double aZ = anOrigin->z();
- gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
- double aA, aB, aC, aD;
- aPln.Coefficients(aA, aB, aC, aD);
- aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
- }
- }
- }
- return aPlane;
+ 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_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
}
}
+//********************************************************************
+void PartSet_WidgetSubShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape)
+{
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ theObject = aSelection->getResult(thePrs);
+ if (!theObject.get() && myCurrentSubShape->object())
+ theObject = myCurrentSubShape->object();
+}
+
//********************************************************************
bool PartSet_WidgetSubShapeSelector::setSelection(
QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
const bool theToValidate)
{
- bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate);
-
- if (aResult && !theToValidate) {
- ObjectPtr aBaseObject = myCurrentSubShape->object();
- GeomShapePtr aBaseShape = myCurrentSubShape->shape();
-
+ //if (theToValidate)
+ // bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate);
+ //else {
+ // the sub-shape is selected, initial shape is not highlighted/selected, we need to use
+ // the sub-shape to fill attribute;
+ ObjectPtr aBaseObject = myCurrentSubShape->object();
+ GeomShapePtr aBaseShape = myCurrentSubShape->shape();
+ bool aResult = aBaseObject.get() && aBaseShape.get();
+ // firstly set the selection to the attribute
+ if (aResult) {
+ QList<ModuleBase_ViewerPrsPtr> aValues;
+ aValues.append(myCurrentSubShape);
+ aResult = ModuleBase_WidgetShapeSelector::setSelection(aValues, theToValidate);
+ }
+ // secondly fill additional attributes
+ if (aResult) {
if (aBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aBaseShape));
- std::shared_ptr<GeomAPI_Pln> aSketchPlane = PartSet_Tools::sketchPlane(mySketch);
std::shared_ptr<GeomAPI_Pnt> aFirstPnt = anEdge->firstPoint();
std::shared_ptr<GeomAPI_Pnt> aLastPnt = anEdge->lastPoint();
- std::shared_ptr<GeomAPI_Pnt2d> aFirstPnt2D = aFirstPnt->to2D(aSketchPlane);
- std::shared_ptr<GeomAPI_Pnt2d> aLastPnt2D = aLastPnt->to2D(aSketchPlane);
+ std::shared_ptr<GeomAPI_Pnt2d> aFirstPnt2D = PartSet_Tools::convertTo2D(mySketch, aFirstPnt);
+ std::shared_ptr<GeomAPI_Pnt2d> aLastPnt2D = PartSet_Tools::convertTo2D(mySketch, aLastPnt);
+
/// find the points in feature attributes
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
aRefLast = aRefAttributes.end();
for (; aRefIt != aRefLast; aRefIt++) {
std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint = *aRefIt;
+ double anX = anAttributePoint->x();
+ double anY = anAttributePoint->y();
if (!aFirstPointAttr.get() && aFirstPnt2D->isEqual(anAttributePoint->pnt()))
aFirstPointAttr = anAttributePoint;
if (!aLastPointAttr.get() && aLastPnt2D->isEqual(anAttributePoint->pnt()))
}
}
+ if (!aFirstPointAttr.get() || !aLastPointAttr)
+ return false;
+
FeaturePtr aFeature = feature();
AttributeRefAttrPtr anAPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
AttributeRefAttrPtr aBPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
anAPointAttr->setAttr(aFirstPointAttr);
aBPointAttr->setAttr(aLastPointAttr);
}
}
+ //}
return aResult;
}
ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(),
aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
// layed on feature coincidences to divide it on several shapes
- FeaturePtr aSketch = sketch();
+ CompositeFeaturePtr aSketch = 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<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()));
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::shared_ptr<GeomAPI_Dir> aDirY(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);
+ aX->dir(), aDirY, aPoints);
int aCoincidentToFeature = aPoints.size();
if (aKind == SketchPlugin_Circle::ID())