All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -21,11 +21,10 @@
***************************************************************************/
# include <qglobal.h>
# include <iomanip>
# include <ios>
# include <Inventor/SbBSPTree.h>
#include <qglobal.h>
#include <iomanip>
#include <ios>
#include <Inventor/SbBSPTree.h>
#include <Base/FileInfo.h>
@@ -35,14 +34,17 @@
using namespace Gui;
class SoVectorizeItem {
class SoVectorizeItem
{
public:
SoVectorizeItem() {
SoVectorizeItem()
{
this->type = UNDEFINED;
this->depth = 0.0f;
}
// quick and easy type system
enum Type {
enum Type
{
UNDEFINED,
LINE,
TRIANGLE,
@@ -51,34 +53,40 @@ public:
IMAGE
};
int type;
float depth; // for depth sorting
float depth; // for depth sorting
};
class SoVectorizePoint : public SoVectorizeItem {
class SoVectorizePoint: public SoVectorizeItem
{
public:
SoVectorizePoint() {
SoVectorizePoint()
{
this->type = POINT;
this->vidx = 0;
this->size = 1.0f;
this->col = 0;
}
int vidx; // index to BSPtree coordinate
float size; // Coin size (pixels)
int vidx; // index to BSPtree coordinate
float size; // Coin size (pixels)
uint32_t col;
};
class SoVectorizeTriangle : public SoVectorizeItem {
class SoVectorizeTriangle: public SoVectorizeItem
{
public:
SoVectorizeTriangle() {
SoVectorizeTriangle()
{
this->type = TRIANGLE;
}
int vidx[3]; // indices to BSPtree coordinates
int vidx[3]; // indices to BSPtree coordinates
uint32_t col[3];
};
class SoVectorizeLine : public SoVectorizeItem {
class SoVectorizeLine: public SoVectorizeItem
{
public:
SoVectorizeLine() {
SoVectorizeLine()
{
this->type = LINE;
vidx[0] = 0;
vidx[1] = 0;
@@ -87,48 +95,54 @@ public:
this->pattern = 0xffff;
this->width = 1.0f;
}
int vidx[2]; // indices to BSPtree coordinates
int vidx[2]; // indices to BSPtree coordinates
uint32_t col[2];
uint16_t pattern; // Coin line pattern
float width; // Coin line width (pixels)
};
class SoVectorizeText : public SoVectorizeItem {
class SoVectorizeText: public SoVectorizeItem
{
public:
SoVectorizeText() {
SoVectorizeText()
{
this->type = TEXT;
this->fontsize = 10;
this->col = 0;
this->justification = LEFT;
}
enum Justification {
enum Justification
{
LEFT,
RIGHT,
CENTER
};
SbName fontname;
float fontsize; // size in normalized coordinates
float fontsize; // size in normalized coordinates
SbString string;
SbVec2f pos; // pos in normalized coordinates
SbVec2f pos; // pos in normalized coordinates
uint32_t col;
Justification justification;
};
class SoVectorizeImage : public SoVectorizeItem {
class SoVectorizeImage: public SoVectorizeItem
{
public:
SoVectorizeImage() {
SoVectorizeImage()
{
this->type = IMAGE;
this->image.data = nullptr;
this->image.nc = 0;
}
SbVec2f pos; // pos in normalized coordinates
SbVec2f size; // size in normalized coordinates
SbVec2f pos; // pos in normalized coordinates
SbVec2f size; // size in normalized coordinates
struct Image {
const unsigned char * data;
struct Image
{
const unsigned char* data;
SbVec2s size;
int nc;
} image;
@@ -143,7 +157,7 @@ SoSVGVectorOutput::~SoSVGVectorOutput()
closeFile();
}
SbBool SoSVGVectorOutput::openFile (const char *filename)
SbBool SoSVGVectorOutput::openFile(const char* filename)
{
Base::FileInfo fi(filename);
#ifdef _MSC_VER
@@ -155,10 +169,11 @@ SbBool SoSVGVectorOutput::openFile (const char *filename)
return this->file.is_open();
}
void SoSVGVectorOutput::closeFile ()
void SoSVGVectorOutput::closeFile()
{
if (this->file.is_open())
if (this->file.is_open()) {
this->file.close();
}
}
std::fstream& SoSVGVectorOutput::getFileStream()
@@ -168,47 +183,50 @@ std::fstream& SoSVGVectorOutput::getFileStream()
// ----------------------------------------------------------------
namespace Gui {
namespace Gui
{
class SoFCVectorizeSVGActionP
{
public:
SoFCVectorizeSVGActionP(SoFCVectorizeSVGAction * p) {
SoFCVectorizeSVGActionP(SoFCVectorizeSVGAction* p)
{
this->publ = p;
}
void printCircle(const SbVec3f & v, const SbColor & c, const float radius) const;
void printSquare(const SbVec3f & v, const SbColor & c, const float size) const;
void printTriangle(const SbVec3f * v, const SbColor * c) const;
void printTriangle(const SoVectorizeTriangle * item) const;
void printLine(const SoVectorizeLine * item) const;
void printPoint(const SoVectorizePoint * item) const;
void printText(const SoVectorizeText * item) const;
void printImage(const SoVectorizeImage * item) const;
void printCircle(const SbVec3f& v, const SbColor& c, const float radius) const;
void printSquare(const SbVec3f& v, const SbColor& c, const float size) const;
void printTriangle(const SbVec3f* v, const SbColor* c) const;
void printTriangle(const SoVectorizeTriangle* item) const;
void printLine(const SoVectorizeLine* item) const;
void printPoint(const SoVectorizePoint* item) const;
void printText(const SoVectorizeText* item) const;
void printImage(const SoVectorizeImage* item) const;
private:
SoFCVectorizeSVGAction * publ;
SoFCVectorizeSVGAction* publ;
};
}
} // namespace Gui
void SoFCVectorizeSVGActionP::printText(const SoVectorizeText * item) const
void SoFCVectorizeSVGActionP::printText(const SoVectorizeText* item) const
{
SbVec2f mul = publ->getRotatedViewportSize();
SbVec2f add = publ->getRotatedViewportStartpos();
float posx = item->pos[0]*mul[0]+add[0];
float posy = item->pos[1]*mul[1]+add[1];
float posx = item->pos[0] * mul[0] + add[0];
float posy = item->pos[1] * mul[1] + add[1];
std::ostream& str = publ->getSVGOutput()->getFileStream();
str << "<text x=\"" << posx << "\" y=\"" << posy << "\" "
"font-size=\"" << item->fontsize * mul[1] << "px\">"
<< item->string.getString() << "</text>" << std::endl;
str << "<text x=\"" << posx << "\" y=\"" << posy
<< "\" "
"font-size=\""
<< item->fontsize * mul[1] << "px\">" << item->string.getString() << "</text>" << std::endl;
}
void SoFCVectorizeSVGActionP::printTriangle(const SoVectorizeTriangle * item) const
void SoFCVectorizeSVGActionP::printTriangle(const SoVectorizeTriangle* item) const
{
SbVec2f mul = publ->getRotatedViewportSize();
SbVec2f add = publ->getRotatedViewportStartpos();
const SbBSPTree & bsp = publ->getBSPTree();
const SbBSPTree& bsp = publ->getBSPTree();
SbVec3f v[3];
SbColor c[3];
@@ -217,7 +235,7 @@ void SoFCVectorizeSVGActionP::printTriangle(const SoVectorizeTriangle * item) co
for (int i = 0; i < 3; i++) {
v[i] = bsp.getPoint(item->vidx[i]);
v[i][0] = (v[i][0] * mul[0]) + add[0];
v[i][1] = ((1.0f-v[i][1]) * mul[1]) + add[1];
v[i][1] = ((1.0f - v[i][1]) * mul[1]) + add[1];
c[i].setPackedValue(item->col[i], t[i]);
}
this->printTriangle((SbVec3f*)v, (SbColor*)c);
@@ -254,11 +272,11 @@ Separator {
<?xml version="1.0"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="red" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="35" y2="80">
<stop offset="0" stop-color="rgb(255,0,0)" stop-opacity="1"/>
<stop offset="1" stop-color="rgb(255,0,0)" stop-opacity="0"/>
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <linearGradient id="red"
gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="35" y2="80"> <stop offset="0"
stop-color="rgb(255,0,0)" stop-opacity="1"/> <stop offset="1" stop-color="rgb(255,0,0)"
stop-opacity="0"/>
</linearGradient>
<linearGradient id="blue" gradientUnits="userSpaceOnUse" x1="100" y1="50" x2="0" y2="50">
<stop offset="0" stop-color="rgb(0,0,255)" stop-opacity="1"/>
@@ -289,27 +307,24 @@ Separator {
</g>
</svg>
*/
void SoFCVectorizeSVGActionP::printTriangle(const SbVec3f * v, const SbColor * c) const
void SoFCVectorizeSVGActionP::printTriangle(const SbVec3f* v, const SbColor* c) const
{
if (v[0] == v[1] || v[1] == v[2] || v[0] == v[2])
if (v[0] == v[1] || v[1] == v[2] || v[0] == v[2]) {
return;
}
uint32_t cc = c->getPackedValue();
std::ostream& str = publ->getSVGOutput()->getFileStream();
str << "<path d=\"M "
<< v[2][0] << "," << v[2][1] << " L "
<< v[1][0] << "," << v[1][1] << " "
str << "<path d=\"M " << v[2][0] << "," << v[2][1] << " L " << v[1][0] << "," << v[1][1] << " "
<< v[0][0] << "," << v[0][1] << " z\"" << std::endl
<< " style=\"fill:#"
<< std::hex << std::setw(6) << std::setfill('0') << (cc >> 8)
<< "; stroke:#"
<< std::hex << std::setw(6) << std::setfill('0') << (cc >> 8)
<< ";" << std::endl
<< " style=\"fill:#" << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8)
<< "; stroke:#" << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8) << ";"
<< std::endl
<< " stroke-width:" << publ->getLineWidth() << ";" << std::endl
<< " stroke-linecap:round;stroke-linejoin:round\"/>" << std::endl;
}
void SoFCVectorizeSVGActionP::printCircle(const SbVec3f & v, const SbColor & c, const float radius) const
void SoFCVectorizeSVGActionP::printCircle(const SbVec3f& v, const SbColor& c, const float radius) const
{
// todo
Q_UNUSED(v);
@@ -317,7 +332,7 @@ void SoFCVectorizeSVGActionP::printCircle(const SbVec3f & v, const SbColor & c,
Q_UNUSED(radius);
}
void SoFCVectorizeSVGActionP::printSquare(const SbVec3f & v, const SbColor & c, const float size) const
void SoFCVectorizeSVGActionP::printSquare(const SbVec3f& v, const SbColor& c, const float size) const
{
// todo
Q_UNUSED(v);
@@ -325,12 +340,12 @@ void SoFCVectorizeSVGActionP::printSquare(const SbVec3f & v, const SbColor & c,
Q_UNUSED(size);
}
void SoFCVectorizeSVGActionP::printLine(const SoVectorizeLine * item) const
void SoFCVectorizeSVGActionP::printLine(const SoVectorizeLine* item) const
{
SbVec2f mul = publ->getRotatedViewportSize();
SbVec2f add = publ->getRotatedViewportStartpos();
const SbBSPTree & bsp = publ->getBSPTree();
const SbBSPTree& bsp = publ->getBSPTree();
SbVec3f v[2];
SbColor c[2];
@@ -339,7 +354,7 @@ void SoFCVectorizeSVGActionP::printLine(const SoVectorizeLine * item) const
for (int i = 0; i < 2; i++) {
v[i] = bsp.getPoint(item->vidx[i]);
v[i][0] = (v[i][0] * mul[0]) + add[0];
v[i][1] = ((1.0f-v[i][1]) * mul[1]) + add[1];
v[i][1] = ((1.0f - v[i][1]) * mul[1]) + add[1];
c[i].setPackedValue(item->col[i], t[i]);
}
uint32_t cc = c[0].getPackedValue();
@@ -348,19 +363,18 @@ void SoFCVectorizeSVGActionP::printLine(const SoVectorizeLine * item) const
str << "<line "
<< "x1=\"" << v[0][0] << "\" y1=\"" << v[0][1] << "\" "
<< "x2=\"" << v[1][0] << "\" y2=\"" << v[1][1] << "\" "
<< "stroke=\"#"
<< std::hex << std::setw(6) << std::setfill('0') << (cc >> 8) << "\""
<< "stroke=\"#" << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8) << "\""
<< " stroke-linecap=\"square\" "
<< " stroke-width=\"" << publ->getLineWidth() << "\" />\n";
}
void SoFCVectorizeSVGActionP::printPoint(const SoVectorizePoint * item) const
void SoFCVectorizeSVGActionP::printPoint(const SoVectorizePoint* item) const
{
// todo
Q_UNUSED(item);
}
void SoFCVectorizeSVGActionP::printImage(const SoVectorizeImage * item) const
void SoFCVectorizeSVGActionP::printImage(const SoVectorizeImage* item) const
{
// todo
Q_UNUSED(item);
@@ -387,8 +401,7 @@ SoFCVectorizeSVGAction::~SoFCVectorizeSVGAction()
delete this->p;
}
SoSVGVectorOutput *
SoFCVectorizeSVGAction::getSVGOutput() const
SoSVGVectorOutput* SoFCVectorizeSVGAction::getSVGOutput() const
{
return static_cast<SoSVGVectorOutput*>(SoVectorizeAction::getOutput());
}
@@ -399,17 +412,19 @@ void SoFCVectorizeSVGAction::printHeader() const
str << R"(<?xml version="1.0" encoding="UTF-8" standalone="no"?>)" << std::endl;
str << "<!-- Created with FreeCAD (https://www.freecad.org) -->" << std::endl;
str << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
str << R"( xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events")" << std::endl;
str << R"( version="1.1" baseProfile="full")" << std::endl;
str << R"( xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events")"
<< std::endl;
str << R"( version="1.1" baseProfile="full")" << std::endl;
SbVec2f size = getPageSize();
if (this->getOrientation() == LANDSCAPE) {
SbSwap<float>(size[0], size[1]);
}
if (getUseMM()) {
str << " width=\"" << size[0] << "mm\" height=\"" << size[1] << "mm\""<< std::endl;
str << " width=\"" << size[0] << "mm\" height=\"" << size[1] << "mm\"" << std::endl;
str << " viewBox=\"0 0 " << size[0] << " " << size[1] << "\">" << std::endl;
} else { //original code used px
}
else { // original code used px
str << " width=\"" << size[0] << "\" height=\"" << size[1] << "\">" << std::endl;
}
str << "<g>" << std::endl;
@@ -423,8 +438,7 @@ void SoFCVectorizeSVGAction::printFooter() const
}
void SoFCVectorizeSVGAction::printViewport() const
{
}
{}
void SoFCVectorizeSVGAction::printBackground() const
{
@@ -434,7 +448,7 @@ void SoFCVectorizeSVGAction::printBackground() const
SbVec2f mul = getRotatedViewportSize();
SbVec2f add = getRotatedViewportStartpos();
float x[2],y[2];
float x[2], y[2];
x[0] = add[0];
x[1] = mul[0] - add[0];
y[0] = add[1];
@@ -447,40 +461,38 @@ void SoFCVectorizeSVGAction::printBackground() const
std::ostream& str = this->getSVGOutput()->getFileStream();
str << "</g>" << std::endl;
str << "<path" << std::endl;
str << " d=\"M "
<< x[0] << "," << y[0] << " L "
<< x[1] << "," << y[0] << " L "
<< x[1] << "," << y[1] << " L "
<< x[0] << "," << y[1] << " L "
<< x[0] << "," << y[0] << " z \"" << std::endl;
str << " style=\"fill:#"
<< std::hex << std::setw(6) << std::setfill('0') << (cc >> 8)
str << " d=\"M " << x[0] << "," << y[0] << " L " << x[1] << "," << y[0] << " L " << x[1]
<< "," << y[1] << " L " << x[0] << "," << y[1] << " L " << x[0] << "," << y[0] << " z \""
<< std::endl;
str << " style=\"fill:#" << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8)
<< ";fill-opacity:1;fill-rule:evenodd;stroke:none;"
"stroke-width:" << getLineWidth() << ";stroke-linecap:butt;stroke-linejoin:"
"stroke-width:"
<< getLineWidth()
<< ";stroke-linecap:butt;stroke-linejoin:"
"miter;stroke-opacity:1\" />\n";
str << "<g>" << std::endl;
}
void SoFCVectorizeSVGAction::printItem(const SoVectorizeItem * item) const
void SoFCVectorizeSVGAction::printItem(const SoVectorizeItem* item) const
{
switch (item->type) {
case SoVectorizeItem::TRIANGLE:
this->p->printTriangle(static_cast<const SoVectorizeTriangle*>(item));
break;
case SoVectorizeItem::LINE:
this->p->printLine(static_cast<const SoVectorizeLine*>(item));
break;
case SoVectorizeItem::POINT:
this->p->printPoint(static_cast<const SoVectorizePoint*>(item));
break;
case SoVectorizeItem::TEXT:
this->p->printText(static_cast<const SoVectorizeText*>(item));
break;
case SoVectorizeItem::IMAGE:
this->p->printImage(static_cast<const SoVectorizeImage*>(item));
break;
default:
assert(0 && "unsupported item");
break;
case SoVectorizeItem::TRIANGLE:
this->p->printTriangle(static_cast<const SoVectorizeTriangle*>(item));
break;
case SoVectorizeItem::LINE:
this->p->printLine(static_cast<const SoVectorizeLine*>(item));
break;
case SoVectorizeItem::POINT:
this->p->printPoint(static_cast<const SoVectorizePoint*>(item));
break;
case SoVectorizeItem::TEXT:
this->p->printText(static_cast<const SoVectorizeText*>(item));
break;
case SoVectorizeItem::IMAGE:
this->p->printImage(static_cast<const SoVectorizeImage*>(item));
break;
default:
assert(0 && "unsupported item");
break;
}
}