aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Syrjä <mikko@3d-system.fi>2019-04-03 01:03:35 +0300
committerMikko Syrjä <mikko@3d-system.fi>2019-04-03 01:03:35 +0300
commit65596429891cd3a8f402d16d17b13fbeda671ffa (patch)
tree842e23a842405b9a5c56ddba62a79a0b6abffdee
parent2121977dad193f63d3db54bb46dbaccef2c61518 (diff)
downloadsymedit-65596429891cd3a8f402d16d17b13fbeda671ffa.tar.gz
symedit-65596429891cd3a8f402d16d17b13fbeda671ffa.zip
Some preliminary arc support.
-rw-r--r--Editor.qml64
-rw-r--r--symbol.cpp79
-rw-r--r--symbol.h7
-rw-r--r--symedit.cpp43
-rw-r--r--symedit.h4
5 files changed, 114 insertions, 83 deletions
diff --git a/Editor.qml b/Editor.qml
index 04ce48d..1666e60 100644
--- a/Editor.qml
+++ b/Editor.qml
@@ -98,7 +98,7 @@ Rectangle
{
if ( tool === Editor.Tool.Line )
{
- manager.addPointItem(Operation.Line, Qt.point(startx, starty), Qt.point(endx, endy), colorindex, 0)
+ manager.addLineItem(Operation.Line, Qt.point(startx, starty), Qt.point(endx, endy), 0, colorindex, 0)
symbol = manager.getSymbol(true)
}
else if ( tool === Editor.Tool.RectCenter || tool === Editor.Tool.RectCorner )
@@ -108,10 +108,10 @@ Rectangle
startx -= (endx - startx)
starty -= (endy - starty)
}
- if ( manager.addPointItem(Operation.Rectangle, Qt.point(startx, starty), Qt.point(endx, endy), colorindex, fillitem) )
+ if ( manager.addLineItem(Operation.Rectangle, Qt.point(startx, starty), Qt.point(endx, endy), 0, colorindex, fillitem) )
symbol = manager.getSymbol(true)
}
- else if ( tool > 30 && tool < 40 ) // circle
+ else if ( tool > 30 && tool < 50 ) // circle or arc
{
var deltax = Math.abs(mousex - startx)
var deltay = Math.abs(mousey - starty)
@@ -121,25 +121,34 @@ Rectangle
radius = (deltax < deltay ? deltax : deltay) / 2
centerx = (startx + endx) / 2
centery = (starty + endy) / 2
+ if ( manager.addPointItem(Operation.Circle, Qt.point(centerx, centery), radius, colorindex, fillitem) )
+ symbol = manager.getSymbol(true)
}
else if ( tool === Editor.Tool.CircleDiameter )
{
radius = Math.sqrt(deltax * deltax + deltay * deltay) / 2
centerx = (startx + endx) / 2
centery = (starty + endy) / 2
+ if ( manager.addPointItem(Operation.Circle, Qt.point(centerx, centery), radius, colorindex, fillitem) )
+ symbol = manager.getSymbol(true)
}
else if ( tool === Editor.Tool.CircleCenter )
{
radius = Math.sqrt(deltax * deltax + deltay * deltay)
- centerx = startx
- centery = starty
+ if ( manager.addPointItem(Operation.Circle, Qt.point(startx, starty), radius, colorindex, fillitem) )
+ symbol = manager.getSymbol(true)
+ }
+ else if ( tool === Editor.Tool.ArcSemi )
+ {
+ radius = Math.sqrt(deltax * deltax + deltay * deltay) / 2
+ if ( manager.addLineItem(Operation.Arc, Qt.point(startx, starty), Qt.point(endx, endy), radius, colorindex, fillitem) )
+ symbol = manager.getSymbol(true)
+ }
+ else if ( tool === Editor.Tool.ArcQuarter )
+ {
+ radius = Math.sqrt(deltax * deltax + deltay * deltay)
+ //##
}
- if ( manager.addValueItem(Operation.Circle, Qt.point(centerx, centery), radius, colorindex, fillitem) )
- symbol = manager.getSymbol(true)
- }
- else if ( tool > 40 && tool < 50 ) // arc
- {
-
}
else if ( tool > 50 && tool < 60 ) // text
{
@@ -196,17 +205,12 @@ Rectangle
context.stroke()
}
- function paintsemicircle(context, center, start, end, radius, fill)
+ function paintsemicircle(context, start, end, radius, fill)
{
-/*
-// context.beginPath().moveTo((center.x + max + offsetx) * scalexy, (max - center.y + offsety) * scalexy)
- context.beginPath().moveTo((start.x + max + offsetx) * scalexy, (max - start.y + offsety) * scalexy)
- context.arcTo(
- (start.x + max - radius + offsetx) * scalexy,
- (max - start.y - radius + offsety) * scalexy,
- (end.x + max - radius + offsetx) * scalexy,
- (max - end.y - radius + offsety) * scalexy,
- radius * scalexy)
+// context.beginPath().moveTo((start.x + max + offsetx) * scalexy, (max - start.y + offsety) * scalexy)
+ context.beginPath().moveTo((0 + max + offsetx) * scalexy, (max - 0 + offsety) * scalexy)
+ context.arcTo((start.x + max + offsetx) * scalexy, (max - start.y + offsety) * scalexy,
+ (end.x + max + offsetx) * scalexy, (max - end.y + offsety) * scalexy, radius)
if ( fill )
{
context.fillStyle = (fill === 2 ? paintcolor : backcolor)
@@ -214,7 +218,6 @@ Rectangle
}
else
context.stroke()
-*/
}
function setalignment(context, align)
@@ -297,14 +300,15 @@ Rectangle
var currentcolor = 1
var active = manager.getActiveIndex()
- var index, count = manager.getItemCount()
+ var count = manager.getItemCount()
+ var operation, index, radius, fill, color
+ var point, position
for ( index = 0; index < count; index++ )
{
var operation = manager.getItemOperation(index)
- var point, position = manager.getItemPosition(index)
- var radius, fill = manager.getItemFill(index)
-
- var color = manager.getItemColor(index)
+ position = manager.getItemPosition(index)
+ fill = manager.getItemFill(index)
+ color = manager.getItemColor(index)
if ( color !== currentcolor )
{
setcolorindex(context, color)
@@ -336,13 +340,11 @@ Rectangle
}
else if ( operation === Operation.Arc )
{
-/*
point = manager.getItemPoint(index)
radius = manager.getItemValue(index)
- paintsemicircle(context, position, radius, fill)
+ paintsemicircle(context, position, point, radius, fill)
if ( !preview && fill && index === active )
- paintsemicircle(context, position, radius, false)
-*/
+ paintsemicircle(context, position, point, radius, false)
}
else if ( operation === Operation.Text )
{
diff --git a/symbol.cpp b/symbol.cpp
index 3133e3d..fd6b1d4 100644
--- a/symbol.cpp
+++ b/symbol.cpp
@@ -33,21 +33,31 @@ SymEditSymbol::Item::Item() : Operation(Operation::None), Fill(0), Align(9)
\param fill Item area fill.
*/
SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, int value, int color, int fill)
- : Operation(operation), Point(point), Value(value, value), Color(color), Fill(fill), Align(9)
+ : Operation(operation), Point(point), Value(value), Color(color), Fill(fill), Align(9)
{
}
-SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint value, int color, int fill)
- : Operation(operation), Point(point), Value(value), Color(color), Fill(fill), Align(0)
+SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QString value, int color, int align)
+ : Operation(operation), Point(point), Value(0), Text(value), Color(color), Fill(0), Align(align)
{
}
-SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QString value, int color, int align)
- : Operation(operation), Point(point), Text(value), Color(color), Fill(0), Align(align)
+//@}
+
+//! Constructor.
+/*!
+ \param operation Item operation.
+ \param point Item position.
+ \param end End position.
+ \param value Item value.
+ \param color Item color index.
+ \param fill Item area fill.
+*/
+SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill)
+ : Operation(operation), Point(point), End(end), Value(value), Color(color), Fill(fill), Align(0)
{
}
-//@}
//
// symbol functions
@@ -76,11 +86,11 @@ void SymEditSymbol::Load(const QString& buffer)
int x = string.mid(1, comma - 1).toInt();
int y = string.mid(comma + 1).toInt();
if ( type == 'D' )
- Items.push_back(Item(Operation::Line, position, QPoint(x, y), color, fill));
+ Items.push_back(Item(Operation::Line, position, QPoint(x, y), 0, color, fill));
else if ( type == 'B' )
- Items.push_back(Item(Operation::Rectangle, position, QPoint(x, y), color, fill));
- else if ( type == 'H' )
- Items.push_back(Item(Operation::Arc, position, QPoint(x, y), color, fill));
+ Items.push_back(Item(Operation::Rectangle, position, QPoint(x, y), 0, color, fill));
+// else if ( type == 'H' )
+// Items.push_back(Item(Operation::Arc, position, QPoint(x, y), color, fill));
position = QPoint(x, y);
}
else // single parameter
@@ -111,7 +121,7 @@ void SymEditSymbol::Load(const QString& buffer)
*/
QString& SymEditSymbol::Save(QString& buffer, bool rich) const
{
- auto appendvalue = [](QString& buffer, const QPoint& point, int count)
+ auto appendpoint = [](QString& buffer, const QPoint& point, int count)
{
QString value;
buffer.append(value.setNum(point.x()));
@@ -143,9 +153,9 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const
if ( item.Fill != fill )
fill = appendoption('F', buffer, item.Fill);
if ( item.Point != position )
- appendvalue(buffer.append('U'), item.Point, 2);
- appendvalue(buffer.append(item.Operation == Operation::Line ? 'D' : 'B'), item.Value, 2);
- position = item.Value;
+ appendpoint(buffer.append('U'), item.Point, 2);
+ appendpoint(buffer.append(item.Operation == Operation::Line ? 'D' : 'B'), item.End, 2);
+ position = item.End;
break;
}
case Operation::Circle:
@@ -155,8 +165,8 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const
if ( item.Fill != fill )
fill = appendoption('F', buffer, item.Fill);
if ( item.Point != position )
- appendvalue(buffer.append('U'), item.Point, 2);
- appendvalue(buffer.append('R'), item.Value, 1);
+ appendpoint(buffer.append('U'), item.Point, 2);
+ appendoption('R', buffer, item.Value);
position = item.Point;
break;
}
@@ -167,7 +177,7 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const
if ( item.Align != align )
align = appendoption('J', buffer, item.Align);
if ( item.Point != position )
- appendvalue(buffer.append('U'), item.Point, 2);
+ appendpoint(buffer.append('U'), item.Point, 2);
if ( item.Text.front() != '$' && item.Text.front() != '#' )
buffer.append('!'); // constant text
buffer.append(item.Text).append(';');
@@ -180,8 +190,8 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const
if ( item.Fill != fill )
fill = appendoption('F', buffer, item.Fill);
if ( item.Point != position )
- appendvalue(buffer.append('U'), item.Point, 2);
- appendvalue(buffer.append('H'), item.Value, 1);
+ appendpoint(buffer.append('U'), item.Point, 2);
+ appendoption('H', buffer, item.Value);
position = item.Point;
break;
}
@@ -203,7 +213,6 @@ void SymEditSymbol::Clear()
Items.clear();
}
-//@{
//! Add symbol item.
/*!
\param operation Item operation.
@@ -220,14 +229,24 @@ SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint po
Items.push_back(item);
return Items.back();
}
-SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint point, QPoint value, int color, int fill)
+
+//! Add symbol item.
+/*!
+ \param operation Item operation.
+ \param point Item position.
+ \param end End position.
+ \param value Item value.
+ \param color Item color index.
+ \param fill Item area fill.
+ \return Reference to item.
+*/
+SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill)
{
- Item item(operation, point, value, color, fill);
+ Item item(operation, point, end, value, color, fill);
ActiveIndex = static_cast<int>(Items.size());
Items.push_back(item);
return Items.back();
}
-//@}
//! Add symbol item.
/*!
@@ -309,20 +328,20 @@ int SymEditSymbol::SelectItem(QPoint point) const
{
case Operation::Line:
{
- distance(point, item.Point, item.Value);
+ distance(point, item.Point, item.End);
break;
}
case Operation::Rectangle:
{
- distance(point, item.Point, QPoint(item.Point.x(), item.Value.y()));
- distance(point, QPoint(item.Point.x(), item.Value.y()), item.Value);
- distance(point, item.Value, QPoint(item.Value.x(), item.Point.y()));
- distance(point, QPoint(item.Value.x(), item.Point.y()), item.Point);
+ distance(point, item.Point, QPoint(item.Point.x(), item.End.y()));
+ distance(point, QPoint(item.Point.x(), item.End.y()), item.End);
+ distance(point, item.End, QPoint(item.End.x(), item.Point.y()));
+ distance(point, QPoint(item.End.x(), item.Point.y()), item.Point);
break;
}
case Operation::Circle:
{
- check(fabs(length(difference(point, item.Point)) - item.Value.x()));
+ check(fabs(length(difference(point, item.Point)) - item.End.x()));
break;
}
case Operation::Text:
@@ -407,7 +426,7 @@ void SymEditSymbol::RotateSymbol(int dir)
{
rotate(item.Point, dir);
if ( item.Operation == Operation::Line || item.Operation == Operation::Rectangle )
- rotate(item.Value, dir);
+ rotate(item.End, dir);
}
}
diff --git a/symbol.h b/symbol.h
index bdde5e1..c745f65 100644
--- a/symbol.h
+++ b/symbol.h
@@ -33,12 +33,13 @@ public:
public:
Item();
Item(Operation::Type operation, QPoint point, int value, int color, int fill);
- Item(Operation::Type operation, QPoint point, QPoint value, int color, int fill);
+ Item(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill);
Item(Operation::Type operation, QPoint point, QString value, int color, int align);
Operation::Type Operation; //!< Item operation.
QPoint Point; //!< Item coordinates.
- QPoint Value; //!< Item value.
+ QPoint End; //!< End coordinates.
+ int Value; //!< Item value.
QString Text; //!< Text string.
int Color; //!< Color index.
int Fill; //!< Fill area.
@@ -50,7 +51,7 @@ public:
void Clear();
Item& AddItem(Operation::Type operation, QPoint point, int value, int color, int fill);
- Item& AddItem(Operation::Type operation, QPoint point, QPoint end, int color, int fill);
+ Item& AddItem(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill);
Item& AddItem(Operation::Type operation, QPoint point, QString text, int color, int align);
bool RemoveItem(int index);
diff --git a/symedit.cpp b/symedit.cpp
index 555a0da..b78ef07 100644
--- a/symedit.cpp
+++ b/symedit.cpp
@@ -190,37 +190,46 @@ QString SymEditManager::getSymbol(bool rich) const
return Symbol.Save(buffer, rich);
}
-//@{
-//! Add symbol item.
+//! Add point item.
/*!
\param operation Item operation.
- \param point Item position.
+ \param point Point position.
\param value Item value.
- \param color Item color index.
+ \param color Color index.
\param fill Item area fill.
\return True for success.
*/
-bool SymEditManager::addValueItem(int operation, QPoint point, int value, int color, int fill)
+bool SymEditManager::addPointItem(int operation, QPoint point, int value, int color, int fill)
{
undosave();
Symbol.AddItem(static_cast<Operation::Type>(operation), point, value, color, fill);
return true;
}
-bool SymEditManager::addPointItem(int operation, QPoint point, QPoint value, int color, int fill)
+
+//! Add symbol item.
+/*!
+ \param operation Item operation.
+ \param point Start position.
+ \param end End position.
+ \param value Item value.
+ \param color Color index.
+ \param fill Item area fill.
+ \return True for success.
+*/
+bool SymEditManager::addLineItem(int operation, QPoint point, QPoint end, int value, int color, int fill)
{
undosave();
- Symbol.AddItem(static_cast<Operation::Type>(operation), point, value, color, fill);
+ Symbol.AddItem(static_cast<Operation::Type>(operation), point, end, value, color, fill);
return true;
}
-//@}
-//! Add symbol item.
+//! Add Text item.
/*!
\param operation Item operation.
- \param point Item position.
- \param value Item text value.
- \param color Item color index.
- \param align Item text alignment.
+ \param point Text position.
+ \param value Text value.
+ \param color Color index.
+ \param align Text alignment.
\return True for success.
*/
bool SymEditManager::addTextItem(int operation, QPoint point, QString value, int color, int align)
@@ -285,7 +294,7 @@ QPoint SymEditManager::getItemPosition(int index) const
{
const auto& item = Symbol.GetItem(index);
if ( item.Operation == Operation::Rectangle ) // normalize to upper left
- return QPoint(std::min(item.Value.x(), item.Point.x()), std::max(item.Value.y(), item.Point.y()));
+ return QPoint(std::min(item.End.x(), item.Point.x()), std::max(item.End.y(), item.Point.y()));
return item.Point;
}
return QPoint(0, 0);
@@ -301,7 +310,7 @@ int SymEditManager::getItemValue(int index) const
if ( Symbol.GetItemCount() )
{
const auto& item = Symbol.GetItem(index);
- return item.Value.x();
+ return item.Value;
}
return 0;
}
@@ -317,8 +326,8 @@ QPoint SymEditManager::getItemPoint(int index) const
{
const auto& item = Symbol.GetItem(index);
if ( item.Operation == Operation::Rectangle ) // normalize to lower right
- return QPoint(std::max(item.Value.x(), item.Point.x()), std::min(item.Value.y(), item.Point.y()));
- return item.Value;
+ return QPoint(std::max(item.End.x(), item.Point.x()), std::min(item.End.y(), item.Point.y()));
+ return item.End;
}
return QPoint(0, 0);
}
diff --git a/symedit.h b/symedit.h
index f57fd8f..fa34532 100644
--- a/symedit.h
+++ b/symedit.h
@@ -56,8 +56,8 @@ public:
Q_INVOKABLE QString getSymbol(bool rich) const;
- Q_INVOKABLE bool addValueItem(int operation, QPoint point, int value, int color, int fill);
- Q_INVOKABLE bool addPointItem(int operation, QPoint point, QPoint value, int color, int fill);
+ Q_INVOKABLE bool addPointItem(int operation, QPoint point, int value, int color, int fill);
+ Q_INVOKABLE bool addLineItem(int operation, QPoint point, QPoint end, int value, int color, int fill);
Q_INVOKABLE bool addTextItem(int operation, QPoint point, QString value, int color, int align);
Q_INVOKABLE bool removeItem();