@@ -68,17 +68,13 @@ percentCorrectionDlg::percentCorrectionDlg( QWidget *parent) :
6868
6969}
7070
71-
72-
73- double g_laserLambda = 550 .; // a global so a none member function can access it.
74-
7571void percentCorrectionDlg::saveSettings (){
7672 QJsonObject myJsonObject;
77- myJsonObject[" ROC" ] = m_roc;
78- myJsonObject[" mirror radius" ] = m_radius;
79- myJsonObject[" exclusion radius" ] = ui->exclusionRadius ->value ();
73+
74+ myJsonObject[" exclusion radius" ] = m_exclusionRadius/m_radius;
8075 QJsonArray jzones;
81- for (const auto &item : zoneCenter) {
76+ for (const auto &item : m_zoneCenters) {
77+
8278 jzones.append ((double )item/m_radius); // zone centers are saved as a percentage.
8379 }
8480 myJsonObject[" zones" ] = jzones;
@@ -95,19 +91,38 @@ void percentCorrectionDlg::saveSettings(){
9591 * if last zones then use those.
9692 * allow loading and saveing of zones
9793 * allways save current accpeted zones in settings probalby in json format.
94+ * fixme not restoring last zones from registery if they exist. Probably want to do that in constructor not here
95+ * fixme figure that out.
9896*/
99- QList<double > percentCorrectionDlg::generateZoneCenters (double radius, int number_of_zones){
97+ QList<double > percentCorrectionDlg::generateZoneCenters (double radius, int number_of_zones, bool makeNew){
98+ QList<double > zoneCenters;
99+
100+ if (!makeNew) { // read last used zones
101+ QSettings set;
102+ QString jsonstr = set.value (" correctionZones" ," " ).toString ();
103+ if (jsonstr != " " ){
104+ QJsonDocument doc = loadZonesFromJson (jsonstr);
105+ QJsonObject jsonData=doc.object ();
106+
107+ QJsonArray zones = jsonData[" zones" ].toArray ();
108+ m_number_of_zones = zones.size ();
109+ ui->numberOfZones ->blockSignals (true );
110+ ui->numberOfZones ->setValue (m_number_of_zones);
111+ ui->numberOfZones ->blockSignals (false );
112+ return m_zoneCenters;
113+ }
114+
115+ }
116+
100117 double exc_pct = 100 . * pow (m_exclusionRadius,2 .)/pow (radius,2 .);
101118
102- QList<double > zoneCenters;
103119 zoneedge.clear ();
104120 zoneedge << m_exclusionRadius;
105121 // create the zones and the zone centers
106122 for (int i = 1 ; i <= number_of_zones; ++i){
107123 zoneedge << radius * sqrt ((1 . -.01 * exc_pct) * i/number_of_zones + .01 * exc_pct);
108124 }
109125
110-
111126 for (int i = 0 ; i < number_of_zones; ++i){
112127 double zoneCenter = (zoneedge[i] + zoneedge[i+1 ])/2 .;
113128 zoneCenters << QString::number (zoneCenter,' f' ,2 ).toDouble ();
@@ -122,18 +137,18 @@ void percentCorrectionDlg::updateZoneTable(){
122137 QStringList hLabels;
123138
124139 ui->percentTable ->clear ();
125- ui->percentTable ->setColumnCount (zoneCenter .size ());
140+ ui->percentTable ->setColumnCount (m_zoneCenters .size ());
126141 ui->percentTable ->setRowCount (2 );
127142 ui->percentTable ->blockSignals (true );
128143
129144
130- for (int i = 0 ; i < zoneCenter .size (); ++i) {
145+ for (int i = 0 ; i < m_zoneCenters .size (); ++i) {
131146
132147 QTableWidgetItem *item;
133148 if (ui->useInches ->isChecked ())
134- item = new QTableWidgetItem (QString (" %1 inches" ).arg (zoneCenter [i]/25.4 ,0 ,' f' ,2 ));
149+ item = new QTableWidgetItem (QString (" %1 inches" ).arg (m_zoneCenters [i]/25.4 ,0 ,' f' ,2 ));
135150 else
136- item = new QTableWidgetItem (QString (" %1 mm" ).arg (zoneCenter [i],0 ,' f' ,1 ));
151+ item = new QTableWidgetItem (QString (" %1 mm" ).arg (m_zoneCenters [i],0 ,' f' ,1 ));
137152 item->setTextAlignment (Qt::AlignCenter);
138153 ui->percentTable ->setItem (0 , i, item);
139154 item->setTextAlignment (Qt::AlignCenter);
@@ -144,7 +159,7 @@ void percentCorrectionDlg::updateZoneTable(){
144159
145160 ui->percentTable ->setHorizontalHeaderLabels (hLabels);
146161
147- ui->percentTable ->setColumnCount (zoneCenter .size ());
162+ ui->percentTable ->setColumnCount (m_zoneCenters .size ());
148163 ui->percentTable ->blockSignals (false );
149164}
150165QJsonDocument percentCorrectionDlg::loadZonesFromJson (QString str){
@@ -153,16 +168,30 @@ QJsonDocument percentCorrectionDlg::loadZonesFromJson(QString str){
153168 QJsonObject jsonData=jsonDoc.object ();
154169 QJsonArray zones = jsonData[" zones" ].toArray ();
155170
171+ if (jsonData.contains (" exclusion radius" )){
172+ m_exclusionRadius = jsonData[" exclusion radius" ].toDouble () * m_radius;
173+ ui->exclusionRadius ->blockSignals (true );
174+ ui->exclusionRadius ->setValue ((ui->useInches ->isChecked ())? m_exclusionRadius/25.4 :m_exclusionRadius);
175+ ui->exclusionRadius ->blockSignals (false );
176+ }
177+
178+ // else exclusion was not saved in an earlier version. Use the current value
156179
157- zoneCenter.clear ();
180+ m_zoneCenters.clear ();
181+ zoneedge.clear ();
182+ zoneedge << m_exclusionRadius;
158183 ui->percentTable ->clearContents ();
159184 ui->percentTable ->setColumnCount (zones.size ());
160185
186+ // we have to calculate the edge zones from the middle of adjacent zones
161187 for (int i = 0 ; i < zones.size (); ++i) {
162188 double d = zones[i].toDouble ()* m_radius;
163-
164- zoneCenter.append (QString::number (d,' f' ,0 ).toDouble () );
189+ m_zoneCenters.append (QString::number (d,' f' ,0 ).toDouble () );
190+ if (i < zones.size ()-1 )
191+ zoneedge << (d + zones[i+1 ].toDouble () * m_radius)/2 ;
165192 }
193+ zoneedge << m_radius;
194+
166195 return jsonDoc;
167196}
168197
@@ -186,15 +215,15 @@ arma::mat percentCorrectionDlg::makeZoneZerns(QList<double> centers){
186215 return theZs;
187216}
188217
189- void percentCorrectionDlg::makeZones (){
218+ void percentCorrectionDlg::makeZones (bool makeNew ){
190219
191220
192- zoneCenter = generateZoneCenters (m_radius, m_number_of_zones);
221+ m_zoneCenters = generateZoneCenters (m_radius, m_number_of_zones, makeNew );
193222
194223
195224 updateZoneTable ();
196225
197- zoneZerns = makeZoneZerns (zoneCenter );
226+ zoneZerns = makeZoneZerns (m_zoneCenters );
198227
199228}
200229
@@ -334,8 +363,8 @@ QPolygonF percentCorrectionDlg::makePercentages(surfaceData *surf){
334363 double idealoffset = 0 .;
335364 double zernOffset = 0 .;
336365
337- for (int zone = 0 ; zone < zoneCenter .length (); ++zone){
338- double x = zoneCenter [zone];
366+ for (int zone = 0 ; zone < m_zoneCenters .length (); ++zone){
367+ double x = m_zoneCenters [zone];
339368
340369 // idealSurface << QPointF(x, normIdealSlope);
341370 double idealknife = getIdealKE (m_roc, x);
@@ -364,7 +393,7 @@ QPolygonF percentCorrectionDlg::makePercentages(surfaceData *surf){
364393 return correction;
365394}
366395
367- // no longer used but left in case it should be .
396+ // no longer used but left in case we decide to plot the zernike based profile somewhere on the feature .
368397void percentCorrectionDlg::plotProfile (){
369398
370399 mirrorDlg *md = mirrorDlg::get_Instance ();
@@ -389,14 +418,10 @@ void percentCorrectionDlg::plotProfile(){
389418 }
390419 QPolygonF profile2;
391420 // now plot the m_avg surface
392- for (double r = 0 ; r < m_avg.length (); r += 1 . ){
393-
421+ for (double r = 0 .; r < m_avg.length (); r += 1 . ){
394422
395- double y = m_avg[r].y ();// getZernSurface(m_roc, m_radius, surfs[i]->zernvalues, fabs(r), true);
396423
397- // double sphery = m_roc - sqrt(pow(m_roc, 2.0) - pow(r, 2.0));
398- // y -= sphery;
399- // y /= m_lambda_nm * .5E-6;
424+ double y = m_avg[r].y ();
400425 profile2 << QPointF (m_avg[r].x (), y);
401426
402427 }
@@ -426,7 +451,7 @@ void percentCorrectionDlg::plot(){
426451 std::vector<double > zernikes;
427452
428453 // first get the zernike poly spherical terms at each zone center.
429- for (int c = 0 ; c < zoneCenter .length (); ++c){
454+ for (int c = 0 ; c < m_zoneCenters .length (); ++c){
430455
431456 }
432457
@@ -541,8 +566,8 @@ void percentCorrectionDlg::plot(){
541566
542567 if (surfs.length () == 1 ) {
543568 // draw markers
544- for (int i = 0 ; i < zoneCenter .size (); ++i) {
545- double center= zoneCenter [i] * mm;
569+ for (int i = 0 ; i < m_zoneCenters .size (); ++i) {
570+ double center= m_zoneCenters [i] * mm;
546571 QwtPlotMarker *marker = new QwtPlotMarker ();
547572 marker->setLineStyle (QwtPlotMarker::VLine); // Set the line style to vertical
548573 marker->setLinePen (Qt::red,2 ,Qt::DashLine);
@@ -608,7 +633,6 @@ bool compare(QVector< surfaceData *> data1, QVector< surfaceData *> data2){
608633
609634void percentCorrectionDlg::setData ( QVector< surfaceData *> data) {
610635
611- bool different = !compare (data,surfs);
612636
613637 mirrorDlg &md = *mirrorDlg::get_Instance ();
614638 m_roc = md.roc ;
@@ -629,7 +653,7 @@ void percentCorrectionDlg::setData( QVector< surfaceData *> data) {
629653 ui->percentTable ->setVerticalHeaderLabels (labels);
630654 ui->percentTable ->setSizeAdjustPolicy (QAbstractScrollArea::AdjustToContents);
631655
632- makeZones ();
656+ makeZones (false );
633657
634658 plot ();
635659 // if (different)
@@ -674,7 +698,7 @@ void percentCorrectionDlg::on_numberOfZones_valueChanged(int arg1)
674698 QSettings set;
675699 set.setValue (" percent number of zones" , arg1);
676700
677- makeZones ();
701+ makeZones (true );
678702 plot ();
679703
680704}
@@ -719,6 +743,7 @@ void percentCorrectionDlg::on_loadZones_clicked()
719743 ui->numberOfZones ->blockSignals (true );
720744 ui->numberOfZones ->setValue (m_number_of_zones);
721745 ui->numberOfZones ->blockSignals (false );
746+ updateZoneTable ();
722747 saveSettings ();
723748 plot ();
724749
@@ -736,6 +761,7 @@ void percentCorrectionDlg::on_saveZones_clicked()
736761 if (fileName.isEmpty ())
737762 return ;
738763 if (QFileInfo (fileName).suffix ().isEmpty ()) { fileName.append (" .zones" ); }
764+
739765 QString jsonString = set.value (" correctionZones" ).toString ();
740766 QFile file (fileName);
741767 if (!file.open (QIODevice::WriteOnly | QIODevice::Text)) {
@@ -772,7 +798,7 @@ void percentCorrectionDlg::on_maxOrder_valueChanged(int arg1)
772798void percentCorrectionDlg::on_percentTable_itemChanged (QTableWidgetItem *item)
773799{
774800
775- zoneCenter [item->column ()] = item->text ().toDouble ();
801+ m_zoneCenters [item->column ()] = item->text ().toDouble () *( (ui-> useInches -> isChecked ()) ? 25.4 : 1 . );
776802
777803 saveSettings ();
778804 plot ();
@@ -788,20 +814,20 @@ void percentCorrectionDlg::on_useInches_clicked(bool use)
788814 ui->exclusionRadius ->blockSignals (true );
789815 ui->exclusionRadius ->setValue (m_exclusionRadius/25.4 );
790816 ui->exclusionRadius ->blockSignals (false );
791- makeZones ();
817+ makeZones (false );
792818 plot ();
793819}
794820
795821
796- void percentCorrectionDlg::on_useMM_clicked (bool use )
822+ void percentCorrectionDlg::on_useMM_clicked (bool )
797823{
798824 QSettings set;
799825
800826 set.setValue (" correction useInches" , false );
801827 ui->exclusionRadius ->blockSignals (true );
802828 ui->exclusionRadius ->setValue (m_exclusionRadius);
803829 ui->exclusionRadius ->blockSignals (false );
804- makeZones ();
830+ makeZones (false );
805831 plot ();
806832}
807833
@@ -816,7 +842,8 @@ void percentCorrectionDlg::on_exclusionRadius_valueChanged(double arg1)
816842 else
817843 m_exclusionRadius = arg1;
818844 set.setValue (" correction exclusion" , arg1);
819- makeZones ();
845+ makeZones (true );
846+ saveSettings ();
820847 plot ();
821848}
822849
0 commit comments