Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd);
GeomAdaptor_Curve aAdaptor(aCurve);
+ std::shared_ptr<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge);
+ anEdge->setImpl(new TopoDS_Shape(theShape));
if (aAdaptor.GetType() == GeomAbs_Line) {
// Create line
aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID());
+ if (!theObject.get()) {
+ // There is no selected result
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 = anEdge->firstPoint();
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 = anEdge->lastPoint();
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = convertTo2D(theSketch, aPnt1);
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = convertTo2D(theSketch, aPnt2);
+
+ std::shared_ptr<ModelAPI_Data> aData = aMyFeature->data();
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
+
+ aPoint1->setValue(aPnt2d1);
+ aPoint2->setValue(aPnt2d2);
+
+ // If this is an axis then its name has to be changed correspondently
+ std::string aSuffix = "";
+ bool aXdir = fabs(aPnt1->x() - aPnt2->x()) > Precision::Confusion();
+ bool aYdir = fabs(aPnt1->y() - aPnt2->y()) > Precision::Confusion();
+ bool aZdir = fabs(aPnt1->z() - aPnt2->z()) > Precision::Confusion();
+ if (aXdir && (!aYdir) && (!aZdir))
+ aSuffix = "X";
+ else if ((!aXdir) && aYdir && (!aZdir))
+ aSuffix = "Y";
+ else if ((!aXdir) && (!aYdir) && aZdir)
+ aSuffix = "Z";
+ if (aSuffix.length() > 0)
+ aData->setName("Axis_" + aSuffix);
+ aMyFeature->execute();
+
+ }
} else if (aAdaptor.GetType() == GeomAbs_Circle) {
- std::shared_ptr<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge);
- anEdge->setImpl(new TopoDS_Shape(theShape));
if (anEdge->isArc()) {
// Create arc
aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
(aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (anAttr && aRes) {
+ if (!aRes.get()) {
+ aRes = aMyFeature->firstResult();
+ }
+ if (anAttr.get() && aRes.get()) {
std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
anEdge->setImpl(new TopoDS_Shape(theShape));
(aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (anAttr && aRes) {
+ if (!aRes.get()) {
+ // If the point is selected not from Result object
+ std::shared_ptr<GeomAPI_Shape> aShape =
+ std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(theShape));
+
+ std::shared_ptr<GeomAPI_Vertex> aVertex =
+ std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = convertTo2D(theSketch, aPnt);
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Point::COORD_ID()));
+ aPoint->setValue(aPnt2d);
+ if ((aPnt->x() < Precision::Confusion()) &&
+ (aPnt->y() < Precision::Confusion()) &&
+ (aPnt->z() < Precision::Confusion()))
+ aData->setName("Origin");
+
+ aMyFeature->execute();
+ aRes = aMyFeature->firstResult();
+ }
+ if (anAttr.get() && aRes.get()) {
std::shared_ptr<GeomAPI_Shape> aVert(new GeomAPI_Shape);
aVert->setImpl(new TopoDS_Shape(theShape));
void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
const bool theUpdateViewer)
{
+ //Handle(AIS_InteractiveObject) aTriehedron = getTrihedron();
+ //if (!aTriehedron.IsNull())
+ // deactivateAIS(aTriehedron);
+
QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
for (; anIt != aLast; anIt++) {
deactivate(*anIt, false);
Handle(AIS_InteractiveObject) anAISIO;
AIS_ListOfInteractive aPrsList;
- if (theObjList.isEmpty())
- return;
- else {
- foreach(ObjectPtr aObj, theObjList) {
- if (myResult2AISObjectMap.contains(aObj))
- aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
- }
+ //if (aObjList.isEmpty())
+ // return;
+ //else {
+ foreach(ObjectPtr aObj, theObjList) {
+ if (myResult2AISObjectMap.contains(aObj))
+ aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
}
+ //}
+
+ // Add trihedron because it has to partisipate in selection
+ Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
+ if (!aTrihedron.IsNull())
+ aPrsList.Append(aTrihedron);
+
+ if (aPrsList.Extent() == 0)
+ return;
AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
bool isActivationChanged = false;
if (activate(anAISIO, myActiveSelectionModes, false))
isActivationChanged = true;
}
+ if (!aTrihedron.IsNull()) {
+ foreach(int aMode, myActiveSelectionModes)
+ aContext->SetSelectionSensitivity(aTrihedron, aMode, 8);
+ }
// VSV It seems that there is no necessity to update viewer on activation
//if (theUpdateViewer && isActivationChanged)
// updateViewer();
void XGUI_Displayer::deactivateTrihedron() const
{
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
+ if (!aTrihedron.IsNull()) {
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ aContext->Deactivate(aTrihedron);
+ }
+}
+
+Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
if (!aContext.IsNull()) {
AIS_ListOfInteractive aList;
aContext->DisplayedObjects(aList, true);
for (aIt.Initialize(aList); aIt.More(); aIt.Next()) {
Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value());
if (!aTrihedron.IsNull()) {
- aContext->Deactivate(aTrihedron);
+ return aTrihedron;
}
}
}
+ return Handle(AIS_InteractiveObject)();
}
void XGUI_Displayer::openLocalContext()
{
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ Handle(AIS_InteractiveContext) aContext = AISContext();
// Open local context if there is no one
if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
// Preserve selected objects
//aContext->ClearCurrents();
aContext->OpenLocalContext();
- deactivateTrihedron();
+ //deactivateTrihedron();
//aContext->NotUseDisplayedObjects();
//myUseExternalObjects = false;
void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
{
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ Handle(AIS_InteractiveContext) aContext = AISContext();
if (!aContext.IsNull()) {
if (theMode == -1)
aContext->Deactivate(theIO);
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
aContext->OpenLocalContext();
- deactivateTrihedron();
+ //deactivateTrihedron();
aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
}
// trihedron AIS check should be after the AIS loading.
// If it is not loaded, it is steel selectable in the viewer.
- Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
- if (aTrihedron.IsNull()) {
+ //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
+ //if (aTrihedron.IsNull()) {
//aContext->Load(anAISIO, -1, true);
// In order to clear active modes list
if (theModes.size() == 0) {
isActivationChanged = true;
}
}
- }
+ //}
}
return isActivationChanged;
}
/// \param theUpdateViewer update viewer flag
/// \return previously defined color on the object
QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
+
+ /// Returns Trihedron object if it is displayed
+ Handle(AIS_InteractiveObject) getTrihedron() const;
/// Converts shape type (TopAbs_ShapeEnum) to selection mode
/// \param theShapeType a shape type from TopAbs_ShapeEnum
#include <ModelAPI_Feature.h>
#include <AIS_InteractiveContext.hxx>
+#include <AIS_Axis.hxx>
+#include <AIS_Point.hxx>
+#include <Geom_Line.hxx>
+#include <BRep_Builder.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Point.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <Prs3d_DatumAspect.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <StdSelect_BRepOwner.hxx>
TopoDS_Shape aShape = aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location());
if (!aShape.IsNull())
thePrs.setShape(aShape);
- }
+ } else {
+ // Fill by trihedron shapes
+ Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(anIO);
+ if (!aAxis.IsNull()) {
+ // an Axis from Trihedron
+ Handle(Geom_Line) aLine = aAxis->Component();
+ Handle(Prs3d_DatumAspect) DA = aAxis->Attributes()->DatumAspect();
+ Handle(Geom_TrimmedCurve) aTLine = new Geom_TrimmedCurve(aLine, 0, DA->FirstAxisLength());
+
+ BRep_Builder aBuilder;
+ TopoDS_Edge aEdge;
+ aBuilder.MakeEdge(aEdge, aTLine, Precision::Confusion());
+ if (!aEdge.IsNull())
+ thePrs.setShape(aEdge);
+ } else {
+ Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(anIO);
+ if (!aPoint.IsNull()) {
+ // A point from trihedron
+ Handle(Geom_Point) aPnt = aPoint->Component();
+ BRep_Builder aBuilder;
+ TopoDS_Vertex aVertex;
+ aBuilder.MakeVertex(aVertex, aPnt->Pnt(), Precision::Confusion());
+ if (!aVertex.IsNull())
+ thePrs.setShape(aVertex);
+ }
+ }
+ }
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
ObjectPtr aFeature = aDisplayer->getObject(anIO);