[TD]combine @wmayer and edi271 changes re command extensions

This commit is contained in:
wandererfan
2022-01-05 19:27:34 -05:00
committed by WandererFan
parent de1ab433e5
commit f2d624cede
5 changed files with 163 additions and 137 deletions

View File

@@ -78,6 +78,7 @@ using namespace TechDrawGui;
using namespace TechDraw;
using namespace std;
namespace TechDrawGui {
//internal structures and sort functions
struct dimVertex{
// save a dimension defining vertex and its point
@@ -111,6 +112,7 @@ bool _checkSelAndObj(Gui::Command* cmd,
std::vector<Gui::SelectionObject>& selection,
TechDraw::DrawViewPart*& objFeat,
std::string message);
}
//===========================================================================
// TechDraw_ExtensionInsertDiameter
@@ -2081,6 +2083,7 @@ bool CmdTechDrawExtensionCreateLengthArc::isActive(void)
return (havePage && haveView);
}
namespace TechDrawGui {
//===========================================================================
// internal helper routines
//===========================================================================
@@ -2196,6 +2199,7 @@ std::vector<TechDraw::DrawViewDimension*>_getDimensions(std::vector<Gui::Selecti
}
return validDimension;
}
}
//------------------------------------------------------------------------------
void CreateTechDrawCommandsExtensionDims(void)
@@ -2228,4 +2232,4 @@ void CreateTechDrawCommandsExtensionDims(void)
rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateHorizChamferDimension());
rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateVertChamferDimension());
rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateLengthArc());
}
}

View File

@@ -79,9 +79,11 @@ using namespace TechDrawGui;
using namespace TechDraw;
using namespace std;
LineAttributes activeAttributes; // container holding global line attributes
namespace TechDrawGui {
//LineAttributes activeAttributes; // container holding global line attributes
//internal helper functions
lineAttributes& _getActiveLineAttributes();
bool _circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C);
Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3);
void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor);
@@ -157,6 +159,7 @@ void execHoleCircle(Gui::Command* cmd){
objFeat->requestPaint();
Gui::Command::commitCommand();
}
}
DEF_STD_CMD_A(CmdTechDrawExtensionHoleCircle)
@@ -168,7 +171,7 @@ CmdTechDrawExtensionHoleCircle::CmdTechDrawExtensionHoleCircle()
sMenuText = QT_TR_NOOP("Draw bolt circle centerlines");
sToolTipText = QT_TR_NOOP("Draw the centerlines of a bolt circle\n\
- pick favoured line attributes\n\
- select at least three cirles of a bolt circle\n\
- select at least three circles of a bolt circle\n\
- click this button");
sWhatsThis = "TechDraw_ExtensionHoleCircle";
sStatusTip = sToolTipText;
@@ -352,7 +355,7 @@ void CmdTechDrawExtensionCircleCenterLinesGroup::languageChange()
arc2->setToolTip(QApplication::translate("TechDraw_Extension",
"Draw the centerlines of a bolt circle\n\
- pick favoured line attributes\n\
- select at least three cirles of a bolt circle\n\
- select at least three circles of a bolt circle\n\
- click this buttone"));
arc2->setStatusTip(arc2->toolTip());
}
@@ -724,7 +727,7 @@ CmdTechDrawExtensionSelectLineAttributes::CmdTechDrawExtensionSelectLineAttribut
void CmdTechDrawExtensionSelectLineAttributes::activated(int iMsg)
{
Q_UNUSED(iMsg);
Gui::Control().showDialog(new TaskDlgSelectLineAttributes(& activeAttributes));
Gui::Control().showDialog(new TaskDlgSelectLineAttributes(&_getActiveLineAttributes()));
}
bool CmdTechDrawExtensionSelectLineAttributes::isActive(void)
@@ -1433,8 +1436,8 @@ void execExtendShortenLine(Gui::Command* cmd, bool extend){
Base::Vector3d P1 = genLine->points.at(1);
if (baseGeo->cosmetic){
std::string uniTag = baseGeo->getCosmeticTag();
int oldStyle;
float oldWeight;
int oldStyle = 1;
float oldWeight = 1.0f;
App::Color oldColor;
std::vector<std::string> toDelete;
toDelete.push_back(uniTag);
@@ -1647,6 +1650,13 @@ bool CmdTechDrawExtendShortenLineGroup::isActive(void)
//===========================================================================
// internal helper routines
//===========================================================================
namespace TechDrawGui {
lineAttributes& _getActiveLineAttributes()
{
static lineAttributes attributes;
return attributes;
}
bool _checkSel(Gui::Command* cmd,
std::vector<Gui::SelectionObject>& selection,
@@ -1826,13 +1836,12 @@ void _intersectionCC(TechDraw::BaseGeom* geom1, TechDraw::BaseGeom* geom2, std::
}
}
Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3){
// Circle through 3 points, calculate center point
Base::Vector2d p12d(p1.x,p1.y);
Base::Vector2d p22d(p2.x,p2.y);
Base::Vector2d p32d(p3.x,p3.y);
Base::Vector2d centerPoint = Part::Geom2dCircle::getCircleCenter(p12d, p22d, p32d);
return Base::Vector3d(centerPoint.x, centerPoint.y, 0.0);
Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3) {
Base::Vector2d v1(p1.x, p1.y);
Base::Vector2d v2(p2.x, p2.y);
Base::Vector2d v3(p3.x, p3.y);
Base::Vector2d c = Part::Geom2dCircle::getCircleCenter(v1, v2, v3);
return Base::Vector3d(c.x, c.y, 0.0);
}
bool _circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C){
@@ -1909,16 +1918,16 @@ void _createThreadLines(std::vector<std::string> SubNames, TechDraw::DrawViewPar
void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge) {
// set line attributes of a cosmetic edge
cosEdge->m_format.m_style = int(activeAttributes.getStyle()+1);
cosEdge->m_format.m_weight = activeAttributes.getWidthValue();
cosEdge->m_format.m_color = activeAttributes.getColorValue();
cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle();
cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue();
cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue();
}
void _setLineAttributes(TechDraw::CenterLine* cosEdge) {
// set line attributes of a centerline
cosEdge->m_format.m_style = int(activeAttributes.getStyle()+1);
cosEdge->m_format.m_weight = activeAttributes.getWidthValue();
cosEdge->m_format.m_color = activeAttributes.getColorValue();
// set line attributes of a cosmetic edge
cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle();
cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue();
cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue();
}
void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color) {
@@ -1927,6 +1936,7 @@ void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight
cosEdge->m_format.m_weight = weight;
cosEdge->m_format.m_color = color;
}
}
//------------------------------------------------------------------------------
void CreateTechDrawCommandsExtensions(void)

View File

@@ -74,37 +74,61 @@ using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
enum class EdgeStyle {
solid = 1,
dashed = 2,
dotted = 3,
dashdotted = 4
};
enum class EdgeWidth {
small = 1,
middle = 2,
thick = 3
};
enum class EdgeColor {
black = 1,
grey = 2,
red = 3,
green = 4,
blue = 5,
magenta = 6,
cyan = 7,
yellow = 8
};
//===========================================================================
// managing global line attributes
//===========================================================================
LineAttributes::LineAttributes(void)
lineAttributes::lineAttributes(void)
{
style = dotted;
width = middle;
color = black;
style = int(EdgeStyle::dotted);
width = int(EdgeWidth::middle);
color = int(EdgeColor::black);
}
void LineAttributes::setStyle(edgeStyle newStyle)
void lineAttributes::setStyle(int newStyle)
{
style = newStyle;
}
void LineAttributes::setWidth(edgeWidth newWidth)
void lineAttributes::setWidth(int newWidth)
{
width = newWidth;
}
float LineAttributes::getWidthValue(void)
float lineAttributes::getWidthValue(void)
{
switch(width){
case small:
switch(EdgeWidth(width)) {
case EdgeWidth::small:
return 0.18f;
break;
case middle:
case EdgeWidth::middle:
return 0.35f;
break;
case thick:
case EdgeWidth::thick:
return 0.5f;
break;
default:
@@ -112,36 +136,36 @@ float LineAttributes::getWidthValue(void)
}
}
void LineAttributes::setColor(edgeColor newColor)
void lineAttributes::setColor(int newColor)
{
color = newColor;
}
App::Color LineAttributes::getColorValue(void)
App::Color lineAttributes::getColorValue(void)
{
switch(color){
case black:
switch(EdgeColor(color)) {
case EdgeColor::black:
return App::Color(0.0,0.0,0.0);
break;
case grey:
case EdgeColor::grey:
return App::Color(0.7,0.7,0.7);
break;
case red:
case EdgeColor::red:
return App::Color(1.0,0.0,0.0);
break;
case green:
case EdgeColor::green:
return App::Color(0.0,1.0,0.0);
break;
case blue:
case EdgeColor::blue:
return App::Color(0.0,0.0,1.0);
break;
case magenta:
case EdgeColor::magenta:
return App::Color(1.0,0.0,1.0);
break;
case cyan:
case EdgeColor::cyan:
return App::Color(0.0,1.0,1.0);
break;
case yellow:
case EdgeColor::yellow:
return App::Color(1.0,1.0,0.0);
break;
default:
@@ -169,10 +193,9 @@ dimAttributes activeDimAttributes; // container holding dimension attributes
// TaskSelectLineAttributes
//===========================================================================
TaskSelectLineAttributes::TaskSelectLineAttributes(LineAttributes * ptActiveAttributes) :
ui(new Ui_TaskSelectLineAttributes),
activeAttributes(ptActiveAttributes)
TaskSelectLineAttributes::TaskSelectLineAttributes(lineAttributes * ptActiveAttributes) :
activeAttributes(ptActiveAttributes),
ui(new Ui_TaskSelectLineAttributes)
{
ui->setupUi(this);
@@ -202,64 +225,64 @@ void TaskSelectLineAttributes::changeEvent(QEvent *e)
void TaskSelectLineAttributes::setUiEdit()
{
setWindowTitle(QObject::tr("Select Line Attributes"));
LineAttributes::edgeStyle lineStyle = activeAttributes->getStyle();
switch(lineStyle){
case LineAttributes::solid:
setWindowTitle(tr("Select line attributes"));
int lineStyle = activeAttributes->getStyle();
switch(EdgeStyle(lineStyle)) {
case EdgeStyle::solid:
ui->rbSolid->setChecked(true);
break;
case LineAttributes::dashed:
case EdgeStyle::dashed:
ui->rbDashed->setChecked(true);
break;
case LineAttributes::dotted:
case EdgeStyle::dotted:
ui->rbDotted->setChecked(true);
break;
case LineAttributes::dashdotted:
case EdgeStyle::dashdotted:
ui->rbDashDotted->setChecked(true);
break;
default:
ui->rbDashDotted->setChecked(true);
}
LineAttributes::edgeWidth lineWidth = activeAttributes->getWidth();
switch(lineWidth){
case LineAttributes::small:
int lineWidth = activeAttributes->getWidth();
switch(EdgeWidth(lineWidth)) {
case EdgeWidth::small:
ui->rbThin->setChecked(true);
break;
case LineAttributes::middle:
case EdgeWidth::middle:
ui->rbMiddle->setChecked(true);
break;
case LineAttributes::thick:
case EdgeWidth::thick:
ui->rbThick->setChecked(true);
break;
default:
ui->rbMiddle->setChecked(true);
}
LineAttributes::edgeColor lineColor = activeAttributes->getColor();
switch(lineColor){
case LineAttributes::black:
int lineColor = activeAttributes->getColor();
switch(EdgeColor(lineColor)) {
case EdgeColor::black:
ui->rbBlack->setChecked(true);
break;
case LineAttributes::grey:
case EdgeColor::grey:
ui->rbGrey->setChecked(true);
break;
case LineAttributes::red:
case EdgeColor::red:
ui->rbRed->setChecked(true);
break;
case LineAttributes::green:
case EdgeColor::green:
ui->rbGreen->setChecked(true);
break;
case LineAttributes::blue:
case EdgeColor::blue:
ui->rbBlue->setChecked(true);
break;
case LineAttributes::magenta:
case EdgeColor::magenta:
ui->rbMagenta->setChecked(true);
break;
case LineAttributes::cyan:
case EdgeColor::cyan:
ui->rbCyan->setChecked(true);
break;
case LineAttributes::yellow:
case EdgeColor::yellow:
ui->rbYellow->setChecked(true);
break;
default:
@@ -274,60 +297,60 @@ void TaskSelectLineAttributes::setUiEdit()
bool TaskSelectLineAttributes::accept()
{
if (ui->rbSolid->isChecked()){
activeAttributes->setStyle(LineAttributes::solid);
activeAttributes->setStyle(int(EdgeStyle::solid));
}
else if (ui->rbDashed->isChecked()){
activeAttributes->setStyle(LineAttributes::dashed);
activeAttributes->setStyle(int(EdgeStyle::dashed));
}
else if (ui->rbDotted->isChecked()){
activeAttributes->setStyle(LineAttributes::dotted);
activeAttributes->setStyle(int(EdgeStyle::dotted));
}
else if (ui->rbDashDotted->isChecked()){
activeAttributes->setStyle(LineAttributes::dashdotted);
activeAttributes->setStyle(int(EdgeStyle::dashdotted));
}
else {
activeAttributes->setStyle(LineAttributes::dashdotted);
activeAttributes->setStyle(int(EdgeStyle::dashdotted));
}
if (ui->rbThin->isChecked()){
activeAttributes->setWidth(LineAttributes::small);
activeAttributes->setWidth(int(EdgeWidth::small));
}
else if (ui->rbMiddle->isChecked()){
activeAttributes->setWidth(LineAttributes::middle);
activeAttributes->setWidth(int(EdgeWidth::middle));
}
else if (ui->rbThick->isChecked()){
activeAttributes->setWidth(LineAttributes::thick);
activeAttributes->setWidth(int(EdgeWidth::thick));
}
else {
activeAttributes->setWidth(LineAttributes::middle);
activeAttributes->setWidth(int(EdgeWidth::middle));
}
if (ui->rbBlack->isChecked()){
activeAttributes->setColor(LineAttributes::black);
activeAttributes->setColor(int(EdgeColor::black));
}
else if (ui->rbGrey->isChecked()){
activeAttributes->setColor(LineAttributes::grey);
activeAttributes->setColor(int(EdgeColor::grey));
}
else if (ui->rbRed->isChecked()){
activeAttributes->setColor(LineAttributes::red);
activeAttributes->setColor(int(EdgeColor::red));
}
else if (ui->rbGreen->isChecked()){
activeAttributes->setColor(LineAttributes::green);
activeAttributes->setColor(int(EdgeColor::green));
}
else if (ui->rbBlue->isChecked()){
activeAttributes->setColor(LineAttributes::blue);
activeAttributes->setColor(int(EdgeColor::blue));
}
else if (ui->rbMagenta->isChecked()){
activeAttributes->setColor(LineAttributes::magenta);
activeAttributes->setColor(int(EdgeColor::magenta));
}
else if (ui->rbCyan->isChecked()){
activeAttributes->setColor(LineAttributes::cyan);
activeAttributes->setColor(int(EdgeColor::cyan));
}
else if (ui->rbYellow->isChecked()){
activeAttributes->setColor(LineAttributes::yellow);
activeAttributes->setColor(int(EdgeColor::yellow));
}
else {
activeAttributes->setColor(LineAttributes::black);
activeAttributes->setColor(int(EdgeColor::black));
}
double cascadeSpacing = ui->sbSpacing->value();
@@ -338,16 +361,14 @@ bool TaskSelectLineAttributes::accept()
bool TaskSelectLineAttributes::reject()
{
//there's nothing to do.
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
return false;
return true;
}
//===========================================================================
// TaskDlgSelectLineAttributes
//===========================================================================
TaskDlgSelectLineAttributes::TaskDlgSelectLineAttributes(LineAttributes * ptActiveAttributes)
TaskDlgSelectLineAttributes::TaskDlgSelectLineAttributes(lineAttributes * ptActiveAttributes)
: TaskDialog()
{
widget = new TaskSelectLineAttributes(ptActiveAttributes);
@@ -388,4 +409,4 @@ bool TaskDlgSelectLineAttributes::reject()
}
#include <Mod/TechDraw/Gui/moc_TaskSelectLineAttributes.cpp>
#include <Mod/TechDraw/Gui/moc_TaskSelectLineAttributes.cpp>

View File

@@ -30,10 +30,6 @@
#include <Mod/TechDraw/App/Cosmetic.h>
#include <Mod/TechDraw/Gui/ui_TaskSelectLineAttributes.h>
class Ui_TaskSelectLineAttributes;
class dimAttributes {
double cascadeSpacing;
@@ -72,37 +68,33 @@ class QGIView;
class QGIPrimPath;
class MDIViewPage;
class ViewProviderViewPart;
class Ui_TaskSelectLineAttributes;
class LineAttributes {
public:
enum edgeStyle{solid, dashed, dotted, dashdotted};
enum edgeWidth{small, middle, thick };
enum edgeColor{black, grey, red, green, blue, magenta, cyan, yellow};
private:
edgeStyle style;
edgeWidth width;
edgeColor color;
class lineAttributes {
int style;
int width;
int color;
public:
public:
LineAttributes(void);
void setStyle(edgeStyle);
edgeStyle getStyle(void) {return style;}
void setWidth(edgeWidth);
edgeWidth getWidth(void) {return width;}
lineAttributes(void);
void setStyle(int);
int getStyle(void) const {return style;}
void setWidth(int);
int getWidth(void) const {return width;}
float getWidthValue(void);
void setColor(edgeColor);
edgeColor getColor(void) {return color;}
void setColor(int);
int getColor(void) const {return color;}
App::Color getColorValue(void);
}; // class LineAttributes
}; // class lineAttributes
class TaskSelectLineAttributes : public QWidget
{
Q_OBJECT
public:
TaskSelectLineAttributes(LineAttributes * ptActiveAttributes);
TaskSelectLineAttributes(lineAttributes * ptActiveAttributes);
~TaskSelectLineAttributes();
public Q_SLOTS:
@@ -111,7 +103,6 @@ public:
virtual bool accept();
virtual bool reject();
void updateTask();
LineAttributes* activeAttributes;
protected Q_SLOTS:
@@ -121,8 +112,8 @@ protected:
void setUiEdit(void);
private:
lineAttributes* activeAttributes;
std::unique_ptr<Ui_TaskSelectLineAttributes> ui;
}; // class TaskSelectLineAttributes
class TaskDlgSelectLineAttributes : public Gui::TaskView::TaskDialog
@@ -130,7 +121,7 @@ class TaskDlgSelectLineAttributes : public Gui::TaskView::TaskDialog
Q_OBJECT
public:
TaskDlgSelectLineAttributes(LineAttributes * ptActiveAttributes);
TaskDlgSelectLineAttributes(lineAttributes * ptActiveAttributes);
~TaskDlgSelectLineAttributes();
public:

View File

@@ -31,17 +31,17 @@
<item row="0" column="0">
<widget class="QLabel" name="label_styles">
<property name="text">
<string>Linestyles:</string>
<string>Line style:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rbSolid">
<property name="toolTip">
<string>Set Line style to solid</string>
<string>Set line style to solid</string>
</property>
<property name="text">
<string>solid</string>
<string>Solid</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -54,7 +54,7 @@
<item row="2" column="0">
<widget class="QRadioButton" name="rbDashed">
<property name="text">
<string>dashed</string>
<string>Dashed</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -67,7 +67,7 @@
<item row="3" column="0">
<widget class="QRadioButton" name="rbDotted">
<property name="text">
<string>dotted</string>
<string>Dotted</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -80,7 +80,7 @@
<item row="4" column="0">
<widget class="QRadioButton" name="rbDashDotted">
<property name="text">
<string>dashdot</string>
<string>Dashdot</string>
</property>
<property name="checked">
<bool>true</bool>
@@ -100,14 +100,14 @@
<item row="0" column="0">
<widget class="QLabel" name="label_width">
<property name="text">
<string>Lineswidth:</string>
<string>Line width:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rbThin">
<property name="text">
<string>thin 0,18</string>
<string>Thin 0,18</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -120,7 +120,7 @@
<item row="2" column="0">
<widget class="QRadioButton" name="rbMiddle">
<property name="text">
<string>middle 0,35</string>
<string>Middle 0,35</string>
</property>
<property name="checked">
<bool>true</bool>
@@ -136,7 +136,7 @@
<item row="3" column="0">
<widget class="QRadioButton" name="rbThick">
<property name="text">
<string>thick 0,70</string>
<string>Thick 0,70</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -153,14 +153,14 @@
<item row="0" column="0">
<widget class="QLabel" name="label_colors">
<property name="text">
<string>Linecolors:</string>
<string>Line color:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rbBlack">
<property name="text">
<string>black</string>
<string>Black</string>
</property>
<property name="checked">
<bool>true</bool>
@@ -176,7 +176,7 @@
<item row="1" column="1">
<widget class="QRadioButton" name="rbBlue">
<property name="text">
<string>blue</string>
<string>Blue</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -189,7 +189,7 @@
<item row="2" column="0">
<widget class="QRadioButton" name="rbGrey">
<property name="text">
<string>grey</string>
<string>Grey</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -202,7 +202,7 @@
<item row="2" column="1">
<widget class="QRadioButton" name="rbMagenta">
<property name="text">
<string>magenta</string>
<string>Magenta</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -215,7 +215,7 @@
<item row="3" column="0">
<widget class="QRadioButton" name="rbRed">
<property name="text">
<string>red</string>
<string>Red</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -228,7 +228,7 @@
<item row="3" column="1">
<widget class="QRadioButton" name="rbCyan">
<property name="text">
<string>cyan</string>
<string>Cyan</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -241,7 +241,7 @@
<item row="4" column="0">
<widget class="QRadioButton" name="rbGreen">
<property name="text">
<string>green</string>
<string>Green</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
@@ -254,7 +254,7 @@
<item row="4" column="1">
<widget class="QRadioButton" name="rbYellow">
<property name="text">
<string>yellow</string>
<string>Yellow</string>
</property>
<property name="autoExclusive">
<bool>true</bool>