From 9d10f3e026251b965fe91167a2980c85ee2679da Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 13 Aug 2015 10:06:43 -0300 Subject: [PATCH] Draft: Added text support to new DXF importer - issue #2205 --- src/Mod/Draft/App/DraftDxf.cpp | 45 ++++++++++++++++++++++++++++++---- src/Mod/Draft/App/DraftDxf.h | 3 ++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Mod/Draft/App/DraftDxf.cpp b/src/Mod/Draft/App/DraftDxf.cpp index 4a3558ae2..b8a63ed68 100644 --- a/src/Mod/Draft/App/DraftDxf.cpp +++ b/src/Mod/Draft/App/DraftDxf.cpp @@ -42,8 +42,10 @@ #include #include +#include #include #include +#include #include using namespace DraftUtils; @@ -127,7 +129,13 @@ void DraftDxfRead::OnReadEllipse(const double* c, double major_radius, double mi void DraftDxfRead::OnReadText(const double *point, const double height, const char* text) { - // not yet implemented + Base::Vector3d pt(point[0],point[1],point[2]); + if(LayerName().substr(0, 6) != "BLOCKS") { + App::Annotation *pcFeature = (App::Annotation *)document->addObject("App::Annotation", "Text"); + pcFeature->LabelText.setValue(Deformat(text)); + pcFeature->Position.setValue(pt); + } + else std::cout << "skipped text in block: " << LayerName() << std::endl; } @@ -178,9 +186,39 @@ void DraftDxfRead::AddObject(Part::TopoShape *shape) } +const char* DraftDxfRead::Deformat(const char* text) +{ + // this function removes DXF formatting from texts + std::stringstream ss; + bool escape = false; // turned on when finding an escape character + bool longescape = false; // turned on for certain escape codes that expect additional chars + for(unsigned int i = 0; i > ::const_iterator i = layers.begin(); i != layers.end(); ++i) { BRep_Builder builder; @@ -189,18 +227,15 @@ void DraftDxfRead::AddGraphics() const std::string k = i->first; std::vector v = i->second; if(k.substr(0, 6) != "BLOCKS") { - std::cout << "joining:" << k << " size " << v.size() << std::endl; for(std::vector::const_iterator j = v.begin(); j != v.end(); ++j) { const TopoDS_Shape& sh = (*j)->_Shape; if (!sh.IsNull()) builder.Add(comp, sh); } if (!comp.IsNull()) { - std::cout << "valid shape" << std::endl; Part::Feature *pcFeature = (Part::Feature *)document->addObject("Part::Feature", k.c_str()); pcFeature->Shape.setValue(comp); } - else std::cout << "invalid shape" << std::endl; } } } diff --git a/src/Mod/Draft/App/DraftDxf.h b/src/Mod/Draft/App/DraftDxf.h index c9ab0f834..c289d45e5 100644 --- a/src/Mod/Draft/App/DraftDxf.h +++ b/src/Mod/Draft/App/DraftDxf.h @@ -46,7 +46,8 @@ namespace DraftUtils void AddGraphics() const; // FreeCAD-specific functions - void AddObject(Part::TopoShape *shape); + void AddObject(Part::TopoShape *shape); //Called by OnRead functions to add Part objects + const char* Deformat(const char* text); // Removes DXF formating from texts protected: App::Document *document;