#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_Session.h>
#include <ModelAPI_AttributeInteger.h>>
#include <ModelAPI_AttributeDouble.h>>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_Validator.h>
#include <Locale_Convert.h>
#include <Events_InfoMessage.h>
+#include <SketchPlugin_Sketch.h>
#include <string>
#include <sstream>
data()->addAttribute(DXFPlugin_Import::BLOCKS_ID(), ModelAPI_AttributeBoolean::typeId());
data()->addAttribute(DXFPlugin_Import::IMPORT_COLORS_ID(), ModelAPI_AttributeBoolean::typeId());
data()->addAttribute(DXFPlugin_Import::EDGES_WITH_WIDTH_ID(), ModelAPI_AttributeBoolean::typeId());
+
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SKETCH_TO_JOIN_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ATTACH_TO_SKETCH_ID());
}
bool DXFPlugin_Import::checkLicense()
Handle(TDocStd_Document) aDoc = new TDocStd_Document("XDE");
Standard_Boolean aBool = aReader.Transfer(aDoc);
+ if (!aBool)
+ {
+ setError("Error: Failed transfer OCAF document from DXF file.");
+ return;
+ }
DXFPlugin_ImportAlgoAPI anAlgo(aDoc);
GeomShapePtr aResShape(new GeomAPI_Shape());
if (isOk)
// Convert shape to sketch
{
- auto aShapes = anAlgo.ConvertToSketchElements(aShape);
+ CompositeFeaturePtr aSketch;
+ if (boolean(DXFPlugin_Import::ATTACH_TO_SKETCH_ID())->value())
+ {
+ auto anObj = reference(DXFPlugin_Import::SKETCH_TO_JOIN_ID())->value();
+ aSketch =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(anObj);
+ }
+ else
+ {
+ DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
+ DocumentPtr aPart = ModelAPI_Session::get()->activeDocument();
+ FeaturePtr aSkFeature = aPart->addFeature("Sketch");
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aSkFeature->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+
+ anOrigin->setX(0);
+ anOrigin->setY(0);
+ anOrigin->setZ(0);
+
+ std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aSkFeature->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ aDirX->setValue(1, 0, 0);
+
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aSkFeature->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aNorm->setValue(0, 0, 1);
+
+ aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aSkFeature);
+ }
+ auto aShapes = anAlgo.ConvertToSketchElements(aShape, aSketch);
isOk = false;
}
// From list of edges create sketch primitives
#include <SketchPlugin_MacroEllipticArc.h>
#include <SketchPlugin_Sketch.h>
+#define _DEBUG
+
+#ifdef _DEBUG
+#include <GeomAPI_Pnt2d.h>
+#endif // _DEBUG
+
DXFPlugin_ImportAlgoAPI::DXFPlugin_ImportAlgoAPI(Handle(TDocStd_Document) theDoc)
{
myDoc = Handle(TDocStd_Document)(theDoc);
return std::vector<int>();
}
-std::list<TopoDS_Shape> DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const TopoDS_Shape theShape) const
+std::list<TopoDS_Shape> DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const TopoDS_Shape theShape, CompositeFeaturePtr theSketch) const
{
- CompositeFeaturePtr aSketch;
- auto aSession = ModelAPI_Session::get();
- auto aPartSet = aSession->moduleDocument();
- auto aPart = aSession->activeDocument();
- for (auto feat : aPart->allFeatures())
- if (feat->getKind() == "Sketch")
- {
- aSketch =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feat);
- break;
- }
-
- if (!aSketch)
- return std::list<TopoDS_Shape>();
-
int aNb = 0;
std::list<TopoDS_Shape> aShapes;
for (TopExp_Explorer anExp(theShape, TopAbs_EDGE); anExp.More(); anExp.Next())
auto aStartP = anEdge->firstPoint();
auto anEndP = anEdge->lastPoint();
auto aCenter = aCircle->center();
- auto anArcFeature = aSketch->addFeature(SketchPlugin_Arc::ID());
+ auto anArcFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(anArcFeature->attribute(SketchPlugin_Arc::START_ID()));
aCenterAttr->setValue(aCenter->x(), aCenter->y());
anArcFeature->execute();
}
+ // BSpline importred incorrect
if (anEdge->isBSpline())
{
const TopoDS_Shape& aShape = anEdge->impl<TopoDS_Shape>();
auto aWeights = aBSpl->Weights();
auto aDegree = aBSpl->Degree();
auto aPoles = aBSpl->Poles();
- auto aBSplineFeature = aSketch->addFeature(SketchPlugin_BSpline::ID());
+
+ auto aBSplineFeature = theSketch->addFeature(SketchPlugin_BSpline::ID());
AttributePoint2DArrayPtr aPolesArray =
std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(aBSplineFeature->attribute(SketchPlugin_BSpline::POLES_ID()));
AttributeIntArrayPtr aMultsArray = aBSplineFeature->data()->intArray(SketchPlugin_BSpline::MULTS_ID());
AttributeIntegerPtr aDegreeAttr = aBSplineFeature->data()->integer(SketchPlugin_BSpline::DEGREE_ID());
aWeightsArray->setSize(aPoles.Size());
- aKnotsArray->setSize(aPoles.Size());
- aMultsArray->setSize(aPoles.Size());
aPolesArray->setSize(aPoles.Size());
aDegreeAttr->setValue(aDegree);
for (int i = 0; i < aPoles.Size(); ++i)
{
aPolesArray->setPnt(i, aPoles[i + 1].X(), aPoles[i + 1].Y());
+ }
+
+ for (int i = 0; i < aPoles.Size(); ++i)
+ {
if (aWeights == NULL)
aWeightsArray->setValue(i, 1);
else
aWeightsArray->setValue(i, aWeights->Value(i + 1));
- aKnotsArray->setValue(i, aKnots.Value(i + 1));
- aMultsArray->setValue(i, aMulti.Value(i + 1));
}
+
+ aKnotsArray->setSize(aPoles.Size() - 2);
+ aKnotsArray->setValue(0, aKnots.Value(aKnots.Lower()));
+ aKnotsArray->setValue(aKnotsArray->size() - 1, aKnots.Value(aKnots.Upper()));
+ for (int i = 1; i < aKnotsArray->size() - 1; ++i)
+ {
+ aKnotsArray->setValue(i, (aKnots.Last() - aKnots.First()) / (aKnotsArray->size() - 1) * i);
+ }
+
+ aMultsArray->setSize(aPoles.Size() - 2);
+ aMultsArray->setValue(0, 4 /*aMulti.Value(aMulti.Lower())*/);
+ aMultsArray->setValue(aMultsArray->size() - 1, 4 /*aMulti.Value(aMulti.Upper())*/);
+ for (int i = 1; i < aMultsArray->size() - 1; ++i)
+ {
+ aMultsArray->setValue(i, 1 /*aMulti.Value(aMulti.Lower() + 1)*/);
+ }
+
+#ifdef _DEBUG
+ std::cout << "\n\nPoles\n";
+ for (int i = 0; i < aPolesArray->size(); ++i)
+ {
+ std::cout << "(" << aPolesArray->pnt(i)->x() << ", " << aPolesArray->pnt(i)->y() << ")," << std::endl;
+ }
+
+ std::cout << "\nWeight\n";
+ for (int i = 0; i < aWeightsArray->size(); ++i)
+ {
+ std::cout << aWeightsArray->value(i) << ", ";
+ }
+ std::cout << std::endl;
+
+ std::cout << "\nKnot:\n";
+ for (int i = 0; i < aKnotsArray->size(); ++i)
+ {
+ std::cout << aKnotsArray->value(i) << ", ";
+ }
+ std::cout << std::endl;
+
+ std::cout << "\nMulti:\n";
+ for (int i = 0; i < aMultsArray->size() - 1; ++i)
+ {
+ std::cout << aMultsArray->value(i) << ", ";
+ }
+ std::cout << aMultsArray->value(aMultsArray->size() - 1) << std::endl;
+#endif
+
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aBSplineFeature->attribute(SketchPlugin_BSpline::START_ID()))->setValue(aPolesArray->pnt(0));
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
{
auto aCircle = anEdge->circle();
auto aCenter = aCircle->center();
- auto aCircleFeature = aSketch->addFeature(SketchPlugin_Circle::ID());
+ auto aCircleFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
auto aMinorR = anEllipse->minorRadius();
auto aCenter = anEllipse->center();
- auto anEllipseFeature = aSketch->addFeature(SketchPlugin_Ellipse::ID());
+ auto anEllipseFeature = theSketch->addFeature(SketchPlugin_Ellipse::ID());
std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(anEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID()));
auto aStartP = anEdge->firstPoint();
auto anEndP = anEdge->lastPoint();
- auto aLineFeature = aSketch->addFeature(SketchPlugin_Line::ID());
+ auto aLineFeature = theSketch->addFeature(SketchPlugin_Line::ID());
std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(aLineFeature->attribute(SketchPlugin_Line::START_ID()));