+
+std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
+{
+ FeaturePtr aBase = feature();
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+
+ return thePoint->to2D(aC->pnt(), aX->dir(), aY);
+}
+
+//--------------------------------------------------------------------------------------
+
+void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aDocName = theDumper.name(aBase->document());
+
+ AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+ if (anExternal->value()) {
+ theDumper << aBase << " = model.addSketch(" << aDocName <<
+ ", " << anExternal << ")" << std::endl;
+ } else {
+ // Sketch is base on a plane.
+ std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
+ std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
+ std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
+
+ // Check the plane is coordinate plane
+ std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
+ if(anExternal->context()) { // checking for selected planes
+ if (!aPlaneName.empty()
+ && anExternal->context()->data()
+ && anExternal->context()->data()->name() == aPlaneName) {
+ // dump sketch based on coordinate plane
+ theDumper << aBase << " = model.addSketch(" << aDocName
+ << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
+ } else { // some other plane
+ theDumper << aBase << " = model.addSketch(" << aDocName <<
+ ", " << anExternal<< ")" << std::endl;
+ }
+ } else {
+ if (aPlaneName.empty()) {
+ // needs import additional module
+ theDumper.importModule("GeomAPI");
+ // dump plane parameters
+ const std::string& aSketchName = theDumper.name(aBase);
+ std::string anOriginName = aSketchName + "_origin";
+ std::string aNormalName = aSketchName + "_norm";
+ std::string aDirXName = aSketchName + "_dirx";
+ // use "\n" instead of std::endl to avoid automatic dumping sketch here
+ // and then dumplicate dumping it in the next line
+ theDumper << anOriginName << " = " << anOrigin << "\n"
+ << aNormalName << " = " << aNormal << "\n"
+ << aDirXName << " = " << aDirX << "\n";
+ // dump sketch based on arbitrary plane
+ theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
+ << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
+ } else {
+ // dump sketch based on coordinate plane
+ theDumper << aBase << " = model.addSketch(" << aDocName
+ << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
+ }
+ }
+ }
+
+ // dump sketch's subfeatures
+ CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
+ theDumper.processSubs(aCompFeat, true);
+}