Rewrite of OrthoViews. Detect page size and titleblock from tags in SVG template. Separation of logic from GUI. Much improved logic. No longer uses python to manipulate views - calls C++ methods directly. Can now support more views, and axonometric views in any position.

This commit is contained in:
j-dowsett 2014-01-10 11:33:34 +00:00
parent c1a2348e33
commit 83c9017eff
5 changed files with 1350 additions and 1142 deletions

File diff suppressed because it is too large Load Diff

View File

@ -28,53 +28,127 @@
#include "ui_TaskOrthoViews.h"
#include <Base/BoundBox.h>
#include <gp_Ax2.hxx>
#include <vector>
#include <Mod/Drawing/App/FeatureViewPart.h>
class Ui_TaskOrthoViews;
using namespace std;
namespace DrawingGui {
class orthoView
class orthoview
{
public:
orthoView(std::string, const char *, const char *, Base::BoundBox3d);
~orthoView();
orthoview(App::Document * parent, App::DocumentObject * part, App::DocumentObject * page, Base::BoundBox3d * partbox);
~orthoview();
void activate(bool);
void setDir(int);
void setDir(float,float,float,float,int);
void set_data(int r_x, int r_y);
void set_projection(gp_Ax2 cs);
void setPos(float = 0, float = 0);
void setScale(float);
void setOrientation(int);
void setScale(float newscale);
float getScale();
void deleteme();
void hidden(int);
void smooth(int);
public:
bool active;
float width;
float height;
void hidden(bool);
void smooth(bool);
private:
void calcCentre();
void updateView();
public: // these aren't used by orthoView, but just informational, hence public
bool ortho; // orthonometric? or axonometric
bool auto_scale; // scale for axonometric has not been manually changed?
int rel_x, rel_y; // relative position of this view
bool away, tri; // binary parameters for axonometric view
int axo; // 0 / 1 / 2 = iso / di / tri metric
gp_Dir up, right; // directions prior to rotations (ie, what was used to orientate the projection)
private:
std::string myname;
Base::BoundBox3d mybox;
int dir;
float angle;
float n[3];
int orientation;
float x, y;
float pageX, pageY;
float scale;
bool axo;
float vert[3];
App::Document * parent_doc;
Drawing::FeatureViewPart * this_view;
string myname;
float x, y; // 2D projection coords of bbox centre relative to origin
float cx, cy, cz; // coords of bbox centre in 3D space
float pageX, pageY; // required coords of centre of bbox projection on page
float scale; // scale of projection
gp_Dir X_dir, Y_dir, Z_dir; // directions of projection, X_dir makes x on page, Y_dir is y on page, Z_dir is out of page
};
class OrthoViews
{
public:
OrthoViews(const char * pagename, const char * partname);
~OrthoViews();
void set_primary(gp_Dir facing, gp_Dir right);
void add_view(int rel_x, int rel_y);
void del_view(int rel_x, int rel_y);
void del_all();
void set_projection(int proj);
void set_hidden(bool state);
void set_smooth(bool state);
void set_Axo(int rel_x, int rel_y, gp_Dir up, gp_Dir right, bool away = false, int axo = 0, bool tri = false);
void set_Axo(int rel_x, int rel_y);
void set_Axo_scale(int rel_x, int rel_y, float axo_scale);
void set_Ortho(int rel_x, int rel_y);
int is_Ortho(int rel_x, int rel_y);
bool get_Axo(int rel_x, int rel_y, int & axo, gp_Dir & up, gp_Dir & right, bool & away, bool & tri, float & axo_scale);
void auto_dims(bool setting);
void set_configs(float configs[5]);
void get_configs(float configs[5]);
private:
void set_orientation(int index);
void load_page(); // get page / titleblock dims from template
void choose_page(); // determine correct portion of page to use to avoid interference with title block
void set_all_orientations(); // update orientations of all views following change in primary view
void calc_layout_size(); // what's the real world size of chosen layout, excluding spaces
void calc_offsets();
void set_views();
void calc_scale();
void process_views();
int index(int rel_x, int rel_y);
private:
vector<orthoview *> views;
Base::BoundBox3d bbox;
App::Document * parent_doc;
App::DocumentObject * part;
App::DocumentObject * page;
string page_name, part_name;
int large[4]; // arrays containing page size info [margin_x, margin_y, size_x, size_y] = [x1, y1, x2-x1, y2-y1]
int small_h[4], small_v[4]; // page size avoiding title block, using maximum horizontal / vertical space
int * page_dims; // points to one of above arrays for which set of page dimensions to use
int block[4]; // title block info [corner x, corner y, width, height], eg [-1, 1, w, h] is in top left corner
bool title;
int * horiz, * vert; // points to min or max r_x / r_y depending upon which corner title block is in
int rotate_coeff; // 1st (= -1) or 3rd (= 1) angle
int min_r_x, max_r_x; // extreme relative positions of views
int min_r_y, max_r_y; // " " "
float width, height, depth; // of non-scaled primary view
float layout_width, layout_height; // of non-scaled layout without spaces
float gap_x, gap_y, min_space; // required spacing between views
float offset_x, offset_y; // coords of centre of upper left view
float scale;
int num_gaps_x, num_gaps_y; // how many gaps between views/edges? = num of views in given direction + 1
gp_Ax2 primary; // coord system of primary view
bool hidden, smooth;
bool autodims;
};
class TaskOrthoViews : public QWidget//: public Gui::TaskView::TaskBox
@ -85,70 +159,43 @@ public:
TaskOrthoViews(QWidget *parent = 0);
~TaskOrthoViews();
bool user_input();
void clean_up(bool);
void clean_up();
protected Q_SLOTS:
void setPrimary(int);
void setRotate(int);
void cb_toggled(bool);
void projectionChanged(int);
void hidden(int);
void smooth(int);
void toggle_auto(int);
void data_entered();
void axoChanged(int);
void axoTopChanged(int);
void axo_flip();
void axoScale();
void ShowContextMenu(const QPoint & pos);
void setPrimary(int dir);
void cb_toggled(bool toggle);
void projectionChanged(int index);
void hidden(int i);
void smooth(int i);
void toggle_auto(int i);
void data_entered(const QString & text);
void change_axo(int p = 3);
void axo_button();
void axo_scale(const QString & text);
void text_return();
protected:
void changeEvent(QEvent *);
void changeEvent(QEvent * e);
private:
void pagesize(std::string&);
void autodims();
void compute();
void validate_cbs();
void view_data(int, int, int &, int &);
void updateSecondaries();
void set_axo();
void setup_axo_tab();
void set_configs();
private:
class Private;
//class Private;
Ui_TaskOrthoViews * ui;
orthoView * views[4];
OrthoViews * orthos;
QCheckBox * c_boxes[5][5]; // matrix of pointers to gui checkboxes
QLineEdit * inputs[5]; // pointers to manual position/scale boxes
float * data[5]; //pointers to scale, x_pos, y_pos, horiz, vert
int map1[4][3][2]; //contains view directions and rotations for vertical secondary positions, for primaries 1,2,3,4
int map2[4][3][2]; //contains view directions and rotations for H and V secondary positions, primaries 5,6
float axonometric[3][6][4][4]; //contains view direction vectors and rotations for axonometric views
int view_status[4][4]; //matrix containing status of four orthoView objects (in use, axo, rel x, rel y)
int view_count; //number of active views
int primary; //view direction of primary view
float x_pos, y_pos; //x and y coords for primary view
int rotate; //rotate primary view clockwise by rotate*90
int proj; //first (=-1) or third (=1) angle projection
float scale; //scale of drawing
bool autoscale; //whether or not to run autodims
float horiz, vert; //centre-centre distances
bool axo_flipped;
int axo;
float pagewidth, pageheight; //these are actually the available width and height, calculated in constructor.
float pageh1, pageh2; //h1 - total usable page height, h2 - total height allowing for info box.
int margin;
int min_space; //minimum space between views, and page edge
float data[5]; // scale, x_pos, y_pos, horiz, vert
int axo_r_x, axo_r_y; // relative position of axo view currently being edited
bool txt_return; // flag to show if return was pressed while editing a text box;
};
//////////////////////////////////////////////////////////////
@ -162,20 +209,15 @@ public:
TaskDlgOrthoViews();
~TaskDlgOrthoViews();
public:
void open();
bool accept();
bool reject();
void clicked(int);
// QDialogButtonBox::StandardButtons getStandardButtons() const
// { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
private:
TaskOrthoViews * widget;
Gui::TaskView::TaskBox* taskbox;
};
} //namespace DrawingGui

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>259</width>
<height>496</height>
<width>250</width>
<height>486</height>
</rect>
</property>
<property name="sizePolicy">
@ -31,7 +31,7 @@
<item row="3" column="1">
<widget class="QCheckBox" name="cb12">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -39,6 +39,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -50,7 +56,7 @@
<item row="4" column="1">
<widget class="QCheckBox" name="cb13">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -58,6 +64,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -69,7 +81,7 @@
<item row="4" column="2">
<widget class="QCheckBox" name="cb23">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -77,6 +89,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -88,7 +106,7 @@
<item row="4" column="3">
<widget class="QCheckBox" name="cb33">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -96,6 +114,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -107,7 +131,7 @@
<item row="2" column="1">
<widget class="QCheckBox" name="cb11">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -115,6 +139,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -132,7 +162,7 @@
<item row="2" column="3">
<widget class="QCheckBox" name="cb31">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -140,6 +170,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -151,7 +187,7 @@
<item row="2" column="2">
<widget class="QCheckBox" name="cb21">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -159,6 +195,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -170,7 +212,7 @@
<item row="3" column="3">
<widget class="QCheckBox" name="cb32">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -178,6 +220,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -189,7 +237,7 @@
<item row="5" column="2">
<widget class="QCheckBox" name="cb24">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -197,6 +245,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -208,7 +262,7 @@
<item row="1" column="2">
<widget class="QCheckBox" name="cb20">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -216,6 +270,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -227,7 +287,7 @@
<item row="3" column="4">
<widget class="QCheckBox" name="cb42">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -235,6 +295,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -264,7 +330,7 @@
<string/>
</property>
<property name="checked">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@ -281,7 +347,7 @@
<item row="3" column="0">
<widget class="QCheckBox" name="cb02">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -289,6 +355,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>Right click for axonometric settings</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -393,7 +465,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>Primary x / y</string>
<string>Top left x / y</string>
</property>
<property name="margin">
<number>2</number>
@ -441,7 +513,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>Secondary dx / dy</string>
<string>Spacing dx / dy </string>
</property>
<property name="margin">
<number>2</number>
@ -507,8 +579,59 @@
<string>Axonometric</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<item row="1" column="0" rowspan="2">
<layout class="QGridLayout" name="gridLayout_6">
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string> Axis out and right</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string> Vertical tilt</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="axoUp">
<property name="enabled">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>X +ve</string>
</property>
</item>
<item>
<property name="text">
<string>Y +ve</string>
</property>
</item>
<item>
<property name="text">
<string>Z +ve</string>
</property>
</item>
<item>
<property name="text">
<string>X -ve</string>
</property>
</item>
<item>
<property name="text">
<string>Y -ve</string>
</property>
</item>
<item>
<property name="text">
<string>Z -ve</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="axoProj">
<property name="enabled">
@ -531,17 +654,7 @@
</item>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="flip">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Switch direction</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string> Scale</string>
@ -558,95 +671,77 @@
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string> Top face</string>
<string> Axis aligned up</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string> Left face</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="axoTop">
<property name="enabled">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>Front</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
<item>
<property name="text">
<string>Back</string>
</property>
</item>
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>Top</string>
</property>
</item>
<item>
<property name="text">
<string>Bottom</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="axoLeft">
<widget class="QComboBox" name="axoRight">
<property name="enabled">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>Right</string>
<string>Y +ve</string>
</property>
</item>
<item>
<property name="text">
<string>Left</string>
<string>Z +ve</string>
</property>
</item>
<item>
<property name="text">
<string>Top</string>
<string>Y -ve</string>
</property>
</item>
<item>
<property name="text">
<string>Bottom</string>
<string>Z -ve</string>
</property>
</item>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="axoScale">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="3" column="1">
<widget class="QPushButton" name="vert_flip">
<property name="text">
<string>Flip</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string> Trimetric</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="tri_flip">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Flip</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -693,12 +788,12 @@
<item row="0" column="0">
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Primary View</string>
<string>View from:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="primary">
<widget class="QComboBox" name="view_from">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
@ -707,37 +802,32 @@
</property>
<item>
<property name="text">
<string/>
<string>X +ve</string>
</property>
</item>
<item>
<property name="text">
<string>Front</string>
<string>Y +ve</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
<string>Z +ve</string>
</property>
</item>
<item>
<property name="text">
<string>Back</string>
<string>X -ve</string>
</property>
</item>
<item>
<property name="text">
<string>Left</string>
<string>Y -ve</string>
</property>
</item>
<item>
<property name="text">
<string>Top</string>
</property>
</item>
<item>
<property name="text">
<string>Bottom</string>
<string>Z -ve</string>
</property>
</item>
</widget>
@ -745,33 +835,33 @@
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>- Rotate</string>
<string>Axis aligned right:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="rotate">
<widget class="QComboBox" name="axis_right">
<item>
<property name="text">
<string notr="true">0</string>
<string notr="true">Y +ve</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">90</string>
<string notr="true">Z +ve</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">180</string>
<string notr="true">Y -ve</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">270</string>
<string notr="true">Z -ve</string>
</property>
</item>
</widget>

View File

@ -18,6 +18,8 @@
inkscape:version="0.48.1 r9760"
sodipodi:docname="A3_Landscape.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<!-- Working space 10 10 410 287 -->
<!-- Title block 220 227 410 287 -->
<metadata
id="metadata849">
<rdf:RDF>

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 126 KiB

View File

@ -17,6 +17,8 @@
inkscape:version="0.47 r22583"
sodipodi:docname="A4_Landscape.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<!-- Working space 10 10 287 200 -->
<!-- Title block 147 153 287 200 -->
<metadata
id="metadata849">
<rdf:RDF>

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB