From: asozinov Date: Mon, 8 Apr 2024 17:14:49 +0000 (+0100) Subject: Sketch fix X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Ftlpr%2F25%2Fhead;p=modules%2Fshaper.git Sketch fix Error license message moved to console --- diff --git a/src/DXFPlugin/DXFPlugin_Import.cpp b/src/DXFPlugin/DXFPlugin_Import.cpp index cbe44388b..d8a20823e 100644 --- a/src/DXFPlugin/DXFPlugin_Import.cpp +++ b/src/DXFPlugin/DXFPlugin_Import.cpp @@ -28,12 +28,15 @@ #include #include #include +#include #include > #include > #include #include +#include #include #include +#include #include #include @@ -90,6 +93,10 @@ void DXFPlugin_Import::initAttributes() 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() @@ -178,6 +185,11 @@ void DXFPlugin_Import::execute() 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()); @@ -196,7 +208,36 @@ void DXFPlugin_Import::execute() 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(anObj); + } + else + { + DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument(); + DocumentPtr aPart = ModelAPI_Session::get()->activeDocument(); + FeaturePtr aSkFeature = aPart->addFeature("Sketch"); + std::shared_ptr anOrigin = std::dynamic_pointer_cast( + aSkFeature->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + + anOrigin->setX(0); + anOrigin->setY(0); + anOrigin->setZ(0); + + std::shared_ptr aDirX = std::dynamic_pointer_cast( + aSkFeature->data()->attribute(SketchPlugin_Sketch::DIRX_ID())); + aDirX->setValue(1, 0, 0); + + std::shared_ptr aNorm = std::dynamic_pointer_cast( + aSkFeature->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + aNorm->setValue(0, 0, 1); + + aSketch = std::dynamic_pointer_cast(aSkFeature); + } + auto aShapes = anAlgo.ConvertToSketchElements(aShape, aSketch); isOk = false; } // From list of edges create sketch primitives diff --git a/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.cpp b/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.cpp index 1adad70c1..7879058e6 100644 --- a/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.cpp +++ b/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.cpp @@ -64,6 +64,12 @@ #include #include +#define _DEBUG + +#ifdef _DEBUG +#include +#endif // _DEBUG + DXFPlugin_ImportAlgoAPI::DXFPlugin_ImportAlgoAPI(Handle(TDocStd_Document) theDoc) { myDoc = Handle(TDocStd_Document)(theDoc); @@ -127,23 +133,8 @@ std::vector DXFPlugin_ImportAlgoAPI::color(const GeomShapePtr theShape) con return std::vector(); } -std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const TopoDS_Shape theShape) const +std::list 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(feat); - break; - } - - if (!aSketch) - return std::list(); - int aNb = 0; std::list aShapes; for (TopExp_Explorer anExp(theShape, TopAbs_EDGE); anExp.More(); anExp.Next()) @@ -162,7 +153,7 @@ std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const T 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 aStartAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(anArcFeature->attribute(SketchPlugin_Arc::START_ID())); @@ -176,6 +167,7 @@ std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const T aCenterAttr->setValue(aCenter->x(), aCenter->y()); anArcFeature->execute(); } + // BSpline importred incorrect if (anEdge->isBSpline()) { const TopoDS_Shape& aShape = anEdge->impl(); @@ -187,7 +179,8 @@ std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const T 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(aBSplineFeature->attribute(SketchPlugin_BSpline::POLES_ID())); @@ -196,21 +189,67 @@ std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const T 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( aBSplineFeature->attribute(SketchPlugin_BSpline::START_ID()))->setValue(aPolesArray->pnt(0)); std::dynamic_pointer_cast( @@ -221,7 +260,7 @@ std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const T { 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 aStartAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID())); @@ -238,7 +277,7 @@ std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const T 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 aCenterAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(anEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID())); @@ -259,7 +298,7 @@ std::list DXFPlugin_ImportAlgoAPI::ConvertToSketchElements(const T 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 aStartAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(aLineFeature->attribute(SketchPlugin_Line::START_ID())); diff --git a/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.h b/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.h index 548bff84b..f8023f8b4 100644 --- a/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.h +++ b/src/DXFPlugin/DXFPlugin_ImportAlgoAPI.h @@ -25,6 +25,7 @@ #include #include +class ModelAPI_CompositeFeature; /** * \class DXFPlugin_ImportAlgoAPI * \ingroup DataAlgo @@ -53,7 +54,7 @@ public: /// Get shape color std::vector color(const GeomShapePtr theShape) const; - std::list ConvertToSketchElements(const TopoDS_Shape theShape) const; + std::list ConvertToSketchElements(const TopoDS_Shape theShape, std::shared_ptr theSketch) const; private: Handle(TDocStd_Document) myDoc; ///< Handle to the document for transferring diff --git a/src/DXFPlugin/plugin-DXF.xml b/src/DXFPlugin/plugin-DXF.xml index c75d721f1..0db518089 100644 --- a/src/DXFPlugin/plugin-DXF.xml +++ b/src/DXFPlugin/plugin-DXF.xml @@ -53,17 +53,14 @@ - - - + + + + diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index dd9746a53..9b6af677b 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -247,9 +247,9 @@ void ModuleBase_IModule::loadProprietaryPlugins() if (!ModelAPI_Session::get()->checkLicense(*itP)) // Check if exist OCCLICENSE_FILE env if (!getenv("OCCLICENSE_FILE")) - Events_InfoMessage(*itP, "Environment variable %1 for %2 plugin is not set!").arg("OCCLICENSE_FILE").arg(*itP).send(); + std::cout << "Environment variable " << "OCCLICENSE_FILE" << " for " << *itP << " plugin is not set!" << std::endl; else - Events_InfoMessage(*itP, "License of %1 plugin is not valid or not exist!").arg(*itP).send(); + std::cout << "License of " << *itP << " plugin is not valid or not exist!" << std::endl; } }