bool isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const;
};
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Vertex> GeomVertexPtr;
+
#endif
IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject,
- const GeomShapePtr& theEdge,
- const gp_Pnt& theCenter)
+ const GeomEdgePtr& theEdge,
+ const gp_Pnt& theCenter,
+ ModelAPI_AttributeSelection::CenterType theType)
: AIS_Point(new Geom_CartesianPoint(theCenter)),
myObject(theObject),
- myEdge(theEdge)
+ myEdge(theEdge),
+ myCenterType(theType)
{
}
\ No newline at end of file
#define PartSet_CenterPrs_H
#include <ModelAPI_Object.h>
-#include <GeomAPI_Shape.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <GeomAPI_Edge.h>
#include <AIS_Point.hxx>
#include <Standard_DefineHandle.hxx>
DEFINE_STANDARD_HANDLE(PartSet_CenterPrs, AIS_Point)
+/**
+* \ingroup GUI
+* A presentation class for displaying of centers of external curcular objects in a sketch
+*/
class PartSet_CenterPrs: public AIS_Point
{
public:
/// Constructor
- /// \param theResult a result object
+ /// \param theObject an object with circular edge
+ /// \param theEdge a circular edge
+ /// \param theCenter a center point of the circular edge
+ /// \param theType a type of the center
Standard_EXPORT PartSet_CenterPrs(const ObjectPtr& theObject,
- const GeomShapePtr& theEdge,
- const gp_Pnt& theCenter);
+ const GeomEdgePtr& theEdge,
+ const gp_Pnt& theCenter,
+ ModelAPI_AttributeSelection::CenterType theType);
+ /// Returns an Object which contains the circular edge
ObjectPtr object() const { return myObject; }
- GeomShapePtr edge() const { return myEdge; }
+
+ /// Returns a circular edge shape
+ GeomEdgePtr edge() const { return myEdge; }
+
+ /// Returns type of the center
+ ModelAPI_AttributeSelection::CenterType centerType() const { return myCenterType; }
DEFINE_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
+
private:
ObjectPtr myObject;
- GeomShapePtr myEdge;
+ GeomEdgePtr myEdge;
+ ModelAPI_AttributeSelection::CenterType myCenterType;
};
#endif
#include <XGUI_Tools.h>
#include <XGUI_Displayer.h>
#include <XGUI_Workshop.h>
+#include <XGUI_SelectionMgr.h>
PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop,
const CompositeFeaturePtr& theSketch)
{
XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
XGUI_Displayer* aDisplayer = aWorkshop->displayer();
- connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjctPtr)),
+ connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
SLOT(onDisplayObject(ObjectPtr, AISObjectPtr)));
+
connect(aDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
SLOT(onEraseObject(ObjectPtr, AISObjectPtr)));
if (myPresentations.isEmpty())
return;
XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+ if (!aWorkshop)
+ return;
+
XGUI_Displayer* aDisplayer = aWorkshop->displayer();
QMapIterator<ObjectPtr, ListOfAIS> aIt(myPresentations);
while (aIt.hasNext()) {
void PartSet_ExternalPointsMgr::updateCenterPresentations()
{
+ XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
// Return if there is no plane defined
- if (!plane().get())
+ if (!plane().get()) {
+ connect(aWorkshop->selector(), SIGNAL(selectionChanged()),
+ SLOT(onSelectionChanged()));
return;
-
- XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+ }
XGUI_Displayer* aDisplayer = aWorkshop->displayer();
QList<std::shared_ptr<ModuleBase_ViewerPrs>> aEdgesPrs = findCircularEdgesInPlane();
foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aEdgesPrs) {
- GeomAPI_Edge aEdge(aPrs->shape());
- if (aEdge.isArc() || aEdge.isCircle()) {
- GeomCirclePtr aCircle = aEdge.circle();
+ GeomEdgePtr aEdge(new GeomAPI_Edge(aPrs->shape()));
+ ListOfAIS aList;
+ if (aEdge->isArc() || aEdge->isCircle()) {
+ GeomCirclePtr aCircle = aEdge->circle();
GeomPointPtr aCenter = aCircle->center();
Handle(PartSet_CenterPrs) aCentPrs =
- new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aCenter->impl<gp_Pnt>());
+ new PartSet_CenterPrs(aPrs->object(), aEdge, aCenter->impl<gp_Pnt>(),
+ ModelAPI_AttributeSelection::CIRCLE_CENTER);
AISObjectPtr anAIS(new GeomAPI_AISObject());
anAIS->setImpl(new Handle(AIS_InteractiveObject)(aCentPrs));
- aDisplayer->displayAIS(anAIS, false);
- ListOfAIS aList;
aList.append(anAIS);
- myPresentations[aPrs->object()] = aList;
- } else if (aEdge.isEllipse()) {
- GeomEllipsePtr aEllipse = aEdge.ellipse();
+ } else if (aEdge->isEllipse()) {
+ GeomEllipsePtr aEllipse = aEdge->ellipse();
GeomPointPtr aF1 = aEllipse->firstFocus();
GeomPointPtr aF2 = aEllipse->secondFocus();
Handle(PartSet_CenterPrs) aF1Prs =
- new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF1->impl<gp_Pnt>());
+ new PartSet_CenterPrs(aPrs->object(), aEdge, aF1->impl<gp_Pnt>(),
+ ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS);
Handle(PartSet_CenterPrs) aF2Prs =
- new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF2->impl<gp_Pnt>());
+ new PartSet_CenterPrs(aPrs->object(), aEdge, aF2->impl<gp_Pnt>(),
+ ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS);
- ListOfAIS aList;
AISObjectPtr anAIS1(new GeomAPI_AISObject());
anAIS1->setImpl(new Handle(AIS_InteractiveObject)(aF1Prs));
- aDisplayer->displayAIS(anAIS1, false);
aList.append(anAIS1);
AISObjectPtr anAIS2(new GeomAPI_AISObject());
anAIS2->setImpl(new Handle(AIS_InteractiveObject)(aF2Prs));
- aDisplayer->displayAIS(anAIS2, false);
aList.append(anAIS2);
+ }
+ if (myPresentations.contains(aPrs->object()))
+ myPresentations[aPrs->object()].append(aList);
+ else
myPresentations[aPrs->object()] = aList;
+ foreach(AISObjectPtr anAIS, aList) {
+ aDisplayer->displayAIS(anAIS, false);
+ aDisplayer->activateAIS(anAIS->impl<Handle(AIS_InteractiveObject)>(), TopAbs_VERTEX, false);
}
}
}
void PartSet_ExternalPointsMgr::onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS)
{
- updateCenterPresentations();
+ if (myPresentations.contains(theObj)) {
+ XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+ XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+ ListOfAIS aList = myPresentations[theObj];
+ foreach(AISObjectPtr aAIS, aList) {
+ aDisplayer->eraseAIS(aAIS, false);
+ }
+ myPresentations.remove(theObj);
+ aDisplayer->updateViewer();
+ }
}
return false;
CompositeFeaturePtr aComp = ModelAPI_Tools::compositeOwner(aFeature);
return aComp == mySketch;
-}
\ No newline at end of file
+}
+
+void PartSet_ExternalPointsMgr::onSelectionChanged()
+{
+ if (plane().get()) {
+ XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+ disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()),
+ this, SLOT(onSelectionChanged()));
+ updateCenterPresentations();
+ }
+}
virtual ~PartSet_ExternalPointsMgr();
-private slots:
+public slots:
/**
* A slot which processes display of object
* \param theObj the displayed object
*/
void onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS);
+ // Called on selection changed
+ void onSelectionChanged();
+
private:
/**
* Returns list of presentations which have displayed shapes with circular edges
/// Returns plane of the current sketch
GeomPlanePtr plane() const;
+ /**
+ * Checks that the given object is an object of the current sketch
+ * \param theRes an object to check
+ * \return True if the given object is a sub-object of the current sketch
+ */
bool isSketchObject(const ObjectPtr& theRes) const;
private:
+ /// Workshop
ModuleBase_IWorkshop* myWorkshop;
+
+ /// Current sketch
CompositeFeaturePtr mySketch;
+ /// Type for list of created AIS objects
typedef QList<AISObjectPtr> ListOfAIS;
+ /// Map of created AIS objects
QMap<ObjectPtr, ListOfAIS> myPresentations;
};
return isAuxiliaryFeature;
}
+
+
+ResultPtr PartSet_Tools::createFixedByExternalCenter(const ObjectPtr& theObject,
+ const std::shared_ptr<GeomAPI_Edge>& theEdge,
+ ModelAPI_AttributeSelection::CenterType theType,
+ const CompositeFeaturePtr& theSketch,
+ bool theTemporary)
+{
+ FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
+
+ if (aMyFeature) {
+ DataPtr aData = aMyFeature->data();
+ AttributeSelectionPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (anAttr.get() && aRes.get()) {
+ anAttr->setValueCenter(aRes, theEdge, theType, theTemporary);
+ aMyFeature->execute();
+ return aMyFeature->lastResult();
+ }
+ }
+ return ResultPtr();
+}
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeSelection.h>
#include <Events_Message.h>
* \return boolean result
*/
static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);
+
+ static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject,
+ const std::shared_ptr<GeomAPI_Edge>& theEdge,
+ ModelAPI_AttributeSelection::CenterType theType,
+ const CompositeFeaturePtr& theSketch,
+ bool theTemporary = false);
+
};
#endif
#include <PartSet_Module.h>
#include <PartSet_SketcherReentrantMgr.h>
#include <PartSet_ExternalObjectsMgr.h>
+#include <PartSet_CenterPrs.h>
#include <XGUI_Tools.h>
#include <XGUI_Workshop.h>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
+#include <Geom_Point.hxx>
#include <cfloat>
#include <climits>
if (!aFirstValue.get() && myPreSelected.get()) {
aFirstValue = myPreSelected;
}
+
// if we have selection and use it
if (aFirstValue.get() && isValidSelectionCustom(aFirstValue) &&
aFirstValue->shape().get()) { /// Trihedron Axis may be selected, but shape is empty
}
}
}
- // End of Bug dependent fragment
+ // The selection could be a center of an external circular object
+ else if (aFirstValue.get() && (!aFirstValue->interactive().IsNull())) {
+ Handle(PartSet_CenterPrs) aAIS = Handle(PartSet_CenterPrs)::DownCast(aFirstValue->interactive());
+ if (!aAIS.IsNull()) {
+ gp_Pnt aPntComp = aAIS->Component()->Pnt();
+ GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z()));
+ TopoDS_Shape aShape = aVertPtr->impl<TopoDS_Shape>();
+
+ ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), mySketch);
+ if (!aFixedObject.get())
+ aFixedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(),
+ aAIS->centerType(), mySketch);
+ if (aFixedObject.get())
+ setConstraintToObject(aFixedObject);
+ // fignal updated should be flushed in order to visualize possible created
+ // external objects e.g. selection of trihedron axis when input end arc point
+ updateObject(feature());
+
+ double aX, aY;
+ if (getPoint2d(aView, aShape, aX, aY)) {
+ // do not create a constraint to the point, which already used by the feature
+ // if the feature contains the point, focus is not switched
+ setPoint(aX, aY);
+ }
+ emit vertexSelected(); // it stops the reentrant operation
+ emit focusOutWidget(this);
+ }
+ }
else {
// A case when point is taken from mouse event
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop)
{
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
- return aConnector->workshop();
+ if (aConnector)
+ return aConnector->workshop();
+ return 0;
}
}