}
}
+void ConstructionPlugin_Axis::createAxisByCylindricalFace()
+{
+ std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
+ // update arguments due to the selection value
+ if (aSelection && !aSelection->isNull() && aSelection->isFace()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+}
+
void ConstructionPlugin_Axis::execute()
{
AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
if (aMethodType == "AxisByPointsCase") {
createAxisByTwoPoints();
} else if (aMethodType == "AxisByCylindricalFaceCase") {
- #ifdef _DEBUG
- std::cout << "ConstructionPlugin_Axis::execute: " << "AxisByCylindricalFaceCase is not supported yet." << std::endl;
- #endif
+ createAxisByCylindricalFace();
}
}
bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
bool isCustomized = theDefaultPrs.get() != NULL &&
theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
protected:
void createAxisByTwoPoints();
+ void createAxisByCylindricalFace();
};
#include <gp_Pln.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Plane.hxx>
+#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax2.hxx>
#include <gp_Circ.hxx>
return aRes;
}
+std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::cylinderAxis(
+ std::shared_ptr<GeomAPI_Shape> theCylindricalFace)
+{
+ std::shared_ptr<GeomAPI_Edge> aResult;
+ const TopoDS_Shape& aShape = theCylindricalFace->impl<TopoDS_Shape>();
+ if (aShape.IsNull())
+ return aResult;
+ TopoDS_Face aFace = TopoDS::Face(aShape);
+ if (aFace.IsNull())
+ return aResult;
+ TopLoc_Location aLoc;
+ Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
+ if (aSurf.IsNull())
+ return aResult;
+ Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf);
+ if (aCyl.IsNull())
+ return aResult;
+ gp_Ax1 anAxis = aCyl->Axis();
+ gp_Pnt aStart(anAxis.Location().Transformed(aLoc.Transformation()));
+ // edge length is 100, "-" because cylinder of extrusion has negative direction with the cylinder
+ gp_Pnt anEnd(anAxis.Location().XYZ() - anAxis.Direction().XYZ() * 100.);
+ anEnd.Transform(aLoc.Transformation());
+
+ BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
+ std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
+ TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+ aRes->setImpl(new TopoDS_Shape(anEdge));
+ return aRes;
+}
+
std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
double theRadius)
public:
/// Creates linear edge by two points
static std::shared_ptr<GeomAPI_Edge> line(std::shared_ptr<GeomAPI_Pnt> theStart,
- std::shared_ptr<GeomAPI_Pnt> theEnd);
+ std::shared_ptr<GeomAPI_Pnt> theEnd);
+ /// Creates edge - axis of the given cylindrical face
+ static std::shared_ptr<GeomAPI_Edge> cylinderAxis(
+ std::shared_ptr<GeomAPI_Shape> theCylindricalFace);
/// Creates linear edge in a form of a circle by a point and a circle radius
static std::shared_ptr<GeomAPI_Edge> lineCircle(std::shared_ptr<GeomAPI_Pnt> theCenter,
{
// perform the selection
TNaming_Selector aSel(selectionLabel());
- TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
TopoDS_Shape aContext;
ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
if (aBody) {
aContext = aBody->shape()->impl<TopoDS_Shape>();
} else {
- ResultConstructionPtr aConstr =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
- if (aConstr) {
- aContext = aConstr->shape()->impl<TopoDS_Shape>();
+ ResultPtr aResult =
+ std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
+ if (aResult) {
+ aContext = aResult->shape()->impl<TopoDS_Shape>();
} else {
Events_Error::send("A result with shape is expected");
return;
}
}
+ TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : aContext;
/// fix for issue 411: result modified shapes must not participate in this selection mechanism
FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
if (aFeatureOwner.get())
aFeatureOwner->eraseResults();
-
- aSel.Select(aNewShape, aContext);
+ if (!aContext.IsNull()) {
+ aSel.Select(aNewShape, aContext);
+ }
}
/// registers the name of the shape in the label (theID == 0) of sub label (theID is a tag)
#include <ModelAPI_AttributeRefAttr.h>
#include <GeomDataAPI_Point2D.h>
+#include <Events_Error.h>
#include <QWidget>
#include <QLayout>
return aFeatureStr;
}
+typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
+static ShapeTypes MyShapeTypes;
+
+TopAbs_ShapeEnum shapeType(const QString& theType)
+{
+ if (MyShapeTypes.count() == 0) {
+ MyShapeTypes["face"] = TopAbs_FACE;
+ MyShapeTypes["faces"] = TopAbs_FACE;
+ MyShapeTypes["vertex"] = TopAbs_VERTEX;
+ MyShapeTypes["vertices"] = TopAbs_VERTEX;
+ MyShapeTypes["wire"] = TopAbs_WIRE;
+ MyShapeTypes["edge"] = TopAbs_EDGE;
+ MyShapeTypes["edges"] = TopAbs_EDGE;
+ MyShapeTypes["shell"] = TopAbs_SHELL;
+ MyShapeTypes["solid"] = TopAbs_SOLID;
+ MyShapeTypes["solids"] = TopAbs_SOLID;
+ }
+ QString aType = theType.toLower();
+ if (MyShapeTypes.contains(aType))
+ return MyShapeTypes[aType];
+ Events_Error::send("Shape type defined in XML is not implemented!");
+ return TopAbs_SHAPE;
+}
+
+
}
#include "ModuleBase.h"
#include <ModelAPI_Feature.h>
+#include <TopAbs_ShapeEnum.hxx>
#include <QPixmap>
/// \return a string
MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false);
+/// Converts string value (name of shape type) to shape enum value
+/// \param theType - string with shape type name
+/// \return TopAbs_ShapeEnum value
+MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType);
+
}
#endif
if (aSelectionListAttr) {
// Store shapes type
TopAbs_ShapeEnum aCurrentType =
- ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
+ ModuleBase_Tools::shapeType(myTypeCombo->currentText());
aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
}
return true;
if (aSelectionListAttr) {
// Restore shape type
- setCurrentShapeType(
- ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
+ setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionListAttr->selectionType().c_str()));
updateSelectionList(aSelectionListAttr);
return true;
}
//********************************************************************
bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
+ TopoDS_Shape aShape = thePrs.shape();
+ if ((myTypeCombo->count() > 1) && (!aShape.IsNull())) {
+ TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText());
+ if (aShape.ShapeType() != aType)
+ return false;
+ }
ResultPtr aResult;
if (!thePrs.owner().IsNull()) {
ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner());
aSelectionListAttr->append(aResult, GeomShapePtr());
}
else {
- GeomShapePtr aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ GeomShapePtr aShape(new GeomAPI_Shape());
aShape->setImpl(new TopoDS_Shape(aTDSShape));
// We can not select a result of our feature
if (aShape->isEqual(aResult->shape()))
for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
aShapeTypeName = myTypeCombo->itemText(idx);
- TopAbs_ShapeEnum aRefType = ModuleBase_WidgetShapeSelector::shapeType(aShapeTypeName);
+ TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
myIsActive = false;
activateShapeSelection();
if (myIsActive) {
QString aNewType = myTypeCombo->currentText();
QIntList aList;
- aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
+ aList.append(ModuleBase_Tools::shapeType(aNewType));
myWorkshop->activateSubShapesSelection(aList);
} else {
myWorkshop->deactivateSubShapesSelection();
#include <list>
#include <string>
-typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
-static ShapeTypes MyShapeTypes;
-
-TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::shapeType(const QString& theType)
-{
- if (MyShapeTypes.count() == 0) {
- MyShapeTypes["face"] = TopAbs_FACE;
- MyShapeTypes["faces"] = TopAbs_FACE;
- MyShapeTypes["vertex"] = TopAbs_VERTEX;
- MyShapeTypes["vertices"] = TopAbs_VERTEX;
- MyShapeTypes["wire"] = TopAbs_WIRE;
- MyShapeTypes["edge"] = TopAbs_EDGE;
- MyShapeTypes["edges"] = TopAbs_EDGE;
- MyShapeTypes["shell"] = TopAbs_SHELL;
- MyShapeTypes["solid"] = TopAbs_SOLID;
- MyShapeTypes["solids"] = TopAbs_SOLID;
- }
- QString aType = theType.toLower();
- if (MyShapeTypes.contains(aType))
- return MyShapeTypes[aType];
- Events_Error::send("Shape type defined in XML is not implemented!");
- return TopAbs_SHAPE;
-}
ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
{
TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
foreach (QString aType, myShapeTypes) {
- if (aShape.ShapeType() == shapeType(aType))
+ if (aShape.ShapeType() == ModuleBase_Tools::shapeType(aType))
return true;
}
return false;
if (myIsActive) {
QIntList aList;
foreach (QString aType, myShapeTypes) {
- aList.append(shapeType(aType));
+ aList.append(ModuleBase_Tools::shapeType(aType));
}
myWorkshop->activateSubShapesSelection(aList);
} else {
Q_OBJECT
public:
- /// Converts string value (name of shape type) to shape enum value
- /// \param theType - string with shape type name
- /// \return TopAbs_ShapeEnum value
- static TopAbs_ShapeEnum shapeType(const QString& theType);
-
/// Constructor
/// \param theParent the parent object
/// \param theWorkshop instance of workshop interface