std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
return aRes;
-}
\ No newline at end of file
+}
// do noth use naming if selected shape is result shape itself, but not sub-shape
TDF_Label aSelLab = selectionLabel();
- if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
- aSelLab.ForgetAllAttributes(true);
- TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID);
- } else {
- aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
- if (theContext->groupName() == ModelAPI_ResultBody::group())
+ aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
+ if (theContext->groupName() == ModelAPI_ResultBody::group()) {
+ // do not select the whole shape for body:it is already must be in the data framework
+ if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
+ aSelLab.ForgetAllAttributes(true);
+ TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID);
+ } else {
selectBody(theContext, theSubShape);
- else if (theContext->groupName() == ModelAPI_ResultConstruction::group())
- selectConstruction(theContext, theSubShape);
+ }
+ } else if (theContext->groupName() == ModelAPI_ResultConstruction::group()) {
+ selectConstruction(theContext, theSubShape);
}
+ myIsInitialized = true;
std::string aSelName = namingName();
if(!aSelName.empty())
//selectSubShape("EDGE", "Extrusion_1/TopFace|Extrusion_1/LateralFace_1");
//selectSubShape("EDGE", "Sketch_1/Edge_6");
#endif
- myIsInitialized = true;
owner()->data()->sendAttributeUpdated(this);
}
}
}
} else { // simple construction element: the selected is that needed
+ selectConstruction(aContext, aContext->shape());
owner()->data()->sendAttributeUpdated(this);
return true;
}
else if (theShape.ShapeType() == TopAbs_VERTEX) aName<<"Vertex";
if (theRefs.IsNull()) {
- aName<<"_"<<theID;
+ aName<<theID;
} else { // make a compisite name from all sub-elements indexes: "1_2_3_4"
TColStd_MapIteratorOfPackedMapOfInteger aRef(theRefs->GetMap());
for(; aRef.More(); aRef.Next()) {
- aName<<"_"<<aRef.Key();
+ aName<<"-"<<aRef.Key();
}
}
FeaturePtr aContextFeature = theContext->document()->feature(theContext);
CompositeFeaturePtr aComposite =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+ const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
if (!aComposite || aComposite->numberOfSubs() == 0) {
- return; // saving of context is enough: result construction contains exactly the needed shape
+ // saving of context is enough: result construction contains exactly the needed shape
+ TNaming_Builder aBuilder(selectionLabel());
+ aBuilder.Generated(aSubShape);
+ aMyDoc->addNamingName(selectionLabel(), theContext->data()->name());
+ TDataStd_Name::Set(selectionLabel(), theContext->data()->name().c_str());
+ return;
}
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(owner()->data());
TDF_Label aLab = myRef.myRef->Label();
// identify the reuslts of sub-object of the composite by edges
- const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
// save type of the selected shape in integer attribute
TopAbs_ShapeEnum aShapeType = aSubShape.ShapeType();
TDataStd_Integer::Set(aLab, (int)aShapeType);
}
}
-void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
+void PartSet_Module::onVertexSelected()
{
ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
aWgt->setWorkshop(aWorkshop);
aWgt->setSketch(mySketchMgr->activeSketch());
- connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
- this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
+ connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
theModelWidgets.append(aWgt);
return aWgt->getControl();
virtual void registerFilters();
private slots:
- void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+ void onVertexSelected();
private:
aFeature->execute();
}
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
+ findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
+ double theTolerance, const QList<FeaturePtr>& theIgnore)
+{
+ std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+ new GeomAPI_Pnt2d(theX, theY));
+
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
+ for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+ FeaturePtr aFeature = theSketch->subFeature(i);
+ if (!theIgnore.contains(aFeature)) {
+ anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
+ for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ double x = aCurPoint->x();
+ double y = aCurPoint->y();
+ if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
+ return aCurPoint;
+ }
+ }
+ }
+ }
+ return std::shared_ptr<GeomDataAPI_Point2D>();
+}
+
+
void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
const std::string& theAttribute, double theClickedX,
double theClickedY)
aLast = anAttiributes.end();
std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
for (; anIt != aLast && !aFPoint; anIt++) {
- std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(*anIt);
- if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())) {
aFPoint = aCurPoint;
+ break;
+ }
}
if (aFPoint)
PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
std::shared_ptr<GeomAPI_Pln> aPlane;
std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- 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 && anOrigin) {
- 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));
+ 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 && anOrigin) {
+ 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;
static std::shared_ptr<ModelAPI_Document> document();
+ static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch,
+ double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
+
/// Returns a point attribute of the feature by the coordinates if it is
/// \param theFeature the feature
/// \param theX the horizontal coordinate
void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
XGUI_Selection* aSelection = myWorkshop->selector()->selection();
- NCollection_List<TopoDS_Shape> aShapes;
- std::list<ObjectPtr> aObjects;
- aSelection->selectedShapes(aShapes, aObjects);
- if (aShapes.Extent() > 0) {
- TopoDS_Shape aShape = aShapes.First();
- double aX, aY;
- if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
- setPoint(aX, aY);
-
- PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
- emit vertexSelected(aObjects.front(), aShape);
- emit focusOutWidget(this);
- return;
- }
- }
+ // 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);
+ //if (aShapes.Extent() > 0) {
+ // TopoDS_Shape aShape = aShapes.First();
+ // double aX, aY;
+ // if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
+ // setPoint(aX, aY);
+
+ // PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+ // emit vertexSelected(aObjects.front(), aShape);
+ // emit focusOutWidget(this);
+ // return;
+ // }
+ //}
+ // End of Bug dependent fragment
+
// A case when point is taken from mouse event
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
double aX, anY;
- PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
+ Handle(V3d_View) aView = theWnd->v3dView();
+ PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
setPoint(aX, anY);
+ std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
+ QList<FeaturePtr> aIgnore;
+ aIgnore.append(feature());
+
+ double aTolerance = aView->Convert(4);
+ std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
+ PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
+ if (aAttrPnt.get() != NULL) {
+
+ PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
+ emit vertexSelected();
+ }
emit focusOutWidget(this);
}
/// Signal about selection of an existing vertex from an object
/// \param theObject - the selected object
/// \param theShape - the selected shape
- void vertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+ void vertexSelected();
protected slots:
void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
std::dynamic_pointer_cast<SketchPlugin_Sketch>(theFeature);
if (aSketchFeature.get()) {
std::shared_ptr<ModelAPI_Data> aData = aSketchFeature->data();
- std::shared_ptr<GeomDataAPI_Dir> aNormal =
- std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
-
- aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+ if (aData) {
+ std::shared_ptr<GeomDataAPI_Dir> aNormal =
+ std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+
+ aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+ }
}
return aMsg;
}