3
3
4
4
#include " dmreader.h"
5
5
6
+ #include < QPainter>
7
+ #include < QtSvg/QSvgRenderer>
8
+ #include < QPoint>
9
+
6
10
MainWindow::MainWindow (QWidget *parent) :
7
11
QMainWindow(parent),
8
12
ui(new Ui::MainWindow)
@@ -37,6 +41,7 @@ MainWindow::MainWindow(QWidget *parent) :
37
41
38
42
statusBar ()->addWidget (statusLabel);
39
43
44
+ on_angleSpin_editingFinished (); // this is just to update the axes image...
40
45
41
46
// connect al the slots to update the strain images
42
47
connect (ui->colorBar , SIGNAL (limitsChanged (double )), ui->exxPlot , SLOT (SetColorLimits (double )));
@@ -111,6 +116,12 @@ void MainWindow::openDM(std::string filename)
111
116
int ny = dmFile.getY ();
112
117
int nz = dmFile.getZ ();
113
118
119
+ if (nx < 3 || ny < 3 )
120
+ {
121
+ QMessageBox::information (this , tr (" File open" ), tr (" Image too small." ), QMessageBox::Ok);
122
+ return ;
123
+ }
124
+
114
125
std::vector<double > image;
115
126
if ( nz > 1 )
116
127
image = dmFile.getImage (0 , nx*ny);
@@ -562,6 +573,7 @@ void MainWindow::doRefinement(double top, double left, double bottom, double rig
562
573
}
563
574
}
564
575
576
+ // probably poorly named since it does so much more
565
577
void MainWindow::getStrains ()
566
578
{
567
579
updateStatusBar (" GPA completed!" );
@@ -750,6 +762,9 @@ void MainWindow::ExportAll(int choice)
750
762
ui->exxPlot ->ExportSelector (fileDir, " Dilitation" , choice);
751
763
}
752
764
765
+ if (choice == 0 )
766
+ ui->colorBar ->ExportImage (fileDir, " ColourBar" );
767
+
753
768
// need to loop through and show images before exporting them from same plot
754
769
for (int i = 0 ; i < ui->leftCombo ->count (); ++i)
755
770
{
@@ -806,6 +821,9 @@ void MainWindow::ExportStrains(int choice)
806
821
{
807
822
ui->exxPlot ->ExportSelector (fileDir, " Dilitation" , choice);
808
823
}
824
+
825
+ if (choice == 0 )
826
+ ui->colorBar ->ExportImage (fileDir, " ColourBar" );
809
827
}
810
828
811
829
void MainWindow::DisconnectAll ()
@@ -830,6 +848,71 @@ void MainWindow::ClearImages()
830
848
831
849
void MainWindow::on_angleSpin_editingFinished ()
832
850
{
851
+ // OK....
852
+ // This first part is very messy. But bear with me.
853
+ // The axes is actually an SVG file kept int the resource file "axesresource.qrc"
854
+
855
+ // simple, get the angle!
856
+ double angle = ui->angleSpin ->value ();
857
+
858
+ if (lastAngle == angle)
859
+ return ;
860
+
861
+ lastAngle = angle;
862
+
863
+ // These are to account for the size of the text
864
+ // there might be a better way using rects and setting the alignment to centre
865
+ // but I can't be botthered to work it out
866
+ QPoint ysz (-3 , 4.5 );
867
+ QPoint xsz (-3 , 3 );
868
+ // This is the size of our area to draw in
869
+ QSize size (100 , 100 );
870
+ // This is the pixmap that will eventually be shown, we start with it transparent
871
+ QPixmap newmap (size);
872
+ newmap.fill (Qt::transparent);
873
+ // this is the midpoint of our image (so we can rotate around it)
874
+ QPoint mid (size.height ()/2 , size.width ()/2 );
875
+ // this is the position of our labels
876
+ QPoint xp (65 , 65 );
877
+ QPoint yp (35 , 35 );
878
+
879
+ // here we rotate these positions about the mid point
880
+ xp = xp - mid;
881
+ yp = yp - mid;
882
+ QTransform temp;
883
+ QTransform tform = temp.rotate (-angle);
884
+
885
+ xp = tform.map (xp);
886
+ yp = tform.map (yp);
887
+ xp = xp + mid;
888
+ yp = yp + mid;
889
+
890
+ // set the font and colours
891
+ QFont tFont (" Arial" , 12 , QFont::Normal);
892
+ QPen xPen (QColor (" #E30513" ));
893
+ QPen yPen (QColor (" #008D36" ));
894
+
895
+ // here we load the svg from the resource file
896
+ QSvgRenderer renderer (QString (" :/Images/axes.svg" ));
897
+ QPainter* p = new QPainter (&newmap);
898
+ // draw the texts (we have rotated the POSITION before)
899
+ p->setFont (tFont);
900
+ p->setPen (xPen);
901
+ p->drawText (xp + xsz, " x" );
902
+ p->setPen (yPen);
903
+ p->drawText (yp + ysz, " y" );
904
+ // now rotate the svg about hte mid point and draw it
905
+ p->translate (size.height ()/2 ,size.height ()/2 );
906
+ p->rotate (-angle);
907
+ p->translate (-size.height ()/2 ,-size.height ()/2 );
908
+ renderer.render (p);
909
+ // done, phew...
910
+ p->end ();
911
+
912
+ // finally set it
913
+ ui->lblAxes ->setPixmap (newmap);
914
+
915
+ // now do the calculation if we need to
833
916
if (!haveStrains)
834
917
return ;
835
918
@@ -838,6 +921,43 @@ void MainWindow::on_angleSpin_editingFinished()
838
921
839
922
void MainWindow::on_resultModeBox_currentIndexChanged (const QString &mode)
840
923
{
924
+ // set the labels on the image
925
+ if (mode == " Distortion" )
926
+ {
927
+ ui->exxLabel ->setText (" e<sub>xx</sub>" );
928
+ ui->exyLabel ->setText (" e<sub>xy</sub>" );
929
+ ui->eyxLabel ->setText (" e<sub>yx</sub>" );
930
+ ui->eyyLabel ->setText (" e<sub>yy</sub>" );
931
+ ui->exyLabel ->setVisible (true );
932
+ ui->eyxLabel ->setVisible (true );
933
+ ui->eyyLabel ->setVisible (true );
934
+ }
935
+ else if (mode == " Strain" )
936
+ {
937
+ ui->exxLabel ->setText (" ε<sub>xx</sub>" );
938
+ ui->exyLabel ->setText (" ε<sub>xy</sub>" );
939
+ ui->eyxLabel ->setText (" ε<sub>yx</sub>" );
940
+ ui->eyyLabel ->setText (" ε<sub>yy</sub>" );
941
+ ui->exyLabel ->setVisible (true );
942
+ ui->eyxLabel ->setVisible (true );
943
+ ui->eyyLabel ->setVisible (true );
944
+ }
945
+ else if (mode == " Rotation" )
946
+ {
947
+ ui->exxLabel ->setText (" ω<sub>xx</sub>" );
948
+ ui->eyyLabel ->setText (" ω<sub>yy</sub>" );
949
+ ui->exyLabel ->setVisible (false );
950
+ ui->eyxLabel ->setVisible (false );
951
+ ui->eyyLabel ->setVisible (true );
952
+ }
953
+ else if (mode == " Dilitation" )
954
+ {
955
+ ui->exxLabel ->setText (" Δ" );
956
+ ui->exyLabel ->setVisible (false );
957
+ ui->eyxLabel ->setVisible (false );
958
+ ui->eyyLabel ->setVisible (false );
959
+ }
960
+
841
961
if (!haveStrains)
842
962
return ;
843
963
0 commit comments