Drawing: Apply clang format
This commit is contained in:
@@ -26,7 +26,8 @@
|
||||
#include "PageGroup.h"
|
||||
|
||||
|
||||
namespace Drawing {
|
||||
namespace Drawing
|
||||
{
|
||||
extern PyObject* initModule();
|
||||
}
|
||||
|
||||
@@ -36,9 +37,9 @@ PyMOD_INIT_FUNC(Drawing)
|
||||
// load dependent module
|
||||
try {
|
||||
Base::Interpreter().loadModule("Part");
|
||||
//Base::Interpreter().loadModule("Mesh");
|
||||
// Base::Interpreter().loadModule("Mesh");
|
||||
}
|
||||
catch(const Base::Exception& e) {
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_ImportError, e.what());
|
||||
PyMOD_Return(nullptr);
|
||||
}
|
||||
@@ -49,7 +50,7 @@ PyMOD_INIT_FUNC(Drawing)
|
||||
// NOTE: To finish the initialization of our own type objects we must
|
||||
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
|
||||
// This function is responsible for adding inherited slots from a type's base class.
|
||||
|
||||
// clang-format off
|
||||
Drawing::FeaturePage ::init();
|
||||
Drawing::FeatureView ::init();
|
||||
Drawing::FeatureViewPart ::init();
|
||||
@@ -61,6 +62,6 @@ PyMOD_INIT_FUNC(Drawing)
|
||||
Drawing::FeatureViewSymbol ::init();
|
||||
Drawing::FeatureClip ::init();
|
||||
Drawing::FeatureViewSpreadsheet ::init();
|
||||
|
||||
// clang-format on
|
||||
PyMOD_Return(mod);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <boost/regex.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
@@ -36,85 +36,97 @@
|
||||
|
||||
|
||||
using namespace std;
|
||||
using Part::TopoShapePy;
|
||||
using Part::TopoShape;
|
||||
using Part::TopoShapePy;
|
||||
|
||||
namespace Drawing {
|
||||
namespace Drawing
|
||||
{
|
||||
|
||||
/** Copies a Python dictionary of Python strings to a C++ container.
|
||||
*
|
||||
* After the function call, the key-value pairs of the Python
|
||||
* dictionary are copied into the target buffer as C++ pairs
|
||||
* (pair<string, string>).
|
||||
*
|
||||
* @param sourceRange is a Python dictionary (Py::Dict). Both, the
|
||||
* keys and the values must be Python strings.
|
||||
*
|
||||
* @param targetIt refers to where the data should be inserted. Must
|
||||
* be of concept output iterator.
|
||||
*/
|
||||
template<typename OutputIt>
|
||||
void copy(Py::Dict sourceRange, OutputIt targetIt)
|
||||
{
|
||||
/** Copies a Python dictionary of Python strings to a C++ container.
|
||||
*
|
||||
* After the function call, the key-value pairs of the Python
|
||||
* dictionary are copied into the target buffer as C++ pairs
|
||||
* (pair<string, string>).
|
||||
*
|
||||
* @param sourceRange is a Python dictionary (Py::Dict). Both, the
|
||||
* keys and the values must be Python strings.
|
||||
*
|
||||
* @param targetIt refers to where the data should be inserted. Must
|
||||
* be of concept output iterator.
|
||||
*/
|
||||
template<typename OutputIt>
|
||||
void copy(Py::Dict sourceRange, OutputIt targetIt)
|
||||
{
|
||||
string key;
|
||||
string value;
|
||||
|
||||
for (const auto& keyPy : sourceRange.keys()) {
|
||||
key = Py::String(keyPy);
|
||||
value = Py::String(sourceRange[keyPy]);
|
||||
*targetIt = {key, value};
|
||||
++targetIt;
|
||||
key = Py::String(keyPy);
|
||||
value = Py::String(sourceRange[keyPy]);
|
||||
*targetIt = {key, value};
|
||||
++targetIt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
class Module: public Py::ExtensionModule<Module>
|
||||
{
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("Drawing")
|
||||
Module()
|
||||
: Py::ExtensionModule<Module>("Drawing")
|
||||
{
|
||||
add_varargs_method("project",&Module::project,
|
||||
"[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = project(TopoShape[,App.Vector Direction, string type])\n"
|
||||
" -- Project a shape and return the visible/invisible parts of it."
|
||||
);
|
||||
add_varargs_method("projectEx",&Module::projectEx,
|
||||
"[V,V1,VN,VO,VI,H,H1,HN,HO,HI] = projectEx(TopoShape[,App.Vector Direction, string type])\n"
|
||||
" -- Project a shape and return the all parts of it."
|
||||
);
|
||||
add_keyword_method("projectToSVG",&Module::projectToSVG,
|
||||
"string = projectToSVG(TopoShape[, App.Vector direction, string type, float tolerance, dict vStyle, dict v0Style, dict v1Style, dict hStyle, dict h0Style, dict h1Style])\n"
|
||||
" -- Project a shape and return the SVG representation as string."
|
||||
);
|
||||
add_varargs_method("projectToDXF",&Module::projectToDXF,
|
||||
"string = projectToDXF(TopoShape[,App.Vector Direction, string type])\n"
|
||||
" -- Project a shape and return the DXF representation as string."
|
||||
);
|
||||
add_varargs_method("removeSvgTags",&Module::removeSvgTags,
|
||||
add_varargs_method("project",
|
||||
&Module::project,
|
||||
"[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = "
|
||||
"project(TopoShape[,App.Vector Direction, string type])\n"
|
||||
" -- Project a shape and return the visible/invisible parts of it.");
|
||||
add_varargs_method("projectEx",
|
||||
&Module::projectEx,
|
||||
"[V,V1,VN,VO,VI,H,H1,HN,HO,HI] = projectEx(TopoShape[,App.Vector "
|
||||
"Direction, string type])\n"
|
||||
" -- Project a shape and return the all parts of it.");
|
||||
add_keyword_method(
|
||||
"projectToSVG",
|
||||
&Module::projectToSVG,
|
||||
"string = projectToSVG(TopoShape[, App.Vector direction, string type, float tolerance, "
|
||||
"dict vStyle, dict v0Style, dict v1Style, dict hStyle, dict h0Style, dict h1Style])\n"
|
||||
" -- Project a shape and return the SVG representation as string.");
|
||||
add_varargs_method("projectToDXF",
|
||||
&Module::projectToDXF,
|
||||
"string = projectToDXF(TopoShape[,App.Vector Direction, string type])\n"
|
||||
" -- Project a shape and return the DXF representation as string.");
|
||||
add_varargs_method(
|
||||
"removeSvgTags",
|
||||
&Module::removeSvgTags,
|
||||
"string = removeSvgTags(string) -- Removes the opening and closing svg tags\n"
|
||||
"and other metatags from a svg code, making it embeddable"
|
||||
);
|
||||
initialize("This module is the Drawing module."); // register with Python
|
||||
"and other metatags from a svg code, making it embeddable");
|
||||
initialize("This module is the Drawing module.");// register with Python
|
||||
}
|
||||
|
||||
virtual ~Module() {}
|
||||
virtual ~Module()
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual Py::Object invoke_method_varargs(void *method_def, const Py::Tuple &args)
|
||||
virtual Py::Object invoke_method_varargs(void* method_def, const Py::Tuple& args)
|
||||
{
|
||||
try {
|
||||
return Py::ExtensionModule<Module>::invoke_method_varargs(method_def, args);
|
||||
}
|
||||
catch (const Standard_Failure &e) {
|
||||
catch (const Standard_Failure& e) {
|
||||
std::string str;
|
||||
Standard_CString msg = e.GetMessageString();
|
||||
str += typeid(e).name();
|
||||
str += " ";
|
||||
if (msg) {str += msg;}
|
||||
else {str += "No OCCT Exception Message";}
|
||||
if (msg) {
|
||||
str += msg;
|
||||
}
|
||||
else {
|
||||
str += "No OCCT Exception Message";
|
||||
}
|
||||
Base::Console().Error("%s\n", str.c_str());
|
||||
throw Py::Exception(Part::PartExceptionOCCError, str);
|
||||
}
|
||||
catch (const Base::Exception &e) {
|
||||
catch (const Base::Exception& e) {
|
||||
std::string str;
|
||||
str += "FreeCAD exception thrown (";
|
||||
str += e.what();
|
||||
@@ -122,7 +134,7 @@ private:
|
||||
e.ReportException();
|
||||
throw Py::RuntimeError(str);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
catch (const std::exception& e) {
|
||||
std::string str;
|
||||
str += "C++ exception thrown (";
|
||||
str += e.what();
|
||||
@@ -133,53 +145,63 @@ private:
|
||||
}
|
||||
Py::Object project(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *pcObjShape;
|
||||
PyObject *pcObjDir=nullptr;
|
||||
PyObject* pcObjShape;
|
||||
PyObject* pcObjDir = nullptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args.ptr(), "O!|O!",
|
||||
&(Part::TopoShapePy::Type), &pcObjShape,
|
||||
&(Base::VectorPy::Type), &pcObjDir))
|
||||
if (!PyArg_ParseTuple(args.ptr(),
|
||||
"O!|O!",
|
||||
&(Part::TopoShapePy::Type),
|
||||
&pcObjShape,
|
||||
&(Base::VectorPy::Type),
|
||||
&pcObjDir)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
Part::TopoShapePy* pShape = static_cast<Part::TopoShapePy*>(pcObjShape);
|
||||
Base::Vector3d Vector(0,0,1);
|
||||
if (pcObjDir)
|
||||
Base::Vector3d Vector(0, 0, 1);
|
||||
if (pcObjDir) {
|
||||
Vector = *static_cast<Base::VectorPy*>(pcObjDir)->getVectorPtr();
|
||||
}
|
||||
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),Vector);
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), Vector);
|
||||
|
||||
Py::List list;
|
||||
list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.V)) , true));
|
||||
list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.V)), true));
|
||||
list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.V1)), true));
|
||||
list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.H)) , true));
|
||||
list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.H)), true));
|
||||
list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.H1)), true));
|
||||
|
||||
return list;
|
||||
}
|
||||
Py::Object projectEx(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *pcObjShape;
|
||||
PyObject *pcObjDir=nullptr;
|
||||
PyObject* pcObjShape;
|
||||
PyObject* pcObjDir = nullptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args.ptr(), "O!|O!",
|
||||
&(TopoShapePy::Type), &pcObjShape,
|
||||
&(Base::VectorPy::Type), &pcObjDir))
|
||||
if (!PyArg_ParseTuple(args.ptr(),
|
||||
"O!|O!",
|
||||
&(TopoShapePy::Type),
|
||||
&pcObjShape,
|
||||
&(Base::VectorPy::Type),
|
||||
&pcObjDir)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
|
||||
Base::Vector3d Vector(0,0,1);
|
||||
if (pcObjDir)
|
||||
Base::Vector3d Vector(0, 0, 1);
|
||||
if (pcObjDir) {
|
||||
Vector = *static_cast<Base::VectorPy*>(pcObjDir)->getVectorPtr();
|
||||
}
|
||||
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),Vector);
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), Vector);
|
||||
|
||||
Py::List list;
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V)) , true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V1)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VN)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VO)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VI)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H)) , true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H1)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HN)), true));
|
||||
list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HO)), true));
|
||||
@@ -189,140 +211,165 @@ private:
|
||||
}
|
||||
|
||||
Py::Object projectToSVG(const Py::Tuple& args, const Py::Dict& keys)
|
||||
{
|
||||
static const std::array<const char *, 11> argNames {"topoShape",
|
||||
"direction",
|
||||
"type",
|
||||
"tolerance",
|
||||
"vStyle",
|
||||
"v0Style",
|
||||
"v1Style",
|
||||
"hStyle",
|
||||
"h0Style",
|
||||
"h1Style",
|
||||
nullptr};
|
||||
PyObject *pcObjShape = nullptr;
|
||||
PyObject *pcObjDir = nullptr;
|
||||
const char *extractionTypePy = nullptr;
|
||||
ProjectionAlgos::ExtractionType extractionType = ProjectionAlgos::Plain;
|
||||
const float tol = 0.1f;
|
||||
PyObject* vStylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes vStyle;
|
||||
PyObject* v0StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes v0Style;
|
||||
PyObject* v1StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes v1Style;
|
||||
PyObject* hStylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes hStyle;
|
||||
PyObject* h0StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes h0Style;
|
||||
PyObject* h1StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes h1Style;
|
||||
|
||||
// Get the arguments
|
||||
{
|
||||
static const std::array<const char*, 11> argNames {"topoShape",
|
||||
"direction",
|
||||
"type",
|
||||
"tolerance",
|
||||
"vStyle",
|
||||
"v0Style",
|
||||
"v1Style",
|
||||
"hStyle",
|
||||
"h0Style",
|
||||
"h1Style",
|
||||
nullptr};
|
||||
PyObject* pcObjShape = nullptr;
|
||||
PyObject* pcObjDir = nullptr;
|
||||
const char* extractionTypePy = nullptr;
|
||||
ProjectionAlgos::ExtractionType extractionType = ProjectionAlgos::Plain;
|
||||
const float tol = 0.1f;
|
||||
PyObject* vStylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes vStyle;
|
||||
PyObject* v0StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes v0Style;
|
||||
PyObject* v1StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes v1Style;
|
||||
PyObject* hStylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes hStyle;
|
||||
PyObject* h0StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes h0Style;
|
||||
PyObject* h1StylePy = nullptr;
|
||||
ProjectionAlgos::XmlAttributes h1Style;
|
||||
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(
|
||||
args.ptr(), keys.ptr(),
|
||||
"O!|O!sfOOOOOO",
|
||||
argNames,
|
||||
&(TopoShapePy::Type), &pcObjShape,
|
||||
&(Base::VectorPy::Type), &pcObjDir,
|
||||
&extractionTypePy, &tol,
|
||||
&vStylePy, &v0StylePy, &v1StylePy,
|
||||
&hStylePy, &h0StylePy, &h1StylePy))
|
||||
|
||||
throw Py::Exception();
|
||||
// Get the arguments
|
||||
|
||||
// Convert all arguments into the right format
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(),
|
||||
keys.ptr(),
|
||||
"O!|O!sfOOOOOO",
|
||||
argNames,
|
||||
&(TopoShapePy::Type),
|
||||
&pcObjShape,
|
||||
&(Base::VectorPy::Type),
|
||||
&pcObjDir,
|
||||
&extractionTypePy,
|
||||
&tol,
|
||||
&vStylePy,
|
||||
&v0StylePy,
|
||||
&v1StylePy,
|
||||
&hStylePy,
|
||||
&h0StylePy,
|
||||
&h1StylePy)) {
|
||||
|
||||
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
|
||||
|
||||
Base::Vector3d directionVector(0,0,1);
|
||||
if (pcObjDir)
|
||||
directionVector = static_cast<Base::VectorPy*>(pcObjDir)->value();
|
||||
|
||||
if (extractionTypePy && string(extractionTypePy) == "ShowHiddenLines")
|
||||
extractionType = ProjectionAlgos::WithHidden;
|
||||
|
||||
if (vStylePy)
|
||||
copy(Py::Dict(vStylePy), inserter(vStyle, vStyle.begin()));
|
||||
if (v0StylePy)
|
||||
copy(Py::Dict(v0StylePy), inserter(v0Style, v0Style.begin()));
|
||||
if (v1StylePy)
|
||||
copy(Py::Dict(v1StylePy), inserter(v1Style, v1Style.begin()));
|
||||
if (hStylePy)
|
||||
copy(Py::Dict(hStylePy), inserter(hStyle, hStyle.begin()));
|
||||
if (h0StylePy)
|
||||
copy(Py::Dict(h0StylePy), inserter(h0Style, h0Style.begin()));
|
||||
if (h1StylePy)
|
||||
copy(Py::Dict(h1StylePy), inserter(h1Style, h1Style.begin()));
|
||||
|
||||
// Execute the SVG generation
|
||||
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),
|
||||
directionVector);
|
||||
Py::String result(Alg.getSVG(extractionType, tol,
|
||||
vStyle, v0Style, v1Style,
|
||||
hStyle, h0Style, h1Style));
|
||||
return result;
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
// Convert all arguments into the right format
|
||||
|
||||
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
|
||||
|
||||
Base::Vector3d directionVector(0, 0, 1);
|
||||
if (pcObjDir) {
|
||||
directionVector = static_cast<Base::VectorPy*>(pcObjDir)->value();
|
||||
}
|
||||
|
||||
if (extractionTypePy && string(extractionTypePy) == "ShowHiddenLines") {
|
||||
extractionType = ProjectionAlgos::WithHidden;
|
||||
}
|
||||
|
||||
if (vStylePy) {
|
||||
copy(Py::Dict(vStylePy), inserter(vStyle, vStyle.begin()));
|
||||
}
|
||||
if (v0StylePy) {
|
||||
copy(Py::Dict(v0StylePy), inserter(v0Style, v0Style.begin()));
|
||||
}
|
||||
if (v1StylePy) {
|
||||
copy(Py::Dict(v1StylePy), inserter(v1Style, v1Style.begin()));
|
||||
}
|
||||
if (hStylePy) {
|
||||
copy(Py::Dict(hStylePy), inserter(hStyle, hStyle.begin()));
|
||||
}
|
||||
if (h0StylePy) {
|
||||
copy(Py::Dict(h0StylePy), inserter(h0Style, h0Style.begin()));
|
||||
}
|
||||
if (h1StylePy) {
|
||||
copy(Py::Dict(h1StylePy), inserter(h1Style, h1Style.begin()));
|
||||
}
|
||||
|
||||
// Execute the SVG generation
|
||||
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), directionVector);
|
||||
Py::String result(
|
||||
Alg.getSVG(extractionType, tol, vStyle, v0Style, v1Style, hStyle, h0Style, h1Style));
|
||||
return result;
|
||||
}
|
||||
|
||||
Py::Object projectToDXF(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *pcObjShape;
|
||||
PyObject *pcObjDir=nullptr;
|
||||
const char *type=nullptr;
|
||||
float scale=1.0f;
|
||||
float tol=0.1f;
|
||||
PyObject* pcObjShape;
|
||||
PyObject* pcObjDir = nullptr;
|
||||
const char* type = nullptr;
|
||||
float scale = 1.0f;
|
||||
float tol = 0.1f;
|
||||
|
||||
if (!PyArg_ParseTuple(args.ptr(), "O!|O!sff",
|
||||
&(TopoShapePy::Type), &pcObjShape,
|
||||
&(Base::VectorPy::Type), &pcObjDir, &type, &scale, &tol))
|
||||
if (!PyArg_ParseTuple(args.ptr(),
|
||||
"O!|O!sff",
|
||||
&(TopoShapePy::Type),
|
||||
&pcObjShape,
|
||||
&(Base::VectorPy::Type),
|
||||
&pcObjDir,
|
||||
&type,
|
||||
&scale,
|
||||
&tol)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
|
||||
Base::Vector3d Vector(0,0,1);
|
||||
if (pcObjDir)
|
||||
Base::Vector3d Vector(0, 0, 1);
|
||||
if (pcObjDir) {
|
||||
Vector = static_cast<Base::VectorPy*>(pcObjDir)->value();
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),Vector);
|
||||
}
|
||||
ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), Vector);
|
||||
|
||||
bool hidden = false;
|
||||
if (type && std::string(type) == "ShowHiddenLines")
|
||||
if (type && std::string(type) == "ShowHiddenLines") {
|
||||
hidden = true;
|
||||
}
|
||||
|
||||
Py::String result(Alg.getDXF(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale, tol));
|
||||
Py::String result(
|
||||
Alg.getDXF(hidden ? ProjectionAlgos::WithHidden : ProjectionAlgos::Plain, scale, tol));
|
||||
return result;
|
||||
}
|
||||
Py::Object removeSvgTags(const Py::Tuple& args)
|
||||
{
|
||||
const char* svgcode;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s",&svgcode))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s", &svgcode)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string svg(svgcode);
|
||||
std::string empty = "";
|
||||
std::string endline = "--endOfLine--";
|
||||
std::string linebreak = "\\n";
|
||||
// removing linebreaks for regex to work
|
||||
boost::regex e1 ("\\n");
|
||||
boost::regex e1("\\n");
|
||||
svg = boost::regex_replace(svg, e1, endline);
|
||||
// removing starting xml definition
|
||||
boost::regex e2 ("<\\?xml.*?\\?>");
|
||||
boost::regex e2("<\\?xml.*?\\?>");
|
||||
svg = boost::regex_replace(svg, e2, empty);
|
||||
// removing starting svg tag
|
||||
boost::regex e3 ("<svg.*?>");
|
||||
boost::regex e3("<svg.*?>");
|
||||
svg = boost::regex_replace(svg, e3, empty);
|
||||
// removing sodipodi tags -- DANGEROUS, some sodipodi tags are single, better leave it
|
||||
//boost::regex e4 ("<sodipodi.*?>");
|
||||
//svg = boost::regex_replace(svg, e4, empty);
|
||||
// boost::regex e4 ("<sodipodi.*?>");
|
||||
// svg = boost::regex_replace(svg, e4, empty);
|
||||
// removing metadata tags
|
||||
boost::regex e5 ("<metadata.*?</metadata>");
|
||||
boost::regex e5("<metadata.*?</metadata>");
|
||||
svg = boost::regex_replace(svg, e5, empty);
|
||||
// removing closing svg tags
|
||||
boost::regex e6 ("</svg>");
|
||||
boost::regex e6("</svg>");
|
||||
svg = boost::regex_replace(svg, e6, empty);
|
||||
// restoring linebreaks
|
||||
boost::regex e7 ("--endOfLine--");
|
||||
boost::regex e7("--endOfLine--");
|
||||
svg = boost::regex_replace(svg, e7, linebreak);
|
||||
Py::String result(svg);
|
||||
return result;
|
||||
@@ -334,4 +381,4 @@ PyObject* initModule()
|
||||
return Base::Interpreter().addModule(new Module);
|
||||
}
|
||||
|
||||
} // namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
@@ -22,34 +22,34 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <cmath>
|
||||
# include <sstream>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
# include <Approx_Curve3d.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <BRepAdaptor_Curve.hxx>
|
||||
# include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
# include <BRepLProp_CLProps.hxx>
|
||||
# include <Geom_BezierCurve.hxx>
|
||||
# include <Geom_BSplineCurve.hxx>
|
||||
# include <GeomConvert_BSplineCurveKnotSplitting.hxx>
|
||||
# include <GeomConvert_BSplineCurveToBezierCurve.hxx>
|
||||
# include <gp_Circ.hxx>
|
||||
# include <gp_Dir.hxx>
|
||||
# include <gp_Elips.hxx>
|
||||
# include <gp_Pnt.hxx>
|
||||
# include <gp_Vec.hxx>
|
||||
# include <Poly_Polygon3D.hxx>
|
||||
# include <Standard_Failure.hxx>
|
||||
# include <Standard_Version.hxx>
|
||||
# include <TColStd_Array1OfReal.hxx>
|
||||
# include <TopExp_Explorer.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <TopoDS_Edge.hxx>
|
||||
# include <TopoDS_Shape.hxx>
|
||||
# if OCC_VERSION_HEX < 0x070600
|
||||
# include <BRepAdaptor_HCurve.hxx>
|
||||
# endif
|
||||
#include <Approx_Curve3d.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepLProp_CLProps.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <GeomConvert_BSplineCurveKnotSplitting.hxx>
|
||||
#include <GeomConvert_BSplineCurveToBezierCurve.hxx>
|
||||
#include <Geom_BSplineCurve.hxx>
|
||||
#include <Geom_BezierCurve.hxx>
|
||||
#include <Poly_Polygon3D.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Elips.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
#include <BRepAdaptor_HCurve.hxx>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <Base/Tools.h>
|
||||
@@ -67,17 +67,17 @@ using namespace std;
|
||||
|
||||
TopoDS_Edge DrawingOutput::asCircle(const BRepAdaptor_Curve& c) const
|
||||
{
|
||||
double curv=0;
|
||||
double curv = 0;
|
||||
gp_Pnt pnt, center;
|
||||
|
||||
try {
|
||||
// approximate the circle center from three positions
|
||||
BRepLProp_CLProps prop(c,c.FirstParameter(),2,Precision::Confusion());
|
||||
BRepLProp_CLProps prop(c, c.FirstParameter(), 2, Precision::Confusion());
|
||||
curv += prop.Curvature();
|
||||
prop.CentreOfCurvature(pnt);
|
||||
center.ChangeCoord().Add(pnt.Coord());
|
||||
|
||||
prop.SetParameter(0.5*(c.FirstParameter()+c.LastParameter()));
|
||||
prop.SetParameter(0.5 * (c.FirstParameter() + c.LastParameter()));
|
||||
curv += prop.Curvature();
|
||||
prop.CentreOfCurvature(pnt);
|
||||
center.ChangeCoord().Add(pnt.Coord());
|
||||
@@ -106,8 +106,9 @@ TopoDS_Edge DrawingOutput::asCircle(const BRepAdaptor_Curve& c) const
|
||||
for (int i = nodes.Lower(); i <= nodes.Upper(); i++) {
|
||||
gp_Pnt p = nodes(i);
|
||||
double dist = p.Distance(center);
|
||||
if (std::abs(dist - radius) > 0.001)
|
||||
if (std::abs(dist - radius) > 0.001) {
|
||||
return TopoDS_Edge();
|
||||
}
|
||||
}
|
||||
|
||||
gp_Circ circ;
|
||||
@@ -142,7 +143,7 @@ TopoDS_Edge DrawingOutput::asBSpline(const BRepAdaptor_Curve& c, int maxDegree)
|
||||
Standard_Integer maxSegment = 50;
|
||||
Handle(BRepAdaptor_HCurve) hCurve = new BRepAdaptor_HCurve(c);
|
||||
// approximate the curve using a tolerance
|
||||
Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C0,maxSegment,maxDegree);
|
||||
Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree);
|
||||
if (approx.IsDone() && approx.HasResult()) {
|
||||
// have the result
|
||||
Handle(Geom_BSplineCurve) spline = approx.Curve();
|
||||
@@ -154,15 +155,14 @@ TopoDS_Edge DrawingOutput::asBSpline(const BRepAdaptor_Curve& c, int maxDegree)
|
||||
}
|
||||
|
||||
SVGOutput::SVGOutput()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
std::string SVGOutput::exportEdges(const TopoDS_Shape& input)
|
||||
{
|
||||
std::stringstream result;
|
||||
|
||||
TopExp_Explorer edges(input, TopAbs_EDGE);
|
||||
for (int i = 1 ; edges.More(); edges.Next(),i++) {
|
||||
for (int i = 1; edges.More(); edges.Next(), i++) {
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(edges.Current());
|
||||
BRepAdaptor_Curve adapt(edge);
|
||||
if (adapt.GetType() == GeomAbs_Circle) {
|
||||
@@ -172,14 +172,14 @@ std::string SVGOutput::exportEdges(const TopoDS_Shape& input)
|
||||
printEllipse(adapt, i, result);
|
||||
}
|
||||
else if (adapt.GetType() == GeomAbs_BSplineCurve) {
|
||||
// TopoDS_Edge circle = asCircle(adapt);
|
||||
// if (circle.IsNull()) {
|
||||
printBSpline(adapt, i, result);
|
||||
// }
|
||||
// else {
|
||||
// BRepAdaptor_Curve adapt_circle(circle);
|
||||
// printCircle(adapt_circle, result);
|
||||
// }
|
||||
// TopoDS_Edge circle = asCircle(adapt);
|
||||
// if (circle.IsNull()) {
|
||||
printBSpline(adapt, i, result);
|
||||
// }
|
||||
// else {
|
||||
// BRepAdaptor_Curve adapt_circle(circle);
|
||||
// printCircle(adapt_circle, result);
|
||||
// }
|
||||
}
|
||||
else if (adapt.GetType() == GeomAbs_BezierCurve) {
|
||||
printBezier(adapt, i, result);
|
||||
@@ -196,81 +196,77 @@ std::string SVGOutput::exportEdges(const TopoDS_Shape& input)
|
||||
void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out)
|
||||
{
|
||||
gp_Circ circ = c.Circle();
|
||||
const gp_Pnt& p= circ.Location();
|
||||
const gp_Pnt& p = circ.Location();
|
||||
double r = circ.Radius();
|
||||
double f = c.FirstParameter();
|
||||
double l = c.LastParameter();
|
||||
gp_Pnt s = c.Value(f);
|
||||
gp_Pnt m = c.Value((l+f)/2.0);
|
||||
gp_Pnt m = c.Value((l + f) / 2.0);
|
||||
gp_Pnt e = c.Value(l);
|
||||
|
||||
gp_Vec v1(m,s);
|
||||
gp_Vec v2(m,e);
|
||||
gp_Vec v3(0,0,1);
|
||||
double a = v3.DotCross(v1,v2);
|
||||
gp_Vec v1(m, s);
|
||||
gp_Vec v2(m, e);
|
||||
gp_Vec v3(0, 0, 1);
|
||||
double a = v3.DotCross(v1, v2);
|
||||
|
||||
// a full circle
|
||||
if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
|
||||
out << "<circle cx =\"" << p.X() << "\" cy =\""
|
||||
<< p.Y() << "\" r =\"" << r << "\" />";
|
||||
if (fabs(l - f) > 1.0 && s.SquareDistance(e) < 0.001) {
|
||||
out << "<circle cx =\"" << p.X() << "\" cy =\"" << p.Y() << "\" r =\"" << r << "\" />";
|
||||
}
|
||||
// arc of circle
|
||||
else {
|
||||
// See also https://developer.mozilla.org/en/SVG/Tutorial/Paths
|
||||
char xar = '0'; // x-axis-rotation
|
||||
char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag
|
||||
char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
|
||||
out << "<path d=\"M" << s.X() << " " << s.Y()
|
||||
<< " A" << r << " " << r << " "
|
||||
<< xar << " " << las << " " << swp << " "
|
||||
<< e.X() << " " << e.Y() << "\" />";
|
||||
char xar = '0'; // x-axis-rotation
|
||||
char las = (l - f > D_PI) ? '1' : '0';// large-arc-flag
|
||||
char swp = (a < 0) ? '1' : '0';// sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
|
||||
out << "<path d=\"M" << s.X() << " " << s.Y() << " A" << r << " " << r << " " << xar << " "
|
||||
<< las << " " << swp << " " << e.X() << " " << e.Y() << "\" />";
|
||||
}
|
||||
}
|
||||
|
||||
void SVGOutput::printEllipse(const BRepAdaptor_Curve& c, int id, std::ostream& out)
|
||||
{
|
||||
gp_Elips ellp = c.Ellipse();
|
||||
const gp_Pnt& p= ellp.Location();
|
||||
const gp_Pnt& p = ellp.Location();
|
||||
double r1 = ellp.MajorRadius();
|
||||
double r2 = ellp.MinorRadius();
|
||||
double f = c.FirstParameter();
|
||||
double l = c.LastParameter();
|
||||
gp_Pnt s = c.Value(f);
|
||||
gp_Pnt m = c.Value((l+f)/2.0);
|
||||
gp_Pnt m = c.Value((l + f) / 2.0);
|
||||
gp_Pnt e = c.Value(l);
|
||||
|
||||
// If the minor radius is very small compared to the major radius
|
||||
// the geometry actually degenerates to a line
|
||||
double ratio = std::min(r1,r2)/std::max(r1,r2);
|
||||
double ratio = std::min(r1, r2) / std::max(r1, r2);
|
||||
if (ratio < 0.001) {
|
||||
printGeneric(c, id, out);
|
||||
return;
|
||||
}
|
||||
|
||||
gp_Vec v1(m,s);
|
||||
gp_Vec v2(m,e);
|
||||
gp_Vec v3(0,0,1);
|
||||
double a = v3.DotCross(v1,v2);
|
||||
|
||||
gp_Vec v1(m, s);
|
||||
gp_Vec v2(m, e);
|
||||
gp_Vec v3(0, 0, 1);
|
||||
double a = v3.DotCross(v1, v2);
|
||||
|
||||
// a full ellipse
|
||||
// See also https://developer.mozilla.org/en/SVG/Tutorial/Paths
|
||||
gp_Dir xaxis = ellp.XAxis().Direction();
|
||||
Standard_Real angle = xaxis.AngleWithRef(gp_Dir(1,0,0),gp_Dir(0,0,-1));
|
||||
Standard_Real angle = xaxis.AngleWithRef(gp_Dir(1, 0, 0), gp_Dir(0, 0, -1));
|
||||
angle = Base::toDegrees<double>(angle);
|
||||
if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
|
||||
out << "<g transform = \"rotate(" << angle << "," << p.X() << "," << p.Y() << ")\">" << std::endl;
|
||||
out << "<ellipse cx =\"" << p.X() << "\" cy =\""
|
||||
<< p.Y() << "\" rx =\"" << r1 << "\" ry =\"" << r2 << "\"/>" << std::endl;
|
||||
if (fabs(l - f) > 1.0 && s.SquareDistance(e) < 0.001) {
|
||||
out << "<g transform = \"rotate(" << angle << "," << p.X() << "," << p.Y() << ")\">"
|
||||
<< std::endl;
|
||||
out << "<ellipse cx =\"" << p.X() << "\" cy =\"" << p.Y() << "\" rx =\"" << r1
|
||||
<< "\" ry =\"" << r2 << "\"/>" << std::endl;
|
||||
out << "</g>" << std::endl;
|
||||
}
|
||||
// arc of ellipse
|
||||
else {
|
||||
char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag
|
||||
char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
|
||||
out << "<path d=\"M" << s.X() << " " << s.Y()
|
||||
<< " A" << r1 << " " << r2 << " "
|
||||
<< angle << " " << las << " " << swp << " "
|
||||
<< e.X() << " " << e.Y() << "\" />" << std::endl;
|
||||
char las = (l - f > D_PI) ? '1' : '0';// large-arc-flag
|
||||
char swp = (a < 0) ? '1' : '0';// sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
|
||||
out << "<path d=\"M" << s.X() << " " << s.Y() << " A" << r1 << " " << r2 << " " << angle
|
||||
<< " " << las << " " << swp << " " << e.X() << " " << e.Y() << "\" />" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,28 +297,27 @@ void SVGOutput::printBezier(const BRepAdaptor_Curve& c, int id, std::ostream& ou
|
||||
gp_Pnt p1 = bezier->Pole(1);
|
||||
str << p1.X() << "," << p1.Y();
|
||||
if (bezier->Degree() == 3) {
|
||||
if (poles != 4)
|
||||
if (poles != 4) {
|
||||
Standard_Failure::Raise("do it the generic way");
|
||||
}
|
||||
gp_Pnt p2 = bezier->Pole(2);
|
||||
gp_Pnt p3 = bezier->Pole(3);
|
||||
gp_Pnt p4 = bezier->Pole(4);
|
||||
str << " C"
|
||||
<< p2.X() << "," << p2.Y() << " "
|
||||
<< p3.X() << "," << p3.Y() << " "
|
||||
str << " C" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " "
|
||||
<< p4.X() << "," << p4.Y() << " ";
|
||||
}
|
||||
else if (bezier->Degree() == 2) {
|
||||
if (poles != 3)
|
||||
if (poles != 3) {
|
||||
Standard_Failure::Raise("do it the generic way");
|
||||
}
|
||||
gp_Pnt p2 = bezier->Pole(2);
|
||||
gp_Pnt p3 = bezier->Pole(3);
|
||||
str << " Q"
|
||||
<< p2.X() << "," << p2.Y() << " "
|
||||
<< p3.X() << "," << p3.Y() << " ";
|
||||
str << " Q" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " ";
|
||||
}
|
||||
else if (bezier->Degree() == 1) {
|
||||
if (poles != 2)
|
||||
if (poles != 2) {
|
||||
Standard_Failure::Raise("do it the generic way");
|
||||
}
|
||||
gp_Pnt p2 = bezier->Pole(2);
|
||||
str << " L" << p2.X() << "," << p2.Y() << " ";
|
||||
}
|
||||
@@ -347,11 +342,12 @@ void SVGOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o
|
||||
Standard_Integer maxDegree = 3, maxSegment = 100;
|
||||
Handle(BRepAdaptor_HCurve) hCurve = new BRepAdaptor_HCurve(c);
|
||||
// approximate the curve using a tolerance
|
||||
Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C0,maxSegment,maxDegree);
|
||||
Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree);
|
||||
if (approx.IsDone() && approx.HasResult()) {
|
||||
// have the result
|
||||
spline = approx.Curve();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printGeneric(c, id, out);
|
||||
return;
|
||||
}
|
||||
@@ -359,7 +355,7 @@ void SVGOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o
|
||||
GeomConvert_BSplineCurveToBezierCurve crt(spline);
|
||||
Standard_Integer arcs = crt.NbArcs();
|
||||
str << "<path d=\"M";
|
||||
for (Standard_Integer i=1; i<=arcs; i++) {
|
||||
for (Standard_Integer i = 1; i <= arcs; i++) {
|
||||
Handle(Geom_BezierCurve) bezier = crt.Arc(i);
|
||||
Standard_Integer poles = bezier->NbPoles();
|
||||
if (i == 1) {
|
||||
@@ -367,28 +363,27 @@ void SVGOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o
|
||||
str << p1.X() << "," << p1.Y();
|
||||
}
|
||||
if (bezier->Degree() == 3) {
|
||||
if (poles != 4)
|
||||
if (poles != 4) {
|
||||
Standard_Failure::Raise("do it the generic way");
|
||||
}
|
||||
gp_Pnt p2 = bezier->Pole(2);
|
||||
gp_Pnt p3 = bezier->Pole(3);
|
||||
gp_Pnt p4 = bezier->Pole(4);
|
||||
str << " C"
|
||||
<< p2.X() << "," << p2.Y() << " "
|
||||
<< p3.X() << "," << p3.Y() << " "
|
||||
str << " C" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " "
|
||||
<< p4.X() << "," << p4.Y() << " ";
|
||||
}
|
||||
else if (bezier->Degree() == 2) {
|
||||
if (poles != 3)
|
||||
if (poles != 3) {
|
||||
Standard_Failure::Raise("do it the generic way");
|
||||
}
|
||||
gp_Pnt p2 = bezier->Pole(2);
|
||||
gp_Pnt p3 = bezier->Pole(3);
|
||||
str << " Q"
|
||||
<< p2.X() << "," << p2.Y() << " "
|
||||
<< p3.X() << "," << p3.Y() << " ";
|
||||
str << " Q" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " ";
|
||||
}
|
||||
else if (bezier->Degree() == 1) {
|
||||
if (poles != 2)
|
||||
if (poles != 2) {
|
||||
Standard_Failure::Raise("do it the generic way");
|
||||
}
|
||||
gp_Pnt p2 = bezier->Pole(2);
|
||||
str << " L" << p2.X() << "," << p2.Y() << " ";
|
||||
}
|
||||
@@ -412,24 +407,25 @@ void SVGOutput::printGeneric(const BRepAdaptor_Curve& bac, int id, std::ostream&
|
||||
if (!polygon.IsNull()) {
|
||||
const TColgp_Array1OfPnt& nodes = polygon->Nodes();
|
||||
char c = 'M';
|
||||
out << "<path id= \"" /*<< ViewName*/ << id << "\" d=\" ";
|
||||
for (int i = nodes.Lower(); i <= nodes.Upper(); i++){
|
||||
out << c << " " << nodes(i).X() << " " << nodes(i).Y()<< " " ;
|
||||
out << "<path id= \"" /*<< ViewName*/ << id << "\" d=\" ";
|
||||
for (int i = nodes.Lower(); i <= nodes.Upper(); i++) {
|
||||
out << c << " " << nodes(i).X() << " " << nodes(i).Y() << " ";
|
||||
c = 'L';
|
||||
}
|
||||
out << "\" />" << endl;
|
||||
} else if (bac.GetType() == GeomAbs_Line) {
|
||||
//BRep_Tool::Polygon3D assumes the edge has polygon representation - ie already been "tessellated"
|
||||
//this is not true for all edges, especially "floating edges"
|
||||
}
|
||||
else if (bac.GetType() == GeomAbs_Line) {
|
||||
// BRep_Tool::Polygon3D assumes the edge has polygon representation - ie already been
|
||||
// "tessellated" this is not true for all edges, especially "floating edges"
|
||||
double f = bac.FirstParameter();
|
||||
double l = bac.LastParameter();
|
||||
gp_Pnt s = bac.Value(f);
|
||||
gp_Pnt e = bac.Value(l);
|
||||
char c = 'M';
|
||||
out << "<path id= \"" /*<< ViewName*/ << id << "\" d=\" ";
|
||||
out << c << " " << s.X() << " " << s.Y()<< " " ;
|
||||
out << "<path id= \"" /*<< ViewName*/ << id << "\" d=\" ";
|
||||
out << c << " " << s.X() << " " << s.Y() << " ";
|
||||
c = 'L';
|
||||
out << c << " " << e.X() << " " << e.Y()<< " " ;
|
||||
out << c << " " << e.X() << " " << e.Y() << " ";
|
||||
out << "\" />" << endl;
|
||||
}
|
||||
}
|
||||
@@ -437,15 +433,14 @@ void SVGOutput::printGeneric(const BRepAdaptor_Curve& bac, int id, std::ostream&
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
DXFOutput::DXFOutput()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
std::string DXFOutput::exportEdges(const TopoDS_Shape& input)
|
||||
{
|
||||
std::stringstream result;
|
||||
|
||||
TopExp_Explorer edges(input, TopAbs_EDGE);
|
||||
for (int i = 1 ; edges.More(); edges.Next(),i++) {
|
||||
for (int i = 1; edges.More(); edges.Next(), i++) {
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(edges.Current());
|
||||
BRepAdaptor_Curve adapt(edge);
|
||||
if (adapt.GetType() == GeomAbs_Circle) {
|
||||
@@ -466,53 +461,52 @@ std::string DXFOutput::exportEdges(const TopoDS_Shape& input)
|
||||
return result.str();
|
||||
}
|
||||
|
||||
void DXFOutput::printHeader( std::ostream& out)
|
||||
void DXFOutput::printHeader(std::ostream& out)
|
||||
{
|
||||
out << 0 << endl;
|
||||
out << "SECTION" << endl;
|
||||
out << 2 << endl;
|
||||
out << "ENTITIES" << endl;
|
||||
out << 0 << endl;
|
||||
out << "SECTION" << endl;
|
||||
out << 2 << endl;
|
||||
out << "ENTITIES" << endl;
|
||||
}
|
||||
|
||||
void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out)
|
||||
{
|
||||
gp_Circ circ = c.Circle();
|
||||
//const gp_Ax1& axis = c->Axis();
|
||||
const gp_Pnt& p= circ.Location();
|
||||
// const gp_Ax1& axis = c->Axis();
|
||||
const gp_Pnt& p = circ.Location();
|
||||
double r = circ.Radius();
|
||||
double f = c.FirstParameter();
|
||||
double l = c.LastParameter();
|
||||
gp_Pnt s = c.Value(f);
|
||||
gp_Pnt m = c.Value((l+f)/2.0);
|
||||
gp_Pnt m = c.Value((l + f) / 2.0);
|
||||
gp_Pnt e = c.Value(l);
|
||||
|
||||
gp_Vec v1(m,s);
|
||||
gp_Vec v2(m,e);
|
||||
gp_Vec v3(0,0,1);
|
||||
double a = v3.DotCross(v1,v2);
|
||||
gp_Vec v1(m, s);
|
||||
gp_Vec v2(m, e);
|
||||
gp_Vec v3(0, 0, 1);
|
||||
double a = v3.DotCross(v1, v2);
|
||||
|
||||
// a full circle
|
||||
if (s.SquareDistance(e) < 0.001) {
|
||||
//out << "<circle cx =\"" << p.X() << "\" cy =\""
|
||||
//<< p.Y() << "\" r =\"" << r << "\" />";
|
||||
out << 0 << endl;
|
||||
out << "CIRCLE" << endl;
|
||||
out << 8 << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl; // Layer number
|
||||
out << "100" << endl;
|
||||
// out << "<circle cx =\"" << p.X() << "\" cy =\""
|
||||
//<< p.Y() << "\" r =\"" << r << "\" />";
|
||||
out << 0 << endl;
|
||||
out << "CIRCLE" << endl;
|
||||
out << 8 << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl;// Layer number
|
||||
out << "100" << endl;
|
||||
out << "AcDbEntity" << endl;
|
||||
out << "100" << endl;
|
||||
out << "AcDbCircle" << endl;
|
||||
out << 10 << endl; // Centre X
|
||||
out << p.X() << endl; // X in WCS coordinates
|
||||
out << 20 << endl;
|
||||
out << p.Y() << endl; // Y in WCS coordinates
|
||||
out << 30 << endl;
|
||||
out << 0 << endl; // Z in WCS coordinates-leaving flat
|
||||
out << 40 << endl; //
|
||||
out << r << endl; // Radius
|
||||
}
|
||||
|
||||
out << "100" << endl;
|
||||
out << "AcDbCircle" << endl;
|
||||
out << 10 << endl; // Centre X
|
||||
out << p.X() << endl;// X in WCS coordinates
|
||||
out << 20 << endl;
|
||||
out << p.Y() << endl;// Y in WCS coordinates
|
||||
out << 30 << endl;
|
||||
out << 0 << endl; // Z in WCS coordinates-leaving flat
|
||||
out << 40 << endl;//
|
||||
out << r << endl; // Radius
|
||||
}
|
||||
|
||||
|
||||
// arc of circle
|
||||
@@ -525,121 +519,122 @@ void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out)
|
||||
<< " A" << r << " " << r << " "
|
||||
<< xar << " " << las << " " << swp << " "
|
||||
<< e.X() << " " << e.Y() << "\" />";*/
|
||||
double ax = s.X() - p.X();
|
||||
double ay = s.Y() - p.Y();
|
||||
double bx = e.X() - p.X();
|
||||
double by = e.Y() - p.Y();
|
||||
|
||||
double start_angle = atan2(ay, ax) * 180/D_PI;
|
||||
double end_angle = atan2(by, bx) * 180/D_PI;
|
||||
|
||||
|
||||
if(a > 0){
|
||||
double temp = start_angle;
|
||||
start_angle = end_angle;
|
||||
end_angle = temp;}
|
||||
out << 0 << endl;
|
||||
out << "ARC" << endl;
|
||||
out << 8 << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl; // Layer number
|
||||
out << "100" << endl;
|
||||
out << "AcDbEntity" << endl;
|
||||
out << "100" << endl;
|
||||
out << "AcDbCircle" << endl;
|
||||
out << 10 << endl; // Centre X
|
||||
out << p.X() << endl; // X in WCS coordinates
|
||||
out << 20 << endl;
|
||||
out << p.Y() << endl; // Y in WCS coordinates
|
||||
out << 30 << endl;
|
||||
out << 0 << endl; // Z in WCS coordinates
|
||||
out << 40 << endl; //
|
||||
out << r << endl; // Radius
|
||||
out << "100" << endl;
|
||||
out << "AcDbArc" << endl;
|
||||
out << 50 << endl;
|
||||
out << start_angle << endl; // Start angle
|
||||
out << 51 << endl;
|
||||
out << end_angle << endl; // End angle
|
||||
double ax = s.X() - p.X();
|
||||
double ay = s.Y() - p.Y();
|
||||
double bx = e.X() - p.X();
|
||||
double by = e.Y() - p.Y();
|
||||
|
||||
double start_angle = atan2(ay, ax) * 180 / D_PI;
|
||||
double end_angle = atan2(by, bx) * 180 / D_PI;
|
||||
|
||||
|
||||
if (a > 0) {
|
||||
double temp = start_angle;
|
||||
start_angle = end_angle;
|
||||
end_angle = temp;
|
||||
}
|
||||
out << 0 << endl;
|
||||
out << "ARC" << endl;
|
||||
out << 8 << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl;// Layer number
|
||||
out << "100" << endl;
|
||||
out << "AcDbEntity" << endl;
|
||||
out << "100" << endl;
|
||||
out << "AcDbCircle" << endl;
|
||||
out << 10 << endl; // Centre X
|
||||
out << p.X() << endl;// X in WCS coordinates
|
||||
out << 20 << endl;
|
||||
out << p.Y() << endl;// Y in WCS coordinates
|
||||
out << 30 << endl;
|
||||
out << 0 << endl; // Z in WCS coordinates
|
||||
out << 40 << endl;//
|
||||
out << r << endl; // Radius
|
||||
out << "100" << endl;
|
||||
out << "AcDbArc" << endl;
|
||||
out << 50 << endl;
|
||||
out << start_angle << endl;// Start angle
|
||||
out << 51 << endl;
|
||||
out << end_angle << endl;// End angle
|
||||
}
|
||||
}
|
||||
|
||||
void DXFOutput::printEllipse(const BRepAdaptor_Curve& c, int /*id*/, std::ostream& out)
|
||||
{
|
||||
gp_Elips ellp = c.Ellipse();
|
||||
const gp_Pnt& p= ellp.Location();
|
||||
const gp_Pnt& p = ellp.Location();
|
||||
double r1 = ellp.MajorRadius();
|
||||
double r2 = ellp.MinorRadius();
|
||||
double dp = ellp.Axis().Direction().Dot(gp_Vec(0,0,1));
|
||||
double dp = ellp.Axis().Direction().Dot(gp_Vec(0, 0, 1));
|
||||
|
||||
// a full ellipse
|
||||
/* if (s.SquareDistance(e) < 0.001) {
|
||||
out << "<ellipse cx =\"" << p.X() << "\" cy =\""
|
||||
<< p.Y() << "\" rx =\"" << r1 << "\" ry =\"" << r2 << "\"/>";
|
||||
/* if (s.SquareDistance(e) < 0.001) {
|
||||
out << "<ellipse cx =\"" << p.X() << "\" cy =\""
|
||||
<< p.Y() << "\" rx =\"" << r1 << "\" ry =\"" << r2 << "\"/>";
|
||||
}
|
||||
// arc of ellipse
|
||||
else {
|
||||
// See also https://developer.mozilla.org/en/SVG/Tutorial/Paths
|
||||
gp_Dir xaxis = ellp.XAxis().Direction();
|
||||
Standard_Real angle = xaxis.Angle(gp_Dir(1,0,0));
|
||||
angle = Base::toDegrees<double>(angle);
|
||||
char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag
|
||||
char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
|
||||
out << "<path d=\"M" << s.X() << " " << s.Y()
|
||||
<< " A" << r1 << " " << r2 << " "
|
||||
<< angle << " " << las << " " << swp << " "
|
||||
<< e.X() << " " << e.Y() << "\" />";
|
||||
}*/
|
||||
gp_Dir xaxis = ellp.XAxis().Direction();
|
||||
double angle = xaxis.AngleWithRef(gp_Dir(1, 0, 0), gp_Dir(0, 0, -1));
|
||||
// double rotation = Base::toDegrees<double>(angle);
|
||||
|
||||
double start_angle = c.FirstParameter();
|
||||
double end_angle = c.LastParameter();
|
||||
|
||||
double major_x;
|
||||
double major_y;
|
||||
|
||||
major_x = r1 * cos(angle);
|
||||
major_y = r1 * sin(angle);
|
||||
|
||||
double ratio = r2 / r1;
|
||||
|
||||
if (dp < 0) {
|
||||
double temp = start_angle;
|
||||
start_angle = end_angle;
|
||||
end_angle = temp;
|
||||
}
|
||||
// arc of ellipse
|
||||
else {
|
||||
// See also https://developer.mozilla.org/en/SVG/Tutorial/Paths
|
||||
gp_Dir xaxis = ellp.XAxis().Direction();
|
||||
Standard_Real angle = xaxis.Angle(gp_Dir(1,0,0));
|
||||
angle = Base::toDegrees<double>(angle);
|
||||
char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag
|
||||
char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
|
||||
out << "<path d=\"M" << s.X() << " " << s.Y()
|
||||
<< " A" << r1 << " " << r2 << " "
|
||||
<< angle << " " << las << " " << swp << " "
|
||||
<< e.X() << " " << e.Y() << "\" />";
|
||||
}*/
|
||||
gp_Dir xaxis = ellp.XAxis().Direction();
|
||||
double angle = xaxis.AngleWithRef(gp_Dir(1,0,0),gp_Dir(0,0,-1));
|
||||
//double rotation = Base::toDegrees<double>(angle);
|
||||
|
||||
double start_angle = c.FirstParameter();
|
||||
double end_angle = c.LastParameter();
|
||||
|
||||
double major_x;double major_y;
|
||||
|
||||
major_x = r1 * cos(angle);
|
||||
major_y = r1 * sin(angle);
|
||||
|
||||
double ratio = r2/r1;
|
||||
|
||||
if(dp < 0){
|
||||
double temp = start_angle;
|
||||
start_angle = end_angle;
|
||||
end_angle = temp;
|
||||
}
|
||||
out << 0 << endl;
|
||||
out << "ELLIPSE" << endl;
|
||||
out << 8 << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl; // Layer number
|
||||
out << "100" << endl;
|
||||
out << 0 << endl;
|
||||
out << "ELLIPSE" << endl;
|
||||
out << 8 << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl;// Layer number
|
||||
out << "100" << endl;
|
||||
out << "AcDbEntity" << endl;
|
||||
out << "100" << endl;
|
||||
out << "AcDbEllipse" << endl;
|
||||
out << 10 << endl; // Centre X
|
||||
out << p.X() << endl; // X in WCS coordinates
|
||||
out << 20 << endl;
|
||||
out << p.Y() << endl; // Y in WCS coordinates
|
||||
out << 30 << endl;
|
||||
out << 0 << endl; // Z in WCS coordinates
|
||||
out << 11 << endl; //
|
||||
out << major_x << endl; // Major X
|
||||
out << 21 << endl;
|
||||
out << major_y << endl; // Major Y
|
||||
out << 31 << endl;
|
||||
out << 0 << endl; // Major Z
|
||||
out << 40 << endl; //
|
||||
out << ratio << endl; // Ratio
|
||||
out << 41 << endl;
|
||||
out << start_angle << endl; // Start angle
|
||||
out << 42 << endl;
|
||||
out << end_angle << endl; // End angle
|
||||
out << "100" << endl;
|
||||
out << "AcDbEllipse" << endl;
|
||||
out << 10 << endl; // Centre X
|
||||
out << p.X() << endl;// X in WCS coordinates
|
||||
out << 20 << endl;
|
||||
out << p.Y() << endl;// Y in WCS coordinates
|
||||
out << 30 << endl;
|
||||
out << 0 << endl; // Z in WCS coordinates
|
||||
out << 11 << endl; //
|
||||
out << major_x << endl;// Major X
|
||||
out << 21 << endl;
|
||||
out << major_y << endl;// Major Y
|
||||
out << 31 << endl;
|
||||
out << 0 << endl; // Major Z
|
||||
out << 40 << endl; //
|
||||
out << ratio << endl;// Ratio
|
||||
out << 41 << endl;
|
||||
out << start_angle << endl;// Start angle
|
||||
out << 42 << endl;
|
||||
out << end_angle << endl;// End angle
|
||||
}
|
||||
|
||||
void DXFOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& out) //Not even close yet- DF
|
||||
void DXFOutput::printBSpline(const BRepAdaptor_Curve& c,
|
||||
int id,
|
||||
std::ostream& out)// Not even close yet- DF
|
||||
{
|
||||
try {
|
||||
std::stringstream str;
|
||||
@@ -648,62 +643,71 @@ void DXFOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o
|
||||
Standard_Integer maxDegree = 3, maxSegment = 50;
|
||||
Handle(BRepAdaptor_HCurve) hCurve = new BRepAdaptor_HCurve(c);
|
||||
// approximate the curve using a tolerance
|
||||
Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C0,maxSegment,maxDegree);
|
||||
Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree);
|
||||
if (approx.IsDone() && approx.HasResult()) {
|
||||
// have the result
|
||||
spline = approx.Curve();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printGeneric(c, id, out);
|
||||
return;
|
||||
}
|
||||
|
||||
//GeomConvert_BSplineCurveToBezierCurve crt(spline);
|
||||
//GeomConvert_BSplineCurveKnotSplitting crt(spline,0);
|
||||
//Standard_Integer arcs = crt.NbArcs();
|
||||
//Standard_Integer arcs = crt.NbSplits()-1;
|
||||
|
||||
// GeomConvert_BSplineCurveToBezierCurve crt(spline);
|
||||
// GeomConvert_BSplineCurveKnotSplitting crt(spline,0);
|
||||
// Standard_Integer arcs = crt.NbArcs();
|
||||
// Standard_Integer arcs = crt.NbSplits()-1;
|
||||
Standard_Integer m = 0;
|
||||
if (spline->IsPeriodic()) {
|
||||
m = spline->NbPoles() + 2*spline->Degree() - spline->Multiplicity(1) + 2;
|
||||
m = spline->NbPoles() + 2 * spline->Degree() - spline->Multiplicity(1) + 2;
|
||||
}
|
||||
else {
|
||||
for (int i=1; i<= spline->NbKnots(); i++)
|
||||
for (int i = 1; i <= spline->NbKnots(); i++) {
|
||||
m += spline->Multiplicity(i);
|
||||
}
|
||||
}
|
||||
TColStd_Array1OfReal knotsequence(1,m);
|
||||
TColStd_Array1OfReal knotsequence(1, m);
|
||||
spline->KnotSequence(knotsequence);
|
||||
TColgp_Array1OfPnt poles(1,spline->NbPoles());
|
||||
TColgp_Array1OfPnt poles(1, spline->NbPoles());
|
||||
spline->Poles(poles);
|
||||
|
||||
|
||||
str << 0 << endl
|
||||
<< "SPLINE" << endl
|
||||
<< 8 << endl // Group code for layer name
|
||||
<< "sheet_layer" << endl // Layer name
|
||||
<< "100" << endl
|
||||
<< 8 << endl // Group code for layer name
|
||||
<< "sheet_layer" << endl// Layer name
|
||||
<< "100" << endl
|
||||
<< "AcDbEntity" << endl
|
||||
<< "100" << endl
|
||||
<< "AcDbSpline" << endl
|
||||
<< "100" << endl
|
||||
<< "AcDbSpline" << endl
|
||||
<< 70 << endl
|
||||
<< spline->IsRational()*4 << endl //flags
|
||||
<< 71 << endl << spline->Degree() << endl
|
||||
<< 72 << endl << knotsequence.Length() << endl
|
||||
<< 73 << endl << poles.Length() << endl
|
||||
<< 74 << endl << 0 << endl; //fitpoints
|
||||
<< spline->IsRational() * 4 << endl// flags
|
||||
<< 71 << endl
|
||||
<< spline->Degree() << endl
|
||||
<< 72 << endl
|
||||
<< knotsequence.Length() << endl
|
||||
<< 73 << endl
|
||||
<< poles.Length() << endl
|
||||
<< 74 << endl
|
||||
<< 0 << endl;// fitpoints
|
||||
|
||||
for (int i = knotsequence.Lower() ; i <= knotsequence.Upper(); i++) {
|
||||
for (int i = knotsequence.Lower(); i <= knotsequence.Upper(); i++) {
|
||||
str << 40 << endl << knotsequence(i) << endl;
|
||||
}
|
||||
for (int i = poles.Lower(); i <= poles.Upper(); i++) {
|
||||
gp_Pnt pole = poles(i);
|
||||
str << 10 << endl << pole.X() << endl
|
||||
<< 20 << endl << pole.Y() << endl
|
||||
<< 30 << endl << pole.Z() << endl;
|
||||
str << 10 << endl
|
||||
<< pole.X() << endl
|
||||
<< 20 << endl
|
||||
<< pole.Y() << endl
|
||||
<< 30 << endl
|
||||
<< pole.Z() << endl;
|
||||
if (spline->IsRational()) {
|
||||
str << 41 << endl << spline->Weight(i) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
//str << "\" />";
|
||||
// str << "\" />";
|
||||
out << str.str();
|
||||
}
|
||||
catch (Standard_Failure&) {
|
||||
@@ -723,24 +727,24 @@ void DXFOutput::printGeneric(const BRepAdaptor_Curve& c, int /*id*/, std::ostrea
|
||||
gp_Vec VE;
|
||||
c.D1(uEnd, PE, VE);
|
||||
|
||||
out << "0" << endl;
|
||||
out << "LINE" << endl;
|
||||
out << "8" << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl; // Layer name
|
||||
out << "100" << endl;
|
||||
out << "0" << endl;
|
||||
out << "LINE" << endl;
|
||||
out << "8" << endl; // Group code for layer name
|
||||
out << "sheet_layer" << endl;// Layer name
|
||||
out << "100" << endl;
|
||||
out << "AcDbEntity" << endl;
|
||||
out << "100" << endl;
|
||||
out << "AcDbLine" << endl;
|
||||
out << "10" << endl; // Start point of line
|
||||
out << PS.X() << endl; // X in WCS coordinates
|
||||
out << "20" << endl;
|
||||
out << PS.Y() << endl; // Y in WCS coordinates
|
||||
out << "30" << endl;
|
||||
out << "0" << endl; // Z in WCS coordinates
|
||||
out << "11" << endl; // End point of line
|
||||
out << PE.X() << endl; // X in WCS coordinates
|
||||
out << "21" << endl;
|
||||
out << PE.Y() << endl; // Y in WCS coordinates
|
||||
out << "31" << endl;
|
||||
out << "0" << endl; // Z in WCS coordinates
|
||||
out << "100" << endl;
|
||||
out << "AcDbLine" << endl;
|
||||
out << "10" << endl; // Start point of line
|
||||
out << PS.X() << endl;// X in WCS coordinates
|
||||
out << "20" << endl;
|
||||
out << PS.Y() << endl;// Y in WCS coordinates
|
||||
out << "30" << endl;
|
||||
out << "0" << endl; // Z in WCS coordinates
|
||||
out << "11" << endl; // End point of line
|
||||
out << PE.X() << endl;// X in WCS coordinates
|
||||
out << "21" << endl;
|
||||
out << PE.Y() << endl;// Y in WCS coordinates
|
||||
out << "31" << endl;
|
||||
out << "0" << endl;// Z in WCS coordinates
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
#ifndef DRAWING_EXPORT_H
|
||||
#define DRAWING_EXPORT_H
|
||||
|
||||
#include <string>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <Mod/Drawing/DrawingGlobal.h>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <string>
|
||||
|
||||
|
||||
class TopoDS_Shape;
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
TopoDS_Edge asBSpline(const BRepAdaptor_Curve&, int maxDegree) const;
|
||||
};
|
||||
|
||||
class DrawingExport SVGOutput : public DrawingOutput
|
||||
class DrawingExport SVGOutput: public DrawingOutput
|
||||
{
|
||||
public:
|
||||
SVGOutput();
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
};
|
||||
|
||||
/* dxf output section - Dan Falck 2011/09/25 */
|
||||
class DrawingExport DXFOutput : public DrawingOutput
|
||||
class DrawingExport DXFOutput: public DrawingOutput
|
||||
{
|
||||
public:
|
||||
DXFOutput();
|
||||
@@ -72,6 +72,6 @@ private:
|
||||
void printGeneric(const BRepAdaptor_Curve&, int id, std::ostream&);
|
||||
};
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
#endif // DRAWING_EXPORT_H
|
||||
#endif// DRAWING_EXPORT_H
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <iostream>
|
||||
# include <sstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include "FeatureClip.h"
|
||||
@@ -39,25 +39,50 @@ using namespace std;
|
||||
|
||||
PROPERTY_SOURCE(Drawing::FeatureClip, App::DocumentObjectGroup)
|
||||
|
||||
FeatureClip::FeatureClip(void)
|
||||
FeatureClip::FeatureClip(void)
|
||||
{
|
||||
static const char *group = "Drawing view";
|
||||
static const char* group = "Drawing view";
|
||||
App::PropertyType hidden = (App::PropertyType)(App::Prop_Hidden);
|
||||
ADD_PROPERTY_TYPE(ViewResult ,(""),group,hidden,"Resulting SVG view of this clip");
|
||||
ADD_PROPERTY_TYPE(X ,(10),group,App::Prop_None ,"The left margin of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(Y ,(10),group,App::Prop_None ,"The top margin of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(Height ,(10),group,App::Prop_None ,"The height of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(Width ,(10),group,App::Prop_None ,"The width of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(ShowFrame ,(0),group,App::Prop_None,"Specifies if the clip frame appears on the page or not");
|
||||
// The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag set to
|
||||
// avoid to call the execute() method. The view provider touches the page object, instead.
|
||||
App::PropertyType propType = static_cast<App::PropertyType>(App::Prop_Hidden|App::Prop_Output);
|
||||
ADD_PROPERTY_TYPE(Visible, (true),group,propType,"Control whether frame is visible in page object");
|
||||
ADD_PROPERTY_TYPE(ViewResult, (""), group, hidden, "Resulting SVG view of this clip");
|
||||
ADD_PROPERTY_TYPE(X,
|
||||
(10),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"The left margin of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(Y,
|
||||
(10),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"The top margin of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(Height,
|
||||
(10),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"The height of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(Width,
|
||||
(10),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"The width of the view area of this clip");
|
||||
ADD_PROPERTY_TYPE(ShowFrame,
|
||||
(0),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"Specifies if the clip frame appears on the page or not");
|
||||
// The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag
|
||||
// set to avoid to call the execute() method. The view provider touches the page object,
|
||||
// instead.
|
||||
App::PropertyType propType =
|
||||
static_cast<App::PropertyType>(App::Prop_Hidden | App::Prop_Output);
|
||||
ADD_PROPERTY_TYPE(Visible,
|
||||
(true),
|
||||
group,
|
||||
propType,
|
||||
"Control whether frame is visible in page object");
|
||||
}
|
||||
|
||||
FeatureClip::~FeatureClip()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/// get called by the container when a Property was changed
|
||||
void FeatureClip::onChanged(const App::Property* prop)
|
||||
@@ -65,7 +90,7 @@ void FeatureClip::onChanged(const App::Property* prop)
|
||||
App::DocumentObjectGroup::onChanged(prop);
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureClip::execute(void)
|
||||
App::DocumentObjectExecReturn* FeatureClip::execute(void)
|
||||
{
|
||||
ostringstream svg;
|
||||
|
||||
@@ -79,7 +104,7 @@ App::DocumentObjectExecReturn *FeatureClip::execute(void)
|
||||
// show clip frame on the page if needed
|
||||
|
||||
if (ShowFrame.getValue()) {
|
||||
svg << "<rect fill=\"None\" stroke=\"#ff0000\" stroke-width=\"1px\""
|
||||
svg << "<rect fill=\"None\" stroke=\"#ff0000\" stroke-width=\"1px\""
|
||||
<< " x=\"" << X.getValue() << "\""
|
||||
<< " y=\"" << Y.getValue() << "\""
|
||||
<< " width=\"" << Width.getValue() << "\""
|
||||
@@ -90,10 +115,10 @@ App::DocumentObjectExecReturn *FeatureClip::execute(void)
|
||||
svg << "<g clip-path=\"url(#" << Label.getValue() << ")\">" << endl;
|
||||
|
||||
// get through the children and collect all the views
|
||||
const vector<App::DocumentObject*> &Grp = Group.getValues();
|
||||
for (vector<App::DocumentObject*>::const_iterator It= Grp.begin();It!=Grp.end();++It) {
|
||||
const vector<App::DocumentObject*>& Grp = Group.getValues();
|
||||
for (vector<App::DocumentObject*>::const_iterator It = Grp.begin(); It != Grp.end(); ++It) {
|
||||
if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) {
|
||||
Drawing::FeatureView *View = static_cast<Drawing::FeatureView *>(*It);
|
||||
Drawing::FeatureView* View = static_cast<Drawing::FeatureView*>(*It);
|
||||
svg << View->ViewResult.getValue() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +53,12 @@ public:
|
||||
/** @name methods override Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingClip";
|
||||
}
|
||||
|
||||
@@ -66,7 +67,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,20 +22,20 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <fstream>
|
||||
# include <iostream>
|
||||
# include <iterator>
|
||||
# include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
# include <boost/regex.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/FileInfo.h>
|
||||
|
||||
#include "FeaturePage.h"
|
||||
#include "FeatureClip.h"
|
||||
#include "FeaturePage.h"
|
||||
#include "FeatureView.h"
|
||||
|
||||
|
||||
@@ -48,18 +48,26 @@ using namespace std;
|
||||
|
||||
PROPERTY_SOURCE(Drawing::FeaturePage, App::DocumentObjectGroup)
|
||||
|
||||
FeaturePage::FeaturePage(void) : numChildren(0)
|
||||
FeaturePage::FeaturePage(void)
|
||||
: numChildren(0)
|
||||
{
|
||||
static const char *group = "Drawing view";
|
||||
static const char* group = "Drawing view";
|
||||
|
||||
ADD_PROPERTY_TYPE(PageResult, (nullptr), group, App::Prop_Output, "Resulting SVG document of that page");
|
||||
ADD_PROPERTY_TYPE(PageResult,
|
||||
(nullptr),
|
||||
group,
|
||||
App::Prop_Output,
|
||||
"Resulting SVG document of that page");
|
||||
ADD_PROPERTY_TYPE(Template, (""), group, App::Prop_None, "Template for the page");
|
||||
ADD_PROPERTY_TYPE(EditableTexts, (""), group, App::Prop_None, "Substitution values for the editable strings in the template");
|
||||
ADD_PROPERTY_TYPE(EditableTexts,
|
||||
(""),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"Substitution values for the editable strings in the template");
|
||||
}
|
||||
|
||||
FeaturePage::~FeaturePage()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void FeaturePage::onBeforeChange(const App::Property* prop)
|
||||
{
|
||||
@@ -78,19 +86,23 @@ void FeaturePage::onChanged(const App::Property* prop)
|
||||
// When loading a document the included file
|
||||
// doesn't need to exist at this point.
|
||||
Base::FileInfo fi(PageResult.getValue());
|
||||
if (!fi.exists())
|
||||
if (!fi.exists()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (prop == &EditableTexts) {
|
||||
}
|
||||
else if (prop == &EditableTexts) {
|
||||
if (!this->isRestoring()) {
|
||||
this->execute();
|
||||
return;
|
||||
}
|
||||
} else if (prop == &Template) {
|
||||
}
|
||||
else if (prop == &Template) {
|
||||
if (!this->isRestoring()) {
|
||||
EditableTexts.setValues(getEditableTextsFromTemplate());
|
||||
}
|
||||
} else if (prop == &Group) {
|
||||
}
|
||||
else if (prop == &Group) {
|
||||
if (Group.getSize() != numChildren) {
|
||||
numChildren = Group.getSize();
|
||||
touch();
|
||||
@@ -103,29 +115,33 @@ void FeaturePage::onChanged(const App::Property* prop)
|
||||
void FeaturePage::onDocumentRestored()
|
||||
{
|
||||
// Needs to be tmp. set because otherwise the custom text gets overridden (#0002064)
|
||||
this->StatusBits.set(App::Restore); // the 'Restore' flag
|
||||
this->StatusBits.set(App::Restore);// the 'Restore' flag
|
||||
|
||||
Base::FileInfo templateInfo(Template.getValue());
|
||||
if (!templateInfo.exists()) {
|
||||
Base::FileInfo fi(Template.getValue());
|
||||
if (fi.fileName().empty())
|
||||
if (fi.fileName().empty()) {
|
||||
fi.setFile(PageResult.getValue());
|
||||
std::string path = App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName();
|
||||
}
|
||||
std::string path =
|
||||
App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName();
|
||||
// try to find the template in user dir/Templates first
|
||||
Base::FileInfo tempfi(App::Application::getUserAppDataDir() + "Templates/" + fi.fileName());
|
||||
if (tempfi.exists())
|
||||
if (tempfi.exists()) {
|
||||
path = tempfi.filePath();
|
||||
}
|
||||
Template.setValue(path);
|
||||
}
|
||||
|
||||
this->StatusBits.reset(App::Restore); // the 'Restore' flag
|
||||
this->StatusBits.reset(App::Restore);// the 'Restore' flag
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *FeaturePage::execute(void)
|
||||
App::DocumentObjectExecReturn* FeaturePage::execute(void)
|
||||
{
|
||||
std::string temp = Template.getValue();
|
||||
if (temp.empty())
|
||||
if (temp.empty()) {
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
Base::FileInfo fi(temp);
|
||||
if (!fi.isReadable()) {
|
||||
@@ -133,54 +149,64 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void)
|
||||
fi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName());
|
||||
// try the redirect
|
||||
if (!fi.isReadable()) {
|
||||
Base::Console().Log("FeaturePage::execute() not able to open %s!\n",Template.getValue());
|
||||
Base::Console().Log("FeaturePage::execute() not able to open %s!\n",
|
||||
Template.getValue());
|
||||
std::string error = std::string("Cannot open file ") + Template.getValue();
|
||||
return new App::DocumentObjectExecReturn(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (std::string(PageResult.getValue()).empty())
|
||||
if (std::string(PageResult.getValue()).empty()) {
|
||||
PageResult.setValue(fi.filePath().c_str());
|
||||
}
|
||||
|
||||
// open Template file
|
||||
string line;
|
||||
ifstream file (fi.filePath().c_str());
|
||||
ifstream file(fi.filePath().c_str());
|
||||
|
||||
// make a temp file for FileIncluded Property
|
||||
string tempName = PageResult.getExchangeTempFile();
|
||||
ostringstream ofile;
|
||||
string tempendl = "--endOfLine--";
|
||||
|
||||
while (getline (file,line))
|
||||
{
|
||||
while (getline(file, line)) {
|
||||
// check if the marker in the template is found
|
||||
if(line.find("<!-- DrawingContent -->") == string::npos)
|
||||
if (line.find("<!-- DrawingContent -->") == string::npos) {
|
||||
// if not - write through
|
||||
ofile << line << tempendl;
|
||||
else
|
||||
{
|
||||
}
|
||||
else {
|
||||
// get through the children and collect all the views
|
||||
const std::vector<App::DocumentObject*> &Grp = Group.getValues();
|
||||
for (std::vector<App::DocumentObject*>::const_iterator It= Grp.begin();It!=Grp.end();++It) {
|
||||
if ( (*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId()) ) {
|
||||
Drawing::FeatureView *View = static_cast<Drawing::FeatureView *>(*It);
|
||||
const std::vector<App::DocumentObject*>& Grp = Group.getValues();
|
||||
for (std::vector<App::DocumentObject*>::const_iterator It = Grp.begin();
|
||||
It != Grp.end();
|
||||
++It) {
|
||||
if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) {
|
||||
Drawing::FeatureView* View = static_cast<Drawing::FeatureView*>(*It);
|
||||
if (View->Visible.getValue()) {
|
||||
ofile << View->ViewResult.getValue();
|
||||
ofile << tempendl << tempendl << tempendl;
|
||||
}
|
||||
} else if ( (*It)->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId()) ) {
|
||||
Drawing::FeatureClip *Clip = static_cast<Drawing::FeatureClip *>(*It);
|
||||
}
|
||||
else if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId())) {
|
||||
Drawing::FeatureClip* Clip = static_cast<Drawing::FeatureClip*>(*It);
|
||||
if (Clip->Visible.getValue()) {
|
||||
ofile << Clip->ViewResult.getValue();
|
||||
ofile << tempendl << tempendl << tempendl;
|
||||
}
|
||||
} else if ( (*It)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId()) ) {
|
||||
}
|
||||
else if ((*It)->getTypeId().isDerivedFrom(
|
||||
App::DocumentObjectGroup::getClassTypeId())) {
|
||||
// getting children inside subgroups too
|
||||
App::DocumentObjectGroup *SubGroup = static_cast<App::DocumentObjectGroup *>(*It);
|
||||
const std::vector<App::DocumentObject*> &SubGrp = SubGroup->Group.getValues();
|
||||
for (std::vector<App::DocumentObject*>::const_iterator Grit= SubGrp.begin();Grit!=SubGrp.end();++Grit) {
|
||||
if ( (*Grit)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId()) ) {
|
||||
Drawing::FeatureView *SView = static_cast<Drawing::FeatureView *>(*Grit);
|
||||
App::DocumentObjectGroup* SubGroup =
|
||||
static_cast<App::DocumentObjectGroup*>(*It);
|
||||
const std::vector<App::DocumentObject*>& SubGrp = SubGroup->Group.getValues();
|
||||
for (std::vector<App::DocumentObject*>::const_iterator Grit = SubGrp.begin();
|
||||
Grit != SubGrp.end();
|
||||
++Grit) {
|
||||
if ((*Grit)->getTypeId().isDerivedFrom(
|
||||
Drawing::FeatureView::getClassTypeId())) {
|
||||
Drawing::FeatureView* SView = static_cast<Drawing::FeatureView*>(*Grit);
|
||||
if (SView->Visible.getValue()) {
|
||||
ofile << SView->ViewResult.getValue();
|
||||
ofile << tempendl << tempendl << tempendl;
|
||||
@@ -198,7 +224,7 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void)
|
||||
string outfragment(ofile.str());
|
||||
const std::vector<std::string>& editText = EditableTexts.getValues();
|
||||
if (!editText.empty()) {
|
||||
boost::regex e1 ("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
boost::regex e1("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
string::const_iterator begin, end;
|
||||
begin = outfragment.begin();
|
||||
end = outfragment.end();
|
||||
@@ -210,9 +236,14 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void)
|
||||
while (boost::regex_search(begin, end, what, e1)) {
|
||||
if (count < editText.size()) {
|
||||
// change values of editable texts
|
||||
boost::regex e2 ("(<text.*?freecad:editable=\""+what[1].str()+"\".*?<tspan.*?)>(.*?)(</tspan>)");
|
||||
boost::regex e2("(<text.*?freecad:editable=\"" + what[1].str()
|
||||
+ "\".*?<tspan.*?)>(.*?)(</tspan>)");
|
||||
std::back_insert_iterator<std::string> out(newfragment);
|
||||
boost::regex_replace(out, begin, what[0].second, e2, "$1>"+editText[count]+"$3");
|
||||
boost::regex_replace(out,
|
||||
begin,
|
||||
what[0].second,
|
||||
e2,
|
||||
"$1>" + editText[count] + "$3");
|
||||
}
|
||||
count++;
|
||||
begin = what[0].second;
|
||||
@@ -224,7 +255,7 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void)
|
||||
}
|
||||
|
||||
// restoring linebreaks and saving the file
|
||||
boost::regex e3 ("--endOfLine--");
|
||||
boost::regex e3("--endOfLine--");
|
||||
string fmt = "\\n";
|
||||
outfragment = boost::regex_replace(outfragment, e3, fmt);
|
||||
ofstream outfinal(tempName.c_str());
|
||||
@@ -236,8 +267,9 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void)
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
std::vector<std::string> FeaturePage::getEditableTextsFromTemplate(void) const {
|
||||
//getting editable texts from "freecad:editable" attributes in SVG template
|
||||
std::vector<std::string> FeaturePage::getEditableTextsFromTemplate(void) const
|
||||
{
|
||||
// getting editable texts from "freecad:editable" attributes in SVG template
|
||||
|
||||
std::vector<string> eds;
|
||||
|
||||
@@ -246,20 +278,21 @@ std::vector<std::string> FeaturePage::getEditableTextsFromTemplate(void) const {
|
||||
Base::FileInfo tfi(temp);
|
||||
if (!tfi.isReadable()) {
|
||||
// if there is a old absolute template file set use a redirect
|
||||
tfi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + tfi.fileName());
|
||||
tfi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/"
|
||||
+ tfi.fileName());
|
||||
// try the redirect
|
||||
if (!tfi.isReadable()) {
|
||||
return eds;
|
||||
}
|
||||
}
|
||||
string tline, tfrag;
|
||||
ifstream tfile (tfi.filePath().c_str());
|
||||
while (getline (tfile,tline)) {
|
||||
ifstream tfile(tfi.filePath().c_str());
|
||||
while (getline(tfile, tline)) {
|
||||
tfrag += tline;
|
||||
tfrag += "--endOfLine--";
|
||||
}
|
||||
tfile.close();
|
||||
boost::regex e ("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
boost::regex e("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
string::const_iterator tbegin, tend;
|
||||
tbegin = tfrag.begin();
|
||||
tend = tfrag.end();
|
||||
|
||||
@@ -49,11 +49,12 @@ public:
|
||||
/** @name methods override Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingPage";
|
||||
}
|
||||
virtual std::vector<std::string> getEditableTextsFromTemplate(void) const;
|
||||
@@ -69,7 +70,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
#include <sstream>
|
||||
|
||||
# include <BRep_Builder.hxx>
|
||||
# include <Standard_Failure.hxx>
|
||||
# include <TopoDS_Compound.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#endif
|
||||
|
||||
#include "FeatureProjection.h"
|
||||
@@ -37,38 +37,43 @@ using namespace Drawing;
|
||||
|
||||
PROPERTY_SOURCE(Drawing::FeatureProjection, Part::Feature)
|
||||
|
||||
FeatureProjection::FeatureProjection()
|
||||
FeatureProjection::FeatureProjection()
|
||||
{
|
||||
static const char *group = "Projection";
|
||||
ADD_PROPERTY_TYPE(Source ,(nullptr),group,App::Prop_None,"Shape to project");
|
||||
ADD_PROPERTY_TYPE(Direction, (Base::Vector3d(0, 0, 1)), group, App::Prop_None,
|
||||
static const char* group = "Projection";
|
||||
ADD_PROPERTY_TYPE(Source, (nullptr), group, App::Prop_None, "Shape to project");
|
||||
ADD_PROPERTY_TYPE(Direction,
|
||||
(Base::Vector3d(0, 0, 1)),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"Projection direction");
|
||||
ADD_PROPERTY_TYPE(VCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(Rg1LineVCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(RgNLineVCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(OutLineVCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(IsoLineVCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(HCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(Rg1LineHCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(RgNLineHCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(OutLineHCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(IsoLineHCompound ,(true),group,App::Prop_None,"Projection parameter");
|
||||
ADD_PROPERTY_TYPE(VCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(Rg1LineVCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(RgNLineVCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(OutLineVCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(IsoLineVCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(HCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(Rg1LineHCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(RgNLineHCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(OutLineHCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
ADD_PROPERTY_TYPE(IsoLineHCompound, (true), group, App::Prop_None, "Projection parameter");
|
||||
}
|
||||
|
||||
FeatureProjection::~FeatureProjection()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureProjection::execute(void)
|
||||
App::DocumentObjectExecReturn* FeatureProjection::execute(void)
|
||||
{
|
||||
App::DocumentObject* link = Source.getValue();
|
||||
if (!link)
|
||||
if (!link) {
|
||||
return new App::DocumentObjectExecReturn("No object linked");
|
||||
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
}
|
||||
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
|
||||
}
|
||||
const TopoDS_Shape& shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
|
||||
if (shape.IsNull())
|
||||
if (shape.IsNull()) {
|
||||
return new App::DocumentObjectExecReturn("Linked shape object is empty");
|
||||
}
|
||||
|
||||
try {
|
||||
const Base::Vector3d& dir = Direction.getValue();
|
||||
@@ -77,26 +82,36 @@ App::DocumentObjectExecReturn *FeatureProjection::execute(void)
|
||||
TopoDS_Compound comp;
|
||||
BRep_Builder builder;
|
||||
builder.MakeCompound(comp);
|
||||
if (!alg.V.IsNull() && VCompound.getValue())
|
||||
if (!alg.V.IsNull() && VCompound.getValue()) {
|
||||
builder.Add(comp, alg.V);
|
||||
if (!alg.V1.IsNull() && Rg1LineVCompound.getValue())
|
||||
}
|
||||
if (!alg.V1.IsNull() && Rg1LineVCompound.getValue()) {
|
||||
builder.Add(comp, alg.V1);
|
||||
if (!alg.VN.IsNull() && RgNLineVCompound.getValue())
|
||||
}
|
||||
if (!alg.VN.IsNull() && RgNLineVCompound.getValue()) {
|
||||
builder.Add(comp, alg.VN);
|
||||
if (!alg.VO.IsNull() && OutLineVCompound.getValue())
|
||||
}
|
||||
if (!alg.VO.IsNull() && OutLineVCompound.getValue()) {
|
||||
builder.Add(comp, alg.VO);
|
||||
if (!alg.VI.IsNull() && IsoLineVCompound.getValue())
|
||||
}
|
||||
if (!alg.VI.IsNull() && IsoLineVCompound.getValue()) {
|
||||
builder.Add(comp, alg.VI);
|
||||
if (!alg.H.IsNull() && HCompound.getValue())
|
||||
}
|
||||
if (!alg.H.IsNull() && HCompound.getValue()) {
|
||||
builder.Add(comp, alg.H);
|
||||
if (!alg.H1.IsNull() && Rg1LineHCompound.getValue())
|
||||
}
|
||||
if (!alg.H1.IsNull() && Rg1LineHCompound.getValue()) {
|
||||
builder.Add(comp, alg.H1);
|
||||
if (!alg.HN.IsNull() && RgNLineHCompound.getValue())
|
||||
}
|
||||
if (!alg.HN.IsNull() && RgNLineHCompound.getValue()) {
|
||||
builder.Add(comp, alg.HN);
|
||||
if (!alg.HO.IsNull() && OutLineHCompound.getValue())
|
||||
}
|
||||
if (!alg.HO.IsNull() && OutLineHCompound.getValue()) {
|
||||
builder.Add(comp, alg.HO);
|
||||
if (!alg.HI.IsNull() && IsoLineHCompound.getValue())
|
||||
}
|
||||
if (!alg.HI.IsNull() && IsoLineHCompound.getValue()) {
|
||||
builder.Add(comp, alg.HI);
|
||||
}
|
||||
|
||||
Shape.setValue(comp);
|
||||
return App::DocumentObject::StdReturn;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Drawing
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class DrawingExport FeatureProjection : public Part::Feature
|
||||
class DrawingExport FeatureProjection: public Part::Feature
|
||||
{
|
||||
PROPERTY_HEADER(Drawing::FeatureProjection);
|
||||
|
||||
@@ -43,28 +43,27 @@ public:
|
||||
FeatureProjection();
|
||||
virtual ~FeatureProjection();
|
||||
|
||||
App::PropertyLink Source;
|
||||
App::PropertyLink Source;
|
||||
App::PropertyVector Direction;
|
||||
App::PropertyBool VCompound;
|
||||
App::PropertyBool Rg1LineVCompound;
|
||||
App::PropertyBool RgNLineVCompound;
|
||||
App::PropertyBool OutLineVCompound;
|
||||
App::PropertyBool IsoLineVCompound;
|
||||
App::PropertyBool HCompound;
|
||||
App::PropertyBool Rg1LineHCompound;
|
||||
App::PropertyBool RgNLineHCompound;
|
||||
App::PropertyBool OutLineHCompound;
|
||||
App::PropertyBool IsoLineHCompound;
|
||||
App::PropertyBool VCompound;
|
||||
App::PropertyBool Rg1LineVCompound;
|
||||
App::PropertyBool RgNLineVCompound;
|
||||
App::PropertyBool OutLineVCompound;
|
||||
App::PropertyBool IsoLineVCompound;
|
||||
App::PropertyBool HCompound;
|
||||
App::PropertyBool Rg1LineHCompound;
|
||||
App::PropertyBool RgNLineHCompound;
|
||||
App::PropertyBool OutLineHCompound;
|
||||
App::PropertyBool IsoLineHCompound;
|
||||
|
||||
/** @name methods override feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
};
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
|
||||
#endif // DRAWING_FEATUREPROJECTION
|
||||
#endif// DRAWING_FEATUREPROJECTION
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <Standard_Failure.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <Base/Exception.h>
|
||||
@@ -40,21 +40,34 @@ using namespace Drawing;
|
||||
PROPERTY_SOURCE(Drawing::FeatureView, App::DocumentObject)
|
||||
|
||||
|
||||
FeatureView::FeatureView(void)
|
||||
FeatureView::FeatureView(void)
|
||||
{
|
||||
static const char* group = "Drawing view";
|
||||
ADD_PROPERTY_TYPE(X, (0), group, App::Prop_None,
|
||||
ADD_PROPERTY_TYPE(X,
|
||||
(0),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"X position of the view on the drawing in modelling units (mm)");
|
||||
ADD_PROPERTY_TYPE(Y, (0), group, App::Prop_None,
|
||||
ADD_PROPERTY_TYPE(Y,
|
||||
(0),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"Y position of the view on the drawing in modelling units (mm)");
|
||||
ADD_PROPERTY_TYPE(Scale, (1.0), group, App::Prop_None, "Scale factor of the view");
|
||||
ADD_PROPERTY_TYPE(Rotation, (0), group, App::Prop_None,
|
||||
ADD_PROPERTY_TYPE(Rotation,
|
||||
(0),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"Rotation of the view in degrees counterclockwise");
|
||||
// The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag set to
|
||||
// avoid to call the execute() method. The view provider touches the page object, instead.
|
||||
// The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag
|
||||
// set to avoid to call the execute() method. The view provider touches the page object,
|
||||
// instead.
|
||||
App::PropertyType propType =
|
||||
static_cast<App::PropertyType>(App::Prop_Hidden | App::Prop_Output);
|
||||
ADD_PROPERTY_TYPE(Visible, (true), group, propType,
|
||||
ADD_PROPERTY_TYPE(Visible,
|
||||
(true),
|
||||
group,
|
||||
propType,
|
||||
"Control whether view is visible in page object");
|
||||
|
||||
App::PropertyType type = (App::PropertyType)(App::Prop_Hidden);
|
||||
@@ -62,10 +75,9 @@ FeatureView::FeatureView(void)
|
||||
}
|
||||
|
||||
FeatureView::~FeatureView()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureView::recompute(void)
|
||||
App::DocumentObjectExecReturn* FeatureView::recompute(void)
|
||||
{
|
||||
try {
|
||||
return App::DocumentObject::recompute();
|
||||
@@ -73,12 +85,14 @@ App::DocumentObjectExecReturn *FeatureView::recompute(void)
|
||||
catch (Standard_Failure& e) {
|
||||
App::DocumentObjectExecReturn* ret =
|
||||
new App::DocumentObjectExecReturn(e.GetMessageString());
|
||||
if (ret->Why.empty()) ret->Why = "Unknown OCC exception";
|
||||
if (ret->Why.empty()) {
|
||||
ret->Why = "Unknown OCC exception";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureView::execute(void)
|
||||
App::DocumentObjectExecReturn* FeatureView::execute(void)
|
||||
{
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
@@ -86,14 +100,17 @@ App::DocumentObjectExecReturn *FeatureView::execute(void)
|
||||
|
||||
// Python Drawing feature ---------------------------------------------------------
|
||||
|
||||
namespace App {
|
||||
namespace App
|
||||
{
|
||||
/// @cond DOXERR
|
||||
PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewPython, Drawing::FeatureView)
|
||||
template<> const char* Drawing::FeatureViewPython::getViewProviderName(void) const {
|
||||
template<>
|
||||
const char* Drawing::FeatureViewPython::getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingViewPython";
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
// explicit template instantiation
|
||||
template class DrawingExport FeaturePythonT<Drawing::FeatureView>;
|
||||
}
|
||||
}// namespace App
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Drawing
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class DrawingExport FeatureView : public App::DocumentObject
|
||||
class DrawingExport FeatureView: public App::DocumentObject
|
||||
{
|
||||
PROPERTY_HEADER(Drawing::FeatureView);
|
||||
|
||||
@@ -43,12 +43,13 @@ public:
|
||||
FeatureView(void);
|
||||
virtual ~FeatureView();
|
||||
|
||||
App::PropertyFloat X,Y,Scale,Rotation;
|
||||
App::PropertyFloat X, Y, Scale, Rotation;
|
||||
App::PropertyString ViewResult;
|
||||
App::PropertyBool Visible;
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
|
||||
@@ -56,15 +57,14 @@ protected:
|
||||
/** @name methods override Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *recompute(void);
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* recompute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
};
|
||||
|
||||
using FeatureViewPython = App::FeaturePythonT<FeatureView>;
|
||||
|
||||
} //namespace Drawing
|
||||
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <iomanip>
|
||||
# include <sstream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include "FeatureViewAnnotation.h"
|
||||
@@ -39,36 +39,39 @@ using namespace std;
|
||||
PROPERTY_SOURCE(Drawing::FeatureViewAnnotation, Drawing::FeatureView)
|
||||
|
||||
|
||||
FeatureViewAnnotation::FeatureViewAnnotation(void)
|
||||
FeatureViewAnnotation::FeatureViewAnnotation(void)
|
||||
{
|
||||
static const char *vgroup = "Drawing view";
|
||||
static const char* vgroup = "Drawing view";
|
||||
|
||||
ADD_PROPERTY_TYPE(Text ,(""),vgroup,App::Prop_None,"The text to be displayed");
|
||||
ADD_PROPERTY_TYPE(Font ,("Sans"),vgroup,App::Prop_None,"The name of the font to use");
|
||||
ADD_PROPERTY_TYPE(TextColor, (0.0f, 0.0f, 0.0f), vgroup, App::Prop_None,
|
||||
ADD_PROPERTY_TYPE(Text, (""), vgroup, App::Prop_None, "The text to be displayed");
|
||||
ADD_PROPERTY_TYPE(Font, ("Sans"), vgroup, App::Prop_None, "The name of the font to use");
|
||||
ADD_PROPERTY_TYPE(TextColor,
|
||||
(0.0f, 0.0f, 0.0f),
|
||||
vgroup,
|
||||
App::Prop_None,
|
||||
"The color of the text");
|
||||
}
|
||||
|
||||
FeatureViewAnnotation::~FeatureViewAnnotation()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureViewAnnotation::execute(void)
|
||||
App::DocumentObjectExecReturn* FeatureViewAnnotation::execute(void)
|
||||
{
|
||||
stringstream result,hr,hg,hb;
|
||||
stringstream result, hr, hg, hb;
|
||||
const App::Color& c = TextColor.getValue();
|
||||
hr << hex << setfill('0') << setw(2) << (int)(255.0*c.r);
|
||||
hg << hex << setfill('0') << setw(2) << (int)(255.0*c.g);
|
||||
hb << hex << setfill('0') << setw(2) << (int)(255.0*c.b);
|
||||
hr << hex << setfill('0') << setw(2) << (int)(255.0 * c.r);
|
||||
hg << hex << setfill('0') << setw(2) << (int)(255.0 * c.g);
|
||||
hb << hex << setfill('0') << setw(2) << (int)(255.0 * c.b);
|
||||
|
||||
result << "<g transform=\"translate(" << X.getValue() << "," << Y.getValue() << ")"
|
||||
<< " rotate(" << Rotation.getValue() << ")\">" << endl
|
||||
<< "<text id=\"" << Label.getValue() << "\"" << endl
|
||||
<< " font-family=\"" << Font.getValue() << "\"" << endl
|
||||
<< " font-size=\"" << Scale.getValue() << "\"" << endl
|
||||
<< " fill=\"#" << hr.str() << hg.str() << hb.str() << "\">" << endl;
|
||||
result << "<g transform=\"translate(" << X.getValue() << "," << Y.getValue() << ")"
|
||||
<< " rotate(" << Rotation.getValue() << ")\">" << endl
|
||||
<< "<text id=\"" << Label.getValue() << "\"" << endl
|
||||
<< " font-family=\"" << Font.getValue() << "\"" << endl
|
||||
<< " font-size=\"" << Scale.getValue() << "\"" << endl
|
||||
<< " fill=\"#" << hr.str() << hg.str() << hb.str() << "\">" << endl;
|
||||
|
||||
for (vector<string>::const_iterator it = Text.getValues().begin(); it != Text.getValues().end(); ++it) {
|
||||
for (vector<string>::const_iterator it = Text.getValues().begin(); it != Text.getValues().end();
|
||||
++it) {
|
||||
result << "<tspan x=\"0\" dy=\"1em\">" << it->c_str() << "</tspan>" << endl;
|
||||
}
|
||||
|
||||
@@ -82,14 +85,17 @@ App::DocumentObjectExecReturn *FeatureViewAnnotation::execute(void)
|
||||
|
||||
// Python Drawing feature ---------------------------------------------------------
|
||||
|
||||
namespace App {
|
||||
namespace App
|
||||
{
|
||||
/// @cond DOXERR
|
||||
PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewAnnotationPython, Drawing::FeatureViewAnnotation)
|
||||
template<> const char* Drawing::FeatureViewAnnotationPython::getViewProviderName(void) const {
|
||||
template<>
|
||||
const char* Drawing::FeatureViewAnnotationPython::getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
// explicit template instantiation
|
||||
template class DrawingExport FeaturePythonT<Drawing::FeatureViewAnnotation>;
|
||||
}
|
||||
}// namespace App
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Drawing
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class DrawingExport FeatureViewAnnotation : public FeatureView
|
||||
class DrawingExport FeatureViewAnnotation: public FeatureView
|
||||
{
|
||||
PROPERTY_HEADER(Drawing::FeatureView);
|
||||
|
||||
@@ -44,18 +44,19 @@ public:
|
||||
FeatureViewAnnotation(void);
|
||||
virtual ~FeatureViewAnnotation();
|
||||
|
||||
App::PropertyStringList Text;
|
||||
App::PropertyString Font;
|
||||
App::PropertyColor TextColor;
|
||||
App::PropertyStringList Text;
|
||||
App::PropertyString Font;
|
||||
App::PropertyColor TextColor;
|
||||
|
||||
/** @name methods override Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
};
|
||||
@@ -63,7 +64,7 @@ public:
|
||||
using FeatureViewAnnotationPython = App::FeaturePythonT<FeatureViewAnnotation>;
|
||||
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
@@ -44,59 +44,88 @@ App::PropertyFloatConstraint::Constraints FeatureViewPart::floatRange = {0.01, 5
|
||||
PROPERTY_SOURCE(Drawing::FeatureViewPart, Drawing::FeatureView)
|
||||
|
||||
|
||||
FeatureViewPart::FeatureViewPart(void)
|
||||
FeatureViewPart::FeatureViewPart(void)
|
||||
{
|
||||
static const char *group = "Shape view";
|
||||
static const char *vgroup = "Drawing view";
|
||||
static const char* group = "Shape view";
|
||||
static const char* vgroup = "Drawing view";
|
||||
|
||||
ADD_PROPERTY_TYPE(Direction ,(0,0,1.0),group,App::Prop_None,"Projection direction");
|
||||
ADD_PROPERTY_TYPE(Source ,(nullptr),group,App::Prop_None,"Shape to view");
|
||||
ADD_PROPERTY_TYPE(ShowHiddenLines ,(false),group,App::Prop_None,"Control the appearance of the dashed hidden lines");
|
||||
ADD_PROPERTY_TYPE(ShowSmoothLines ,(false),group,App::Prop_None,"Control the appearance of the smooth lines");
|
||||
ADD_PROPERTY_TYPE(LineWidth,(0.35),vgroup,App::Prop_None,"The thickness of the viewed lines");
|
||||
ADD_PROPERTY_TYPE(HiddenWidth,(0.15),vgroup,App::Prop_None,"The thickness of the hidden lines, if enabled");
|
||||
ADD_PROPERTY_TYPE(Tolerance,(0.05),vgroup,App::Prop_None,"The tessellation tolerance");
|
||||
ADD_PROPERTY_TYPE(Direction, (0, 0, 1.0), group, App::Prop_None, "Projection direction");
|
||||
ADD_PROPERTY_TYPE(Source, (nullptr), group, App::Prop_None, "Shape to view");
|
||||
ADD_PROPERTY_TYPE(ShowHiddenLines,
|
||||
(false),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"Control the appearance of the dashed hidden lines");
|
||||
ADD_PROPERTY_TYPE(ShowSmoothLines,
|
||||
(false),
|
||||
group,
|
||||
App::Prop_None,
|
||||
"Control the appearance of the smooth lines");
|
||||
ADD_PROPERTY_TYPE(LineWidth,
|
||||
(0.35),
|
||||
vgroup,
|
||||
App::Prop_None,
|
||||
"The thickness of the viewed lines");
|
||||
ADD_PROPERTY_TYPE(HiddenWidth,
|
||||
(0.15),
|
||||
vgroup,
|
||||
App::Prop_None,
|
||||
"The thickness of the hidden lines, if enabled");
|
||||
ADD_PROPERTY_TYPE(Tolerance, (0.05), vgroup, App::Prop_None, "The tessellation tolerance");
|
||||
Tolerance.setConstraints(&floatRange);
|
||||
}
|
||||
|
||||
FeatureViewPart::~FeatureViewPart()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureViewPart::execute(void)
|
||||
App::DocumentObjectExecReturn* FeatureViewPart::execute(void)
|
||||
{
|
||||
std::stringstream result;
|
||||
std::string ViewName = Label.getValue();
|
||||
|
||||
App::DocumentObject* link = Source.getValue();
|
||||
if (!link)
|
||||
if (!link) {
|
||||
return new App::DocumentObjectExecReturn("No object linked");
|
||||
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
}
|
||||
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
|
||||
}
|
||||
TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
|
||||
if (shape.IsNull())
|
||||
if (shape.IsNull()) {
|
||||
return new App::DocumentObjectExecReturn("Linked shape object is empty");
|
||||
}
|
||||
Base::Vector3d Dir = Direction.getValue();
|
||||
bool hidden = ShowHiddenLines.getValue();
|
||||
bool smooth = ShowSmoothLines.getValue();
|
||||
|
||||
try {
|
||||
ProjectionAlgos Alg(shape,Dir);
|
||||
result << "<g"
|
||||
<< " id=\"" << ViewName << "\"" << endl
|
||||
<< " transform=\"rotate("<< Rotation.getValue() << ","<< X.getValue()<<","<<Y.getValue()<<") translate("<< X.getValue()<<","<<Y.getValue()<<") scale("<< Scale.getValue()<<","<<Scale.getValue()<<")\"" << endl
|
||||
<< " >" << endl;
|
||||
ProjectionAlgos Alg(shape, Dir);
|
||||
result << "<g"
|
||||
<< " id=\"" << ViewName << "\"" << endl
|
||||
<< " transform=\"rotate(" << Rotation.getValue() << "," << X.getValue() << ","
|
||||
<< Y.getValue() << ") translate(" << X.getValue() << "," << Y.getValue()
|
||||
<< ") scale(" << Scale.getValue() << "," << Scale.getValue() << ")\"" << endl
|
||||
<< " >" << endl;
|
||||
|
||||
ProjectionAlgos::ExtractionType type = ProjectionAlgos::Plain;
|
||||
if (hidden) type = (ProjectionAlgos::ExtractionType)(type|ProjectionAlgos::WithHidden);
|
||||
if (smooth) type = (ProjectionAlgos::ExtractionType)(type|ProjectionAlgos::WithSmooth);
|
||||
if (hidden) {
|
||||
type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithHidden);
|
||||
}
|
||||
if (smooth) {
|
||||
type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithSmooth);
|
||||
}
|
||||
ProjectionAlgos::XmlAttributes visible_style = {
|
||||
{"stroke-width", to_string(this->LineWidth.getValue() / this->Scale.getValue())}
|
||||
};
|
||||
{"stroke-width", to_string(this->LineWidth.getValue() / this->Scale.getValue())}};
|
||||
ProjectionAlgos::XmlAttributes hidden_style = {
|
||||
{"stroke-width", to_string(this->HiddenWidth.getValue() / this->Scale.getValue()) }
|
||||
};
|
||||
result << Alg.getSVG(type, this->Tolerance.getValue(), visible_style, visible_style, visible_style, hidden_style, hidden_style, hidden_style);
|
||||
{"stroke-width", to_string(this->HiddenWidth.getValue() / this->Scale.getValue())}};
|
||||
result << Alg.getSVG(type,
|
||||
this->Tolerance.getValue(),
|
||||
visible_style,
|
||||
visible_style,
|
||||
visible_style,
|
||||
hidden_style,
|
||||
hidden_style,
|
||||
hidden_style);
|
||||
|
||||
result << "</g>" << endl;
|
||||
|
||||
@@ -111,17 +140,19 @@ App::DocumentObjectExecReturn *FeatureViewPart::execute(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Python Drawing feature ---------------------------------------------------------
|
||||
|
||||
namespace App {
|
||||
namespace App
|
||||
{
|
||||
/// @cond DOXERR
|
||||
PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewPartPython, Drawing::FeatureViewPart)
|
||||
template<> const char* Drawing::FeatureViewPartPython::getViewProviderName(void) const {
|
||||
template<>
|
||||
const char* Drawing::FeatureViewPartPython::getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
// explicit template instantiation
|
||||
template class DrawingExport FeaturePythonT<Drawing::FeatureViewPart>;
|
||||
}
|
||||
}// namespace App
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Drawing
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class DrawingExport FeatureViewPart : public FeatureView
|
||||
class DrawingExport FeatureViewPart: public FeatureView
|
||||
{
|
||||
PROPERTY_HEADER(Part::FeatureViewPart);
|
||||
|
||||
@@ -44,23 +44,24 @@ public:
|
||||
FeatureViewPart(void);
|
||||
virtual ~FeatureViewPart();
|
||||
|
||||
App::PropertyLink Source;
|
||||
App::PropertyLink Source;
|
||||
App::PropertyVector Direction;
|
||||
App::PropertyBool ShowHiddenLines;
|
||||
App::PropertyBool ShowSmoothLines;
|
||||
App::PropertyFloat LineWidth;
|
||||
App::PropertyFloat HiddenWidth;
|
||||
App::PropertyFloatConstraint Tolerance;
|
||||
App::PropertyBool ShowHiddenLines;
|
||||
App::PropertyBool ShowSmoothLines;
|
||||
App::PropertyFloat LineWidth;
|
||||
App::PropertyFloat HiddenWidth;
|
||||
App::PropertyFloatConstraint Tolerance;
|
||||
|
||||
|
||||
/** @name methods override Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
|
||||
@@ -71,7 +72,7 @@ private:
|
||||
using FeatureViewPartPython = App::FeaturePythonT<FeatureViewPart>;
|
||||
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <iomanip>
|
||||
# include <sstream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <App/PropertyUnits.h>
|
||||
@@ -43,53 +43,67 @@ using namespace Drawing;
|
||||
PROPERTY_SOURCE(Drawing::FeatureViewSpreadsheet, Drawing::FeatureView)
|
||||
|
||||
|
||||
FeatureViewSpreadsheet::FeatureViewSpreadsheet(void)
|
||||
FeatureViewSpreadsheet::FeatureViewSpreadsheet(void)
|
||||
{
|
||||
static const char *vgroup = "Drawing view";
|
||||
static const char* vgroup = "Drawing view";
|
||||
|
||||
ADD_PROPERTY_TYPE(CellStart ,("A1"),vgroup,App::Prop_None,"The top left cell of the range to display");
|
||||
ADD_PROPERTY_TYPE(CellEnd ,("B2"),vgroup,App::Prop_None,"The bottom right cell of the range to display");
|
||||
ADD_PROPERTY_TYPE(Font ,("Sans"),vgroup,App::Prop_None,"The name of the font to use");
|
||||
ADD_PROPERTY_TYPE(Color,(0.0f,0.0f,0.0f),vgroup,App::Prop_None,"The default color of the text and lines");
|
||||
ADD_PROPERTY_TYPE(Source ,(nullptr),vgroup,App::Prop_None,"Spreadsheet to view");
|
||||
ADD_PROPERTY_TYPE(LineWidth,(0.35),vgroup,App::Prop_None,"The thickness of the cell lines");
|
||||
ADD_PROPERTY_TYPE(FontSize,(12.0),vgroup,App::Prop_None,"The size of the text");
|
||||
ADD_PROPERTY_TYPE(CellStart,
|
||||
("A1"),
|
||||
vgroup,
|
||||
App::Prop_None,
|
||||
"The top left cell of the range to display");
|
||||
ADD_PROPERTY_TYPE(CellEnd,
|
||||
("B2"),
|
||||
vgroup,
|
||||
App::Prop_None,
|
||||
"The bottom right cell of the range to display");
|
||||
ADD_PROPERTY_TYPE(Font, ("Sans"), vgroup, App::Prop_None, "The name of the font to use");
|
||||
ADD_PROPERTY_TYPE(Color,
|
||||
(0.0f, 0.0f, 0.0f),
|
||||
vgroup,
|
||||
App::Prop_None,
|
||||
"The default color of the text and lines");
|
||||
ADD_PROPERTY_TYPE(Source, (nullptr), vgroup, App::Prop_None, "Spreadsheet to view");
|
||||
ADD_PROPERTY_TYPE(LineWidth, (0.35), vgroup, App::Prop_None, "The thickness of the cell lines");
|
||||
ADD_PROPERTY_TYPE(FontSize, (12.0), vgroup, App::Prop_None, "The size of the text");
|
||||
}
|
||||
|
||||
|
||||
FeatureViewSpreadsheet::~FeatureViewSpreadsheet()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void)
|
||||
App::DocumentObjectExecReturn* FeatureViewSpreadsheet::execute(void)
|
||||
{
|
||||
// quick tests
|
||||
App::DocumentObject* link = Source.getValue();
|
||||
std::string scellstart = CellStart.getValue();
|
||||
std::string scellend = CellEnd.getValue();
|
||||
if (!link)
|
||||
if (!link) {
|
||||
return new App::DocumentObjectExecReturn("No spreadsheet linked");
|
||||
if (!link->getTypeId().isDerivedFrom(Spreadsheet::Sheet::getClassTypeId()))
|
||||
}
|
||||
if (!link->getTypeId().isDerivedFrom(Spreadsheet::Sheet::getClassTypeId())) {
|
||||
return new App::DocumentObjectExecReturn("The linked object is not a spreadsheet");
|
||||
if ( (scellstart.empty()) || (scellend.empty()) )
|
||||
}
|
||||
if ((scellstart.empty()) || (scellend.empty())) {
|
||||
return new App::DocumentObjectExecReturn("Empty cell value");
|
||||
|
||||
}
|
||||
|
||||
// build a list of available columns: A, B, C, ... AA, AB, ... ZY, ZZ.
|
||||
std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
std::vector<std::string> availcolumns;
|
||||
for (int i=0; i<26; ++i) {
|
||||
for (int i = 0; i < 26; ++i) {
|
||||
std::stringstream s;
|
||||
s << alphabet[i];
|
||||
availcolumns.push_back(s.str());
|
||||
}
|
||||
for (int i=0; i<26; ++i) {
|
||||
for (int j=0; i<26; ++i) {
|
||||
for (int i = 0; i < 26; ++i) {
|
||||
for (int j = 0; i < 26; ++i) {
|
||||
std::stringstream s;
|
||||
s << alphabet[i] << alphabet[j];
|
||||
availcolumns.push_back(s.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build rows range and columns range
|
||||
std::vector<std::string> columns;
|
||||
std::vector<int> rows;
|
||||
@@ -106,7 +120,8 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void)
|
||||
std::string endcol = scellend.substr(0, i);
|
||||
bool valid = false;
|
||||
for (std::vector<std::string>::const_iterator j = availcolumns.begin();
|
||||
j != availcolumns.end(); ++j) {
|
||||
j != availcolumns.end();
|
||||
++j) {
|
||||
if ((*j) == startcol) {
|
||||
if ((*j) != endcol) {
|
||||
valid = true;
|
||||
@@ -130,13 +145,14 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (std::exception&) {
|
||||
}
|
||||
catch (std::exception&) {
|
||||
return new App::DocumentObjectExecReturn("Invalid cell range");
|
||||
}
|
||||
|
||||
|
||||
// create the containing group
|
||||
std::string ViewName = Label.getValue();
|
||||
std::stringstream result,hr,hg,hb;
|
||||
std::stringstream result, hr, hg, hb;
|
||||
const App::Color& c = Color.getValue();
|
||||
hr << std::hex << std::setfill('0') << std::setw(2) << (int)(255.0 * c.r);
|
||||
hg << std::hex << std::setfill('0') << std::setw(2) << (int)(255.0 * c.g);
|
||||
@@ -152,8 +168,8 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void)
|
||||
float cellheight = 100;
|
||||
float cellwidth = 100;
|
||||
std::string celltext;
|
||||
Spreadsheet::Sheet* sheet = static_cast<Spreadsheet::Sheet*>(link);
|
||||
std::vector<std::string> skiplist;
|
||||
Spreadsheet::Sheet* sheet = static_cast<Spreadsheet::Sheet*>(link);
|
||||
std::vector<std::string> skiplist;
|
||||
for (std::vector<std::string>::const_iterator col = columns.begin(); col != columns.end();
|
||||
++col) {
|
||||
// create a group for each column
|
||||
@@ -170,14 +186,18 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void)
|
||||
App::Property* prop = sheet->getPropertyByName(address.toString().c_str());
|
||||
std::stringstream field;
|
||||
if (prop) {
|
||||
if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId())))
|
||||
if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId()))) {
|
||||
field << static_cast<App::PropertyQuantity*>(prop)->getValue();
|
||||
else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId())))
|
||||
}
|
||||
else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId()))) {
|
||||
field << static_cast<App::PropertyFloat*>(prop)->getValue();
|
||||
else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId())))
|
||||
}
|
||||
else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId()))) {
|
||||
field << static_cast<App::PropertyString*>(prop)->getValue();
|
||||
else
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
celltext = field.str();
|
||||
}
|
||||
// get colors, style, alignment and span
|
||||
@@ -206,24 +226,30 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void)
|
||||
}
|
||||
if (cell->getStyle(st)) {
|
||||
for (std::set<std::string>::const_iterator i = st.begin(); i != st.end(); ++i) {
|
||||
if ((*i) == "bold")
|
||||
if ((*i) == "bold") {
|
||||
textstyle = textstyle + "font-weight: bold; ";
|
||||
else if ((*i) == "italic")
|
||||
}
|
||||
else if ((*i) == "italic") {
|
||||
textstyle = textstyle + "font-style: italic; ";
|
||||
else if ((*i) == "underline")
|
||||
}
|
||||
else if ((*i) == "underline") {
|
||||
textstyle = textstyle + "text-decoration: underline; ";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cell->getSpans(rowspan, colspan)) {
|
||||
for (int i = 0; i < colspan; ++i) {
|
||||
for (int j = 0; j < rowspan; ++j) {
|
||||
App::CellAddress nextcell(address.row() + j, address.col() + i);
|
||||
if (i > 0)
|
||||
if (i > 0) {
|
||||
cellwidth = cellwidth + sheet->getColumnWidth(nextcell.col());
|
||||
if (j > 0)
|
||||
}
|
||||
if (j > 0) {
|
||||
cellheight = cellheight + sheet->getRowHeight(nextcell.row());
|
||||
if ((i > 0) || (j > 0))
|
||||
}
|
||||
if ((i > 0) || (j > 0)) {
|
||||
skiplist.push_back(nextcell.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,18 +261,21 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void)
|
||||
<< cellwidth << "\" height=\"" << cellheight << "\" style=\"fill:" << bcolor
|
||||
<< ";stroke-width:" << LineWidth.getValue() / Scale.getValue() << ";stroke:#"
|
||||
<< hr.str() << hg.str() << hb.str() << ";\" />" << std::endl;
|
||||
if (alignment & Spreadsheet::Cell::ALIGNMENT_LEFT)
|
||||
if (alignment & Spreadsheet::Cell::ALIGNMENT_LEFT) {
|
||||
result << " <text style=\"" << textstyle << "\" x=\""
|
||||
<< coloffset + FontSize.getValue() / 2 << "\" y=\""
|
||||
<< rowoffset + 0.75 * cellheight << "\" font-family=\"";
|
||||
if (alignment & Spreadsheet::Cell::ALIGNMENT_HCENTER)
|
||||
}
|
||||
if (alignment & Spreadsheet::Cell::ALIGNMENT_HCENTER) {
|
||||
result << " <text text-anchor=\"middle\" style=\"" << textstyle << "\" x=\""
|
||||
<< coloffset + cellwidth / 2 << "\" y=\""
|
||||
<< rowoffset + 0.75 * cellheight << "\" font-family=\"";
|
||||
if (alignment & Spreadsheet::Cell::ALIGNMENT_RIGHT)
|
||||
}
|
||||
if (alignment & Spreadsheet::Cell::ALIGNMENT_RIGHT) {
|
||||
result << " <text text-anchor=\"end\" style=\"" << textstyle << "\" x=\""
|
||||
<< coloffset + (cellwidth - FontSize.getValue() / 2) << "\" y=\""
|
||||
<< rowoffset + 0.75 * cellheight << "\" font-family=\"";
|
||||
}
|
||||
result << Font.getValue() << "\""
|
||||
<< " font-size=\"" << FontSize.getValue() << "\""
|
||||
<< " fill=\"" << fcolor << "\">" << celltext << "</text>" << std::endl;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Drawing
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class DrawingExport FeatureViewSpreadsheet : public FeatureView
|
||||
class DrawingExport FeatureViewSpreadsheet: public FeatureView
|
||||
{
|
||||
PROPERTY_HEADER(Drawing::FeatureView);
|
||||
|
||||
@@ -42,27 +42,28 @@ public:
|
||||
/// Constructor
|
||||
FeatureViewSpreadsheet(void);
|
||||
virtual ~FeatureViewSpreadsheet();
|
||||
App::PropertyLink Source;
|
||||
App::PropertyString CellStart;
|
||||
App::PropertyString CellEnd;
|
||||
App::PropertyString Font;
|
||||
App::PropertyColor Color;
|
||||
App::PropertyFloat LineWidth;
|
||||
App::PropertyFloat FontSize;
|
||||
App::PropertyLink Source;
|
||||
App::PropertyString CellStart;
|
||||
App::PropertyString CellEnd;
|
||||
App::PropertyString Font;
|
||||
App::PropertyColor Color;
|
||||
App::PropertyFloat LineWidth;
|
||||
App::PropertyFloat FontSize;
|
||||
|
||||
/** @name methods override Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <iomanip>
|
||||
# include <iterator>
|
||||
# include <sstream>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
# include <boost/regex.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#endif
|
||||
|
||||
#include "FeatureViewSymbol.h"
|
||||
@@ -42,18 +42,20 @@ using namespace std;
|
||||
PROPERTY_SOURCE(Drawing::FeatureViewSymbol, Drawing::FeatureView)
|
||||
|
||||
|
||||
FeatureViewSymbol::FeatureViewSymbol(void)
|
||||
FeatureViewSymbol::FeatureViewSymbol(void)
|
||||
{
|
||||
static const char *vgroup = "Drawing view";
|
||||
|
||||
ADD_PROPERTY_TYPE(Symbol,(""),vgroup,App::Prop_Hidden,"The SVG code defining this symbol");
|
||||
ADD_PROPERTY_TYPE(EditableTexts,(""),vgroup,App::Prop_None,"Substitution values for the editable strings in this symbol");
|
||||
static const char* vgroup = "Drawing view";
|
||||
|
||||
ADD_PROPERTY_TYPE(Symbol, (""), vgroup, App::Prop_Hidden, "The SVG code defining this symbol");
|
||||
ADD_PROPERTY_TYPE(EditableTexts,
|
||||
(""),
|
||||
vgroup,
|
||||
App::Prop_None,
|
||||
"Substitution values for the editable strings in this symbol");
|
||||
}
|
||||
|
||||
FeatureViewSymbol::~FeatureViewSymbol()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/// get called by the container when a Property was changed
|
||||
void FeatureViewSymbol::onChanged(const App::Property* prop)
|
||||
@@ -63,7 +65,7 @@ void FeatureViewSymbol::onChanged(const App::Property* prop)
|
||||
std::vector<string> eds;
|
||||
std::string svg = Symbol.getValue();
|
||||
if (!svg.empty()) {
|
||||
boost::regex e ("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
boost::regex e("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
std::string::const_iterator tbegin, tend;
|
||||
tbegin = svg.begin();
|
||||
tend = svg.end();
|
||||
@@ -79,13 +81,13 @@ void FeatureViewSymbol::onChanged(const App::Property* prop)
|
||||
Drawing::FeatureView::onChanged(prop);
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void)
|
||||
App::DocumentObjectExecReturn* FeatureViewSymbol::execute(void)
|
||||
{
|
||||
std::string svg = Symbol.getValue();
|
||||
const std::vector<std::string>& editText = EditableTexts.getValues();
|
||||
|
||||
|
||||
if (!editText.empty()) {
|
||||
boost::regex e1 ("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
boost::regex e1("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
|
||||
string::const_iterator begin, end;
|
||||
begin = svg.begin();
|
||||
end = svg.end();
|
||||
@@ -98,9 +100,14 @@ App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void)
|
||||
if (count < editText.size()) {
|
||||
// change values of editable texts. Also strip the "freecad:editable"
|
||||
// attribute so it isn't detected by the page
|
||||
boost::regex e2 ("(<text.*?)(freecad:editable=\""+what[1].str()+"\")(.*?<tspan.*?)>(.*?)(</tspan>)");
|
||||
boost::regex e2("(<text.*?)(freecad:editable=\"" + what[1].str()
|
||||
+ "\")(.*?<tspan.*?)>(.*?)(</tspan>)");
|
||||
std::back_insert_iterator<std::string> out(newsvg);
|
||||
boost::regex_replace(out, begin, what[0].second, e2, "$1$3>"+editText[count]+"$5");
|
||||
boost::regex_replace(out,
|
||||
begin,
|
||||
what[0].second,
|
||||
e2,
|
||||
"$1$3>" + editText[count] + "$5");
|
||||
}
|
||||
count++;
|
||||
begin = what[0].second;
|
||||
@@ -110,13 +117,13 @@ App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void)
|
||||
newsvg.insert(newsvg.end(), begin, end);
|
||||
svg = newsvg;
|
||||
}
|
||||
|
||||
|
||||
std::stringstream result;
|
||||
result << "<g transform=\"translate(" << X.getValue() << "," << Y.getValue() << ")"
|
||||
<< " rotate(" << Rotation.getValue() << ")"
|
||||
<< " scale(" << Scale.getValue() << ")\">" << endl
|
||||
<< svg << endl
|
||||
<< "</g>" << endl;
|
||||
result << "<g transform=\"translate(" << X.getValue() << "," << Y.getValue() << ")"
|
||||
<< " rotate(" << Rotation.getValue() << ")"
|
||||
<< " scale(" << Scale.getValue() << ")\">" << endl
|
||||
<< svg << endl
|
||||
<< "</g>" << endl;
|
||||
|
||||
// Apply the resulting fragment
|
||||
ViewResult.setValue(result.str().c_str());
|
||||
@@ -126,14 +133,17 @@ App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void)
|
||||
|
||||
// Python Drawing feature ---------------------------------------------------------
|
||||
|
||||
namespace App {
|
||||
namespace App
|
||||
{
|
||||
/// @cond DOXERR
|
||||
PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewSymbolPython, Drawing::FeatureViewSymbol)
|
||||
template<> const char* Drawing::FeatureViewSymbolPython::getViewProviderName(void) const {
|
||||
template<>
|
||||
const char* Drawing::FeatureViewSymbolPython::getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
// explicit template instantiation
|
||||
template class DrawingExport FeaturePythonT<Drawing::FeatureViewSymbol>;
|
||||
}
|
||||
}// namespace App
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Drawing
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class DrawingExport FeatureViewSymbol : public FeatureView
|
||||
class DrawingExport FeatureViewSymbol: public FeatureView
|
||||
{
|
||||
PROPERTY_HEADER(Drawing::FeatureView);
|
||||
|
||||
@@ -44,17 +44,18 @@ public:
|
||||
FeatureViewSymbol(void);
|
||||
virtual ~FeatureViewSymbol();
|
||||
|
||||
App::PropertyString Symbol;
|
||||
App::PropertyStringList EditableTexts;
|
||||
App::PropertyString Symbol;
|
||||
App::PropertyStringList EditableTexts;
|
||||
|
||||
/** @name methods override Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual App::DocumentObjectExecReturn* execute(void);
|
||||
//@}
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawingView";
|
||||
}
|
||||
|
||||
@@ -65,7 +66,7 @@ protected:
|
||||
using FeatureViewSymbolPython = App::FeaturePythonT<FeatureViewSymbol>;
|
||||
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include "PageGroup.h"
|
||||
@@ -36,12 +36,11 @@ using namespace Drawing;
|
||||
|
||||
PROPERTY_SOURCE(Drawing::PageGroup, App::DocumentObjectGroup)
|
||||
|
||||
PageGroup::PageGroup(void)
|
||||
PageGroup::PageGroup(void)
|
||||
{
|
||||
static const char *group = "Drawings";
|
||||
ADD_PROPERTY_TYPE(Pages,(nullptr),group,App::Prop_None,"List of pages");
|
||||
static const char* group = "Drawings";
|
||||
ADD_PROPERTY_TYPE(Pages, (nullptr), group, App::Prop_None, "List of pages");
|
||||
}
|
||||
|
||||
PageGroup::~PageGroup()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Drawing
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class DrawingExport PageGroup : public App::DocumentObjectGroup
|
||||
class DrawingExport PageGroup: public App::DocumentObjectGroup
|
||||
{
|
||||
PROPERTY_HEADER(Drawing::PageGroup);
|
||||
|
||||
@@ -45,14 +45,14 @@ public:
|
||||
App::PropertyLinkList Pages;
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const
|
||||
{
|
||||
return "DrawingGui::ViewProviderDrawing";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} //namespace Drawing
|
||||
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#include "PreCompiled.h"
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
// boost
|
||||
@@ -40,26 +39,20 @@
|
||||
|
||||
// OpenCasCade
|
||||
#include <Approx_Curve3d.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepLProp_CLProps.hxx>
|
||||
#include <BRepMesh_IncrementalMesh.hxx>
|
||||
#include <BRepLib.hxx>
|
||||
#include <Geom_BezierCurve.hxx>
|
||||
#include <Geom_BSplineCurve.hxx>
|
||||
#include <BRepMesh_IncrementalMesh.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <GeomConvert_BSplineCurveKnotSplitting.hxx>
|
||||
#include <GeomConvert_BSplineCurveToBezierCurve.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Elips.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#include <Geom_BSplineCurve.hxx>
|
||||
#include <Geom_BezierCurve.hxx>
|
||||
#include <HLRAlgo_Projector.hxx>
|
||||
#include <HLRBRep_Algo.hxx>
|
||||
#include <HLRBRep_HLRToShape.hxx>
|
||||
#include <HLRAlgo_Projector.hxx>
|
||||
#include <Poly_Polygon3D.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
@@ -69,9 +62,15 @@
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Elips.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
# include <BRepAdaptor_HCurve.hxx>
|
||||
#include <BRepAdaptor_HCurve.hxx>
|
||||
#endif
|
||||
|
||||
#endif // _PreComp_
|
||||
#endif// _PreComp_
|
||||
#endif
|
||||
|
||||
@@ -22,25 +22,25 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
#include <sstream>
|
||||
|
||||
# include <BRepLib.hxx>
|
||||
# include <BRepMesh_IncrementalMesh.hxx>
|
||||
# include <gp_Ax2.hxx>
|
||||
# include <gp_Dir.hxx>
|
||||
# include <gp_Pnt.hxx>
|
||||
# include <HLRBRep_Algo.hxx>
|
||||
# include <HLRBRep_HLRToShape.hxx>
|
||||
# include <HLRAlgo_Projector.hxx>
|
||||
# include <TopExp_Explorer.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <TopoDS_Shape.hxx>
|
||||
#include <BRepLib.hxx>
|
||||
#include <BRepMesh_IncrementalMesh.hxx>
|
||||
#include <HLRAlgo_Projector.hxx>
|
||||
#include <HLRBRep_Algo.hxx>
|
||||
#include <HLRBRep_HLRToShape.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#endif
|
||||
|
||||
#include <Base/Exception.h>
|
||||
|
||||
#include "ProjectionAlgos.h"
|
||||
#include "DrawingExport.h"
|
||||
#include "ProjectionAlgos.h"
|
||||
|
||||
|
||||
using namespace Drawing;
|
||||
@@ -51,60 +51,61 @@ using namespace std;
|
||||
//===========================================================================
|
||||
|
||||
|
||||
ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape &Input, const Base::Vector3d &Dir)
|
||||
: Input(Input), Direction(Dir)
|
||||
ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape& Input, const Base::Vector3d& Dir)
|
||||
: Input(Input)
|
||||
, Direction(Dir)
|
||||
{
|
||||
execute();
|
||||
}
|
||||
|
||||
ProjectionAlgos::~ProjectionAlgos()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
//added by tanderson. aka blobfish.
|
||||
//projection algorithms build a 2d curve(pcurve) but no 3d curve.
|
||||
//this causes problems with meshing algorithms after save and load.
|
||||
static const TopoDS_Shape& build3dCurves(const TopoDS_Shape &shape)
|
||||
// added by tanderson. aka blobfish.
|
||||
// projection algorithms build a 2d curve(pcurve) but no 3d curve.
|
||||
// this causes problems with meshing algorithms after save and load.
|
||||
static const TopoDS_Shape& build3dCurves(const TopoDS_Shape& shape)
|
||||
{
|
||||
TopExp_Explorer it;
|
||||
for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next())
|
||||
BRepLib::BuildCurve3d(TopoDS::Edge(it.Current()));
|
||||
return shape;
|
||||
TopExp_Explorer it;
|
||||
for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next()) {
|
||||
BRepLib::BuildCurve3d(TopoDS::Edge(it.Current()));
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
|
||||
void ProjectionAlgos::execute(void)
|
||||
{
|
||||
Handle( HLRBRep_Algo ) brep_hlr = new HLRBRep_Algo;
|
||||
Handle(HLRBRep_Algo) brep_hlr = new HLRBRep_Algo;
|
||||
brep_hlr->Add(Input);
|
||||
|
||||
gp_Ax2 transform(gp_Pnt(0,0,0),gp_Dir(Direction.x,Direction.y,Direction.z));
|
||||
HLRAlgo_Projector projector( transform );
|
||||
gp_Ax2 transform(gp_Pnt(0, 0, 0), gp_Dir(Direction.x, Direction.y, Direction.z));
|
||||
HLRAlgo_Projector projector(transform);
|
||||
brep_hlr->Projector(projector);
|
||||
brep_hlr->Update();
|
||||
brep_hlr->Hide();
|
||||
|
||||
// extracting the result sets:
|
||||
HLRBRep_HLRToShape shapes( brep_hlr );
|
||||
HLRBRep_HLRToShape shapes(brep_hlr);
|
||||
|
||||
V = build3dCurves(shapes.VCompound ());// hard edge visibly
|
||||
V = build3dCurves(shapes.VCompound()); // hard edge visibly
|
||||
V1 = build3dCurves(shapes.Rg1LineVCompound());// Smoth edges visibly
|
||||
VN = build3dCurves(shapes.RgNLineVCompound());// contour edges visibly
|
||||
VO = build3dCurves(shapes.OutLineVCompound());// contours apparents visibly
|
||||
VI = build3dCurves(shapes.IsoLineVCompound());// isoparamtriques visibly
|
||||
H = build3dCurves(shapes.HCompound ());// hard edge invisibly
|
||||
H = build3dCurves(shapes.HCompound()); // hard edge invisibly
|
||||
H1 = build3dCurves(shapes.Rg1LineHCompound());// Smoth edges invisibly
|
||||
HN = build3dCurves(shapes.RgNLineHCompound());// contour edges invisibly
|
||||
HO = build3dCurves(shapes.OutLineHCompound());// contours apparents invisibly
|
||||
HI = build3dCurves(shapes.IsoLineHCompound());// isoparamtriques invisibly
|
||||
}
|
||||
|
||||
string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
double tolerance,
|
||||
XmlAttributes V_style,
|
||||
XmlAttributes V0_style,
|
||||
XmlAttributes V1_style,
|
||||
XmlAttributes H_style,
|
||||
XmlAttributes H0_style,
|
||||
string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
double tolerance,
|
||||
XmlAttributes V_style,
|
||||
XmlAttributes V0_style,
|
||||
XmlAttributes V1_style,
|
||||
XmlAttributes H_style,
|
||||
XmlAttributes H0_style,
|
||||
XmlAttributes H1_style)
|
||||
{
|
||||
stringstream result;
|
||||
@@ -118,14 +119,12 @@ string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
H_style.insert({"stroke-dasharray", "0.2,0.1)"});
|
||||
H_style.insert({"fill", "none"});
|
||||
H_style.insert({"transform", "scale(1,-1)"});
|
||||
BRepMesh_IncrementalMesh(H,tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : H_style)
|
||||
result << " " << attribute.first << "=\""
|
||||
<< attribute.second << "\"\n";
|
||||
result << " >" << endl
|
||||
<< output.exportEdges(H)
|
||||
<< "</g>" << endl;
|
||||
BRepMesh_IncrementalMesh(H, tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : H_style) {
|
||||
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
|
||||
}
|
||||
result << " >" << endl << output.exportEdges(H) << "</g>" << endl;
|
||||
}
|
||||
if (!HO.IsNull() && (type & WithHidden)) {
|
||||
H0_style.insert({"stroke", "rgb(0, 0, 0)"});
|
||||
@@ -135,14 +134,12 @@ string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
H0_style.insert({"stroke-dasharray", "0.02,0.1)"});
|
||||
H0_style.insert({"fill", "none"});
|
||||
H0_style.insert({"transform", "scale(1,-1)"});
|
||||
BRepMesh_IncrementalMesh(HO,tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : H0_style)
|
||||
result << " " << attribute.first << "=\""
|
||||
<< attribute.second << "\"\n";
|
||||
result << " >" << endl
|
||||
<< output.exportEdges(HO)
|
||||
<< "</g>" << endl;
|
||||
BRepMesh_IncrementalMesh(HO, tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : H0_style) {
|
||||
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
|
||||
}
|
||||
result << " >" << endl << output.exportEdges(HO) << "</g>" << endl;
|
||||
}
|
||||
if (!VO.IsNull()) {
|
||||
V0_style.insert({"stroke", "rgb(0, 0, 0)"});
|
||||
@@ -151,14 +148,12 @@ string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
V0_style.insert({"stroke-linejoin", "miter"});
|
||||
V0_style.insert({"fill", "none"});
|
||||
V0_style.insert({"transform", "scale(1,-1)"});
|
||||
BRepMesh_IncrementalMesh(VO,tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : V0_style)
|
||||
result << " " << attribute.first << "=\""
|
||||
<< attribute.second << "\"\n";
|
||||
result << " >" << endl
|
||||
<< output.exportEdges(VO)
|
||||
<< "</g>" << endl;
|
||||
BRepMesh_IncrementalMesh(VO, tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : V0_style) {
|
||||
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
|
||||
}
|
||||
result << " >" << endl << output.exportEdges(VO) << "</g>" << endl;
|
||||
}
|
||||
if (!V.IsNull()) {
|
||||
V_style.insert({"stroke", "rgb(0, 0, 0)"});
|
||||
@@ -167,14 +162,12 @@ string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
V_style.insert({"stroke-linejoin", "miter"});
|
||||
V_style.insert({"fill", "none"});
|
||||
V_style.insert({"transform", "scale(1,-1)"});
|
||||
BRepMesh_IncrementalMesh(V,tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : V_style)
|
||||
result << " " << attribute.first << "=\""
|
||||
<< attribute.second << "\"\n";
|
||||
result << " >" << endl
|
||||
<< output.exportEdges(V)
|
||||
<< "</g>" << endl;
|
||||
BRepMesh_IncrementalMesh(V, tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : V_style) {
|
||||
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
|
||||
}
|
||||
result << " >" << endl << output.exportEdges(V) << "</g>" << endl;
|
||||
}
|
||||
if (!V1.IsNull() && (type & WithSmooth)) {
|
||||
V1_style.insert({"stroke", "rgb(0, 0, 0)"});
|
||||
@@ -183,14 +176,12 @@ string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
V1_style.insert({"stroke-linejoin", "miter"});
|
||||
V1_style.insert({"fill", "none"});
|
||||
V1_style.insert({"transform", "scale(1,-1)"});
|
||||
BRepMesh_IncrementalMesh(V1,tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : V1_style)
|
||||
result << " " << attribute.first << "=\""
|
||||
<< attribute.second << "\"\n";
|
||||
result << " >" << endl
|
||||
<< output.exportEdges(V1)
|
||||
<< "</g>" << endl;
|
||||
BRepMesh_IncrementalMesh(V1, tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : V1_style) {
|
||||
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
|
||||
}
|
||||
result << " >" << endl << output.exportEdges(V1) << "</g>" << endl;
|
||||
}
|
||||
if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
|
||||
H1_style.insert({"stroke", "rgb(0, 0, 0)"});
|
||||
@@ -200,14 +191,12 @@ string ProjectionAlgos::getSVG(ExtractionType type,
|
||||
H1_style.insert({"stroke-dasharray", "0.09,0.05)"});
|
||||
H1_style.insert({"fill", "none"});
|
||||
H1_style.insert({"transform", "scale(1,-1)"});
|
||||
BRepMesh_IncrementalMesh(H1,tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : H1_style)
|
||||
result << " " << attribute.first << "=\""
|
||||
<< attribute.second << "\"\n";
|
||||
result << " >" << endl
|
||||
<< output.exportEdges(H1)
|
||||
<< "</g>" << endl;
|
||||
BRepMesh_IncrementalMesh(H1, tolerance);
|
||||
result << "<g";
|
||||
for (const auto& attribute : H1_style) {
|
||||
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
|
||||
}
|
||||
result << " >" << endl << output.exportEdges(H1) << "</g>" << endl;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
@@ -220,34 +209,34 @@ string ProjectionAlgos::getDXF(ExtractionType type, double /*scale*/, double tol
|
||||
DXFOutput output;
|
||||
|
||||
if (!H.IsNull() && (type & WithHidden)) {
|
||||
//float width = 0.15f/scale;
|
||||
BRepMesh_IncrementalMesh(H,tolerance);
|
||||
result << output.exportEdges(H);
|
||||
// float width = 0.15f/scale;
|
||||
BRepMesh_IncrementalMesh(H, tolerance);
|
||||
result << output.exportEdges(H);
|
||||
}
|
||||
if (!HO.IsNull() && (type & WithHidden)) {
|
||||
//float width = 0.15f/scale;
|
||||
BRepMesh_IncrementalMesh(HO,tolerance);
|
||||
result << output.exportEdges(HO);
|
||||
// float width = 0.15f/scale;
|
||||
BRepMesh_IncrementalMesh(HO, tolerance);
|
||||
result << output.exportEdges(HO);
|
||||
}
|
||||
if (!VO.IsNull()) {
|
||||
//float width = 0.35f/scale;
|
||||
BRepMesh_IncrementalMesh(VO,tolerance);
|
||||
result << output.exportEdges(VO);
|
||||
// float width = 0.35f/scale;
|
||||
BRepMesh_IncrementalMesh(VO, tolerance);
|
||||
result << output.exportEdges(VO);
|
||||
}
|
||||
if (!V.IsNull()) {
|
||||
//float width = 0.35f/scale;
|
||||
BRepMesh_IncrementalMesh(V,tolerance);
|
||||
result << output.exportEdges(V);
|
||||
// float width = 0.35f/scale;
|
||||
BRepMesh_IncrementalMesh(V, tolerance);
|
||||
result << output.exportEdges(V);
|
||||
}
|
||||
if (!V1.IsNull() && (type & WithSmooth)) {
|
||||
//float width = 0.35f/scale;
|
||||
BRepMesh_IncrementalMesh(V1,tolerance);
|
||||
result << output.exportEdges(V1);
|
||||
// float width = 0.35f/scale;
|
||||
BRepMesh_IncrementalMesh(V1, tolerance);
|
||||
result << output.exportEdges(V1);
|
||||
}
|
||||
if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
|
||||
//float width = 0.15f/scale;
|
||||
BRepMesh_IncrementalMesh(H1,tolerance);
|
||||
result << output.exportEdges(H1);
|
||||
// float width = 0.15f/scale;
|
||||
BRepMesh_IncrementalMesh(H1, tolerance);
|
||||
result << output.exportEdges(H1);
|
||||
}
|
||||
|
||||
return result.str();
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#ifndef _ProjectionAlgos_h_
|
||||
#define _ProjectionAlgos_h_
|
||||
|
||||
#include <string>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <string>
|
||||
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Mod/Drawing/DrawingGlobal.h>
|
||||
@@ -41,44 +41,47 @@ class DrawingExport ProjectionAlgos
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
ProjectionAlgos(const TopoDS_Shape &Input,const Base::Vector3d &Dir);
|
||||
ProjectionAlgos(const TopoDS_Shape& Input, const Base::Vector3d& Dir);
|
||||
virtual ~ProjectionAlgos();
|
||||
|
||||
void execute(void);
|
||||
|
||||
enum ExtractionType {
|
||||
enum ExtractionType
|
||||
{
|
||||
Plain = 0,
|
||||
WithHidden = 1,
|
||||
WithSmooth = 2
|
||||
};
|
||||
using XmlAttributes = std::map<std::string,std::string>;
|
||||
using XmlAttributes = std::map<std::string, std::string>;
|
||||
|
||||
std::string getSVG(ExtractionType type, double tolerance=0.05,
|
||||
XmlAttributes V_style=XmlAttributes(),
|
||||
XmlAttributes V0_style=XmlAttributes(),
|
||||
XmlAttributes V1_style=XmlAttributes(),
|
||||
XmlAttributes H_style=XmlAttributes(),
|
||||
XmlAttributes H0_style=XmlAttributes(),
|
||||
XmlAttributes H1_style=XmlAttributes());
|
||||
std::string getDXF(ExtractionType type, double scale, double tolerance);//added by Dan Falck 2011/09/25
|
||||
std::string getSVG(ExtractionType type,
|
||||
double tolerance = 0.05,
|
||||
XmlAttributes V_style = XmlAttributes(),
|
||||
XmlAttributes V0_style = XmlAttributes(),
|
||||
XmlAttributes V1_style = XmlAttributes(),
|
||||
XmlAttributes H_style = XmlAttributes(),
|
||||
XmlAttributes H0_style = XmlAttributes(),
|
||||
XmlAttributes H1_style = XmlAttributes());
|
||||
std::string
|
||||
getDXF(ExtractionType type, double scale, double tolerance);// added by Dan Falck 2011/09/25
|
||||
|
||||
|
||||
const TopoDS_Shape &Input;
|
||||
const Base::Vector3d &Direction;
|
||||
const TopoDS_Shape& Input;
|
||||
const Base::Vector3d& Direction;
|
||||
|
||||
TopoDS_Shape V ;// hard edge visibly
|
||||
TopoDS_Shape V; // hard edge visibly
|
||||
TopoDS_Shape V1;// Smoth edges visibly
|
||||
TopoDS_Shape VN;// contour edges visibly
|
||||
TopoDS_Shape VO;// contours apparents visibly
|
||||
TopoDS_Shape VI;// isoparamtriques visibly
|
||||
TopoDS_Shape H ;// hard edge invisibly
|
||||
TopoDS_Shape H; // hard edge invisibly
|
||||
TopoDS_Shape H1;// Smoth edges invisibly
|
||||
TopoDS_Shape HN;// contour edges invisibly
|
||||
TopoDS_Shape HO;// contours apparents invisibly
|
||||
TopoDS_Shape HI;// isoparamtriques invisibly
|
||||
};
|
||||
|
||||
} //namespace Drawing
|
||||
}// namespace Drawing
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user