BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
layerelementcontroller.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/sldeditor/layerelementcontroller.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 
22 
24 #include <stdexcept>
25 #include <string>
26 
27 using namespace ModelView;
28 
29 namespace gui2 {
30 
31 //! Constructor
32 LayerElementController::LayerElementController(LayerElementItem* layer_view_item)
33  : QObject(), p_model_item(layer_view_item), m_sample_item_id(" ")
34 {
35 }
36 
37 //! Returns the pointer to the LayerElementItem in the model
39 {
40  return p_model_item;
41 }
42 
43 //! Allow the population of the own elements
45 {
51 }
52 
53 //! If loacally created the view elements nees to be locally destroyed
55 {
56  if (m_segment_views[0]) {
57  auto temp_ptr = m_segment_views[0];
59  delete temp_ptr;
60  }
61  if (m_segment_views[1]) {
62  auto temp_ptr = m_segment_views[1];
64  delete temp_ptr;
65  }
66  if (m_handle_views[0]) {
67  auto temp_ptr_0 = m_handle_views[0];
68  auto temp_ptr_1 = m_handle_views[1];
70  delete temp_ptr_0;
71  delete temp_ptr_1;
72  }
73  if (p_roughness_view) {
74  auto temp_ptr = p_roughness_view;
76  delete temp_ptr;
77  }
78  if (m_rough_handles_views[0]) {
79  auto temp_ptr_0 = m_rough_handles_views[0];
80  auto temp_ptr_1 = m_rough_handles_views[1];
82  delete temp_ptr_0;
83  delete temp_ptr_1;
84  }
85 }
86 
87 //! Connect to the set item
89 {
90  auto on_property_change = [this](ModelView::SessionItem* /*item*/, std::string property_name) {
91  if (property_name == LayerElementItem::P_X_POS) {
96  if (layerBelow())
99  layerElementItem()->property<double>(LayerElementItem::P_X_POS)
100  + layerElementItem()->property<double>(LayerElementItem::P_WIDTH));
101  }
102  if (property_name == LayerElementItem::P_HEIGHT) {
104  layerElementItem()->property<double>(LayerElementItem::P_HEIGHT));
108  updateRoughness();
109  if (layerBelow()) {
113  }
114  }
115  if (property_name == LayerElementItem::P_WIDTH) {
117  layerElementItem()->property<double>(LayerElementItem::P_WIDTH));
121  updateRoughness();
122  if (layerBelow())
125  layerElementItem()->property<double>(LayerElementItem::P_X_POS)
126  + layerElementItem()->property<double>(LayerElementItem::P_WIDTH));
127  }
128  if (property_name == LayerElementItem::P_ROUGHNESS) {
129  emit roughnessChanged(m_sample_item_id, layerElementItem()->property<double>(
131  updateRoughness();
132  }
133 
134  // Side segment update
135  if (property_name == LayerElementItem::P_SIDE_THICKNESS) {
137  }
138  if (property_name == LayerElementItem::P_SIDE_PEN_WIDTH) {
140  }
141  if (property_name == LayerElementItem::P_SIDE_PEN_COLOR) {
143  }
144  if (property_name == LayerElementItem::P_SIDE_BRUSH_COLOR) {
146  }
147 
148  // Top segment update
149  if (property_name == LayerElementItem::P_TOP_THICKNESS) {
151  }
152  if (property_name == LayerElementItem::P_TOP_PEN_WIDTH) {
154  }
155  if (property_name == LayerElementItem::P_TOP_PEN_COLOR) {
157  }
158  if (property_name == LayerElementItem::P_TOP_BRUSH_COLOR) {
160  }
161 
162  // Segment handle update
163  if (property_name == LayerElementItem::P_HANDLE_RADIUS) {
165  }
166  if (property_name == LayerElementItem::P_HANDLE_BRUSH_COLOR) {
168  }
169  if (property_name == LayerElementItem::P_HANDLE_PEN_WIDTH) {
171  }
172  if (property_name == LayerElementItem::P_HANDLE_PEN_COLOR) {
174  }
175 
176  // Roughness handles update
177  if (property_name == LayerElementItem::P_R_HANDLE_RADIUS) {
178  updateRoughness();
179  }
180  if (property_name == LayerElementItem::P_R_HANDLE_BRUSH_COLOR) {
181  updateRoughness();
182  }
183  if (property_name == LayerElementItem::P_R_HANDLE_PEN_WIDTH) {
184  updateRoughness();
185  }
186  if (property_name == LayerElementItem::P_R_HANDLE_PEN_COLOR) {
187  updateRoughness();
188  }
189 
190  // Roughness update
191  if (property_name == LayerElementItem::P_ROUGHNESS_BRUSH_COLOR) {
192  updateRoughness();
193  }
194  if (property_name == LayerElementItem::P_ROUGHNESS_PEN_WIDTH) {
195  updateRoughness();
196  }
197  if (property_name == LayerElementItem::P_ROUGHNESS_PEN_COLOR) {
198  updateRoughness();
199  }
200  };
201 
202  layerElementItem()->mapper()->setOnPropertyChange(on_property_change, this);
203 }
204 
205 //! Disconnect from the set item
207 {
208  layerElementItem()->mapper()->unsubscribe(this);
209 }
210 
211 //! Set the scene
213 {
214  if (!scene)
215  return;
216 
217  p_scene = scene;
218 
223 }
224 
225 //! Return the current set scene
227 {
228  return p_scene;
229 }
230 
231 //! Set the scene
233 {
234  if (!scene())
235  return;
236 
241  p_scene = nullptr;
242 }
243 
244 //! Set the idenfier of the sample item to report
245 void LayerElementController::setSampleItemId(std::string identifier)
246 {
247  m_sample_item_id = identifier;
248 }
249 
250 //! Return the set sample item identifier
252 {
253  return m_sample_item_id;
254 }
255 
256 //! Unset the sample item identifier
258 {
259  m_sample_item_id = " ";
260 }
261 
262 //! Get the scene adapter to convert to axes
264 {
265  if (!p_scene)
266  return nullptr;
267 
268  return p_scene->sceneAdapter();
269 }
270 
271 //! Set the layer above the current one in relation
273 {
274  p_controller_above = layer_view_controller;
275 
276  if (layer_view_controller->layerBelow() != this)
277  layer_view_controller->setLayerBelow(this);
278 
279  double pos =
283 }
284 
285 //! Set the layer below the current one in relation
287 {
288  p_controller_below = layer_view_controller;
289 
290  if (layer_view_controller->layerAbove() != this)
291  layer_view_controller->setLayerAbove(this);
292 }
293 
294 //! Return the layer above the current one in relation
296 {
297  return p_controller_above;
298 }
299 
300 //! Return the layer below the current one in relation
302 {
303  return p_controller_below;
304 }
305 
306 //! Unset the layer above the current one in relation
308 {
309  if (!p_controller_above)
310  return;
311 
312  if (silent)
314 
315  p_controller_above = nullptr;
316 }
317 
318 //! Unset the layer below the current one in relation
320 {
321  if (!p_controller_below)
322  return;
323 
324  if (silent)
326 
327  p_controller_below = nullptr;
328 }
329 
330 //! Set the side segment elements
332 {
333  m_segment_views[0] = segment_view;
334  m_segment_views[0]->adaptW(false);
335  m_segment_views[0]->setLayerElementController(this);
337 
338  if (scene())
339  scene()->addItem(m_segment_views[0]);
340 }
341 
342 //! Set the top segment elements
344 {
345  m_segment_views[1] = segment_view;
346  m_segment_views[1]->adaptH(false);
347  m_segment_views[1]->setLayerElementController(this);
349 
350  if (scene())
351  scene()->addItem(m_segment_views[1]);
352 }
353 
354 //! Return the side Segment view
356 {
357  return m_segment_views[0];
358 }
359 
360 //! Return the top Segment view
362 {
363  return m_segment_views[1];
364 }
365 
366 //! Unset the side segment elements
368 {
369  if (m_segment_views[0] && scene() && m_segment_views[0]->scene() == scene())
370  scene()->removeItem(m_segment_views[0]);
371 
372  m_segment_views[0] = nullptr;
373 }
374 
375 //! Unset the top segment elements
377 {
378  if (m_segment_views[1] && scene() && m_segment_views[1]->scene() == scene())
379  scene()->removeItem(m_segment_views[1]);
380 
381  m_segment_views[1] = nullptr;
382 }
383 
384 //! The move logic for the segments
386 {
387  if (segment_view == sideSegment()) {
389  } else if (segment_view == topSegment()) {
390  topSegmentMoved();
391  }
392 }
393 
394 //! Update the view of the side segment
396 {
397  if (!m_segment_views[0])
398  return;
399 
400  auto pen = QPen();
401  pen.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_SIDE_PEN_COLOR));
402  pen.setWidthF(layerElementItem()->property<double>(LayerElementItem::P_SIDE_PEN_WIDTH));
403  m_segment_views.at(0)->setPen(pen);
404 
405  auto brush = QBrush(Qt::SolidPattern);
406  brush.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_SIDE_BRUSH_COLOR));
407  m_segment_views.at(0)->setBrush(brush);
408 
409  m_segment_views.at(0)->setRectangle(sideSegmentRect());
410 }
411 
412 //! Update the view of the top segment
414 {
415  if (!m_segment_views[1])
416  return;
417 
418  auto pen = QPen();
419  pen.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_TOP_PEN_COLOR));
420  pen.setWidthF(layerElementItem()->property<double>(LayerElementItem::P_TOP_PEN_WIDTH));
421  m_segment_views.at(1)->setPen(pen);
422 
423  auto brush = QBrush(Qt::SolidPattern);
424  brush.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_TOP_BRUSH_COLOR));
425  m_segment_views.at(1)->setBrush(brush);
426 
427  m_segment_views.at(1)->setRectangle(topSegmentRect());
428 }
429 
430 //! Return the side segment rectangle
432 {
433  double this_pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
434  double this_height = layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
435  double this_thickness =
437 
438  double above_height = 0;
439  if (layerAbove()) {
440  above_height =
442  }
443 
444  if (above_height > this_height) {
445  return QRectF(this_pos - this_thickness / 2., this_height, this_thickness,
446  above_height - this_height);
447  } else {
448  return QRectF(this_pos - this_thickness / 2., above_height, this_thickness,
449  this_height - above_height);
450  }
451 }
452 
453 //! Return the top segment rectangle
455 {
456  double pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
457  double height = layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
458  double width = layerElementItem()->property<double>(LayerElementItem::P_WIDTH);
459  double thickness = layerElementItem()->property<double>(LayerElementItem::P_TOP_THICKNESS);
460  return QRectF(pos, height - thickness / 2., width, thickness);
461 }
462 
463 //! Put segments on scene
465 {
466  if (!scene())
467  return;
468  for (auto segment_view : m_segment_views) {
469  if (segment_view)
470  scene()->addItem(segment_view);
471  }
472 }
473 
474 //! Remove the segments from the scene
476 {
477  if (!scene())
478  return;
479  for (auto segment_view : m_segment_views) {
480  if (segment_view && segment_view->scene() == scene())
481  scene()->removeItem(segment_view);
482  }
483 }
484 
485 //! Handle the position variation of the side segment
487 {
488  double x = sideSegment()->getLastPos().x();
489  if (layerAbove()) {
490  double w = 0;
491  auto item = layerAbove()->layerElementItem();
492  if (x < item->property<double>(LayerElementItem::P_X_POS)) {
493  x = item->property<double>(LayerElementItem::P_X_POS) + w;
494  } else {
495  w = x - item->property<double>(LayerElementItem::P_X_POS);
496  }
497  item->setProperty(LayerElementItem::P_WIDTH, w);
498  }
500 }
501 
502 //! Handle the position variation of the top segment
504 {
505  double y = topSegment()->getLastPos().y();
506  if (y < 0)
507  y = 0;
509 }
510 
511 //! Set the side segment elements
513  HandleElementView* second_handle)
514 {
515  m_handle_views[0] = first_handle;
516  m_handle_views[1] = second_handle;
517  m_handle_views[0]->setLayerElementController(this);
518  m_handle_views[1]->setLayerElementController(this);
520 
521  if (scene()) {
522  scene()->addItem(m_handle_views[0]);
523  scene()->addItem(m_handle_views[1]);
524  }
525 }
526 
527 //! Return the side Segment view
529 {
530  return m_handle_views[0];
531 }
532 
533 //! Return the top Segment view
535 {
536  return m_handle_views[1];
537 }
538 
539 //! Unset the side segment elements
541 {
542  if (m_handle_views[0] && scene() && m_handle_views[0]->scene() == scene())
543  scene()->removeItem(m_handle_views[0]);
544  if (m_handle_views[1] && scene() && m_handle_views[1]->scene() == scene())
545  scene()->removeItem(m_handle_views[1]);
546 
547  m_handle_views[0] = nullptr;
548  m_handle_views[1] = nullptr;
549 }
550 
551 //! The move logic for the handles associated to the segments
553 {
554  if (handle_view == leftRoughnessHandle()) {
555  leftHandleMoved();
556  } else if (handle_view == rightRoughnessHandle()) {
558  }
559 }
560 
561 //! Update the handles of the segment
563 {
564  auto pen = QPen();
565  pen.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_HANDLE_PEN_COLOR));
566  pen.setWidthF(layerElementItem()->property<double>(LayerElementItem::P_HANDLE_PEN_WIDTH));
567 
568  auto brush = QBrush(Qt::SolidPattern);
569  brush.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_HANDLE_BRUSH_COLOR));
570 
571  if (m_handle_views[0]) {
572  m_handle_views.at(0)->setPen(pen);
573  m_handle_views.at(0)->setBrush(brush);
574  m_handle_views.at(0)->setRectangle(firstSegmentHandleRect());
575  }
576  if (m_handle_views[1]) {
577  m_handle_views.at(1)->setPen(pen);
578  m_handle_views.at(1)->setBrush(brush);
579  m_handle_views.at(1)->setRectangle(secondSegmentHandleRect());
580  }
581 }
582 
583 //! Get the first segment handle rectangle
585 {
586  double pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
587  double radius = layerElementItem()->property<double>(LayerElementItem::P_HANDLE_RADIUS);
588 
589  double above_height = 0;
590  if (layerAbove()) {
591  above_height =
593  }
594 
595  return QRectF(pos - radius, above_height - radius, 2 * radius, 2 * radius);
596 }
597 
598 //! Get the second segment handle rectangle
600 {
601  double pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
602  double height = layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
603  double radius = layerElementItem()->property<double>(LayerElementItem::P_HANDLE_RADIUS);
604  return QRectF(pos - radius, height - radius, 2 * radius, 2 * radius);
605 }
606 
607 //! Put the segment handles on the secene
609 {
610  if (!scene())
611  return;
612  for (auto handle_view : m_handle_views) {
613  if (handle_view)
614  scene()->addItem(handle_view);
615  }
616 }
617 
618 //! Remove the segment handles on the scene
620 {
621  if (!scene())
622  return;
623  for (auto handle_view : m_handle_views) {
624  if (handle_view && handle_view->scene() == scene())
625  scene()->removeItem(handle_view);
626  }
627 }
628 
629 //! Set the roughness element view
631 {
632  p_roughness_view = roughness_view;
633  updateRoughness();
634 
635  if (scene()) {
636  scene()->addItem(p_roughness_view);
637  }
638 }
639 
640 //! Set the roughness handle element views
642  HandleElementView* second_handle_view)
643 {
644  m_rough_handles_views[0] = first_handle_view;
645  m_rough_handles_views[1] = second_handle_view;
646  m_rough_handles_views[0]->setFlag(QGraphicsItem::ItemIsMovable);
647  m_rough_handles_views[1]->setFlag(QGraphicsItem::ItemIsMovable);
648  m_rough_handles_views[0]->setLayerElementController(this);
649  m_rough_handles_views[1]->setLayerElementController(this);
650  updateRoughness();
651 
652  if (scene()) {
653  scene()->addItem(m_rough_handles_views[0]);
654  scene()->addItem(m_rough_handles_views[1]);
655  }
656 }
657 
658 //! Return the roughness element view
660 {
661  return p_roughness_view;
662 }
663 
664 //! Return the left roughness handle element view
666 {
667  return m_rough_handles_views[0];
668 }
669 
670 //! Return the right roughness handle element view
672 {
673  return m_rough_handles_views[1];
674 }
675 
676 //! Remove the roughness view element pointer
678 {
679  if (p_roughness_view && scene() && p_roughness_view->scene() == scene())
680  scene()->removeItem(p_roughness_view);
681  p_roughness_view = nullptr;
682 }
683 
684 //! Remove the handle pointers
686 {
687  if (m_rough_handles_views[0] && scene() && m_rough_handles_views[0]->scene() == scene())
688  scene()->removeItem(m_rough_handles_views[0]);
689  if (m_rough_handles_views[1] && scene() && m_rough_handles_views[1]->scene() == scene())
690  scene()->removeItem(m_rough_handles_views[1]);
691 
692  m_rough_handles_views[0] = nullptr;
693  m_rough_handles_views[1] = nullptr;
694 }
695 
696 //! Update the whole roughness drawing
698 {
699  // Test the roughness
701  // double width = layerElementItem()->property<double>(LayerElementItem::P_WIDTH);
703 
704  // Perform the painting
705  auto pen = QPen();
706  auto brush = QBrush();
707 
708  // Take care of the rounghnessview
709  pen.setStyle(Qt::PenStyle::DashLine);
710  pen.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_ROUGHNESS_PEN_COLOR));
711  pen.setWidthF(layerElementItem()->property<double>(LayerElementItem::P_ROUGHNESS_PEN_WIDTH));
712  brush.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_ROUGHNESS_BRUSH_COLOR));
713  if (p_roughness_view) {
714  p_roughness_view->setPen(pen);
715  p_roughness_view->setBrush(brush);
718  }
719 
720  // Take care of the handles
721  pen.setStyle(Qt::PenStyle::SolidLine);
722  pen.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_R_HANDLE_PEN_COLOR));
723  pen.setWidthF(layerElementItem()->property<double>(LayerElementItem::P_R_HANDLE_PEN_WIDTH));
724  brush.setColor(layerElementItem()->property<QColor>(LayerElementItem::P_R_HANDLE_BRUSH_COLOR));
725  brush.setStyle(Qt::SolidPattern);
726 
727  if (m_rough_handles_views[0]) {
728  m_rough_handles_views.at(0)->setPen(pen);
729  m_rough_handles_views.at(0)->setBrush(brush);
730  m_rough_handles_views.at(0)->setRectangle(leftRoughnessHandleRect());
731  }
732  if (m_rough_handles_views[1]) {
733  m_rough_handles_views.at(1)->setPen(pen);
734  m_rough_handles_views.at(1)->setBrush(brush);
735  m_rough_handles_views.at(1)->setRectangle(rightRoughnessHandleRect());
736  }
737 }
738 
739 //! get the left painter path for the roughness view
741 {
742  double pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
743  double height = layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
745 
746  auto path = QPainterPath();
747 
748  auto layer_above = layerAbove();
749  if (!layer_above) {
750  path.moveTo(pos, 0);
751  path.lineTo(pos - roughness, 0);
752  } else {
753  path.moveTo(pos - roughness,
754  layer_above->layerElementItem()->property<double>(LayerElementItem::P_HEIGHT));
755  }
756  path.lineTo(pos - roughness, height);
757  path.lineTo(pos, height);
758 
759  return path;
760 }
761 
762 //! get the right painter path for the roughness view
764 {
765  double pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
766  double height = layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
768 
769  auto path = QPainterPath();
770 
771  auto layer_above = layerAbove();
772  if (!layer_above) {
773  path.moveTo(pos, 0);
774  path.lineTo(pos + roughness, 0);
775  } else {
776  path.moveTo(pos,
777  layer_above->layerElementItem()->property<double>(LayerElementItem::P_HEIGHT));
778  path.lineTo(pos + roughness,
779  layer_above->layerElementItem()->property<double>(LayerElementItem::P_HEIGHT));
780  }
781  path.lineTo(pos + roughness, height);
782 
783  return path;
784 }
785 
786 //! get the rectangle for the left roughness handles
788 {
789  double pos_x = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
790  double height = layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
793 
794  auto layer_above = layerAbove();
795  double lower_height = 0;
796  if (layer_above) {
797  lower_height =
798  layer_above->layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
799  }
800  double pos_y = (lower_height - height) / 2 + height;
801 
802  return QRectF(pos_x - roughness - radius, pos_y - radius, 2 * radius, 2 * radius);
803 }
804 
805 //! get the rectangle for the right roughness handles
807 {
808  double pos_x = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
809  double height = layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
812 
813  auto layer_above = layerAbove();
814  double lower_height = 0;
815  if (layer_above) {
816  lower_height =
817  layer_above->layerElementItem()->property<double>(LayerElementItem::P_HEIGHT);
818  }
819  double pos_y = (lower_height - height) / 2 + height;
820 
821  return QRectF(pos_x + roughness - radius, pos_y - radius, 2 * radius, 2 * radius);
822 }
823 
824 //! Put the roughnes view on the scene
826 {
827  if (!scene())
828  return;
829  if (p_roughness_view)
830  scene()->addItem(p_roughness_view);
831 }
832 
833 //! Put the roughness handles on the scene
835 {
836  if (!scene())
837  return;
838  for (auto handle_roughness_view : m_rough_handles_views) {
839  if (handle_roughness_view)
840  scene()->addItem(handle_roughness_view);
841  }
842 }
843 
844 //! Remove the roughness view item from the scene
846 {
847  if (!scene())
848  return;
849  if (p_roughness_view && p_roughness_view->scene() == scene())
850  scene()->removeItem(p_roughness_view);
851 }
852 
853 //! Remove the roughness handles from the sene
855 {
856  if (!scene())
857  return;
858  for (auto handle_roughness_view : m_rough_handles_views) {
859  if (handle_roughness_view && handle_roughness_view->scene() == scene())
860  scene()->removeItem(handle_roughness_view);
861  }
862 }
863 
864 //! Handle the position variation of the left handle
866 {
867  double pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
868  double roughness = pos - leftRoughnessHandle()->getLastPos().x();
870 }
871 
872 //! Handle the position variation of the right handle
874 {
875  double pos = layerElementItem()->property<double>(LayerElementItem::P_X_POS);
876  double roughness = rightRoughnessHandle()->getLastPos().x() - pos;
878 }
879 
880 //! Handle the position variation of the right handle
881 void LayerElementController::setRoughnessInLimits(double roughness, bool active) const
882 {
883  if (roughness < 0) {
885  return;
886  }
887 
888  double width = layerElementItem()->property<double>(LayerElementItem::P_WIDTH);
889  if (width == 0)
890  width = 1e6;
891 
892  auto layer_above = layerAbove();
893  if (layer_above) {
894  double second_width =
895  layer_above->layerElementItem()->property<double>(LayerElementItem::P_WIDTH);
896  if (second_width == 0)
897  second_width = 1e6;
898 
899  if (second_width < width)
900  width = second_width;
901  }
902 
903  if (roughness > width / 2.) {
905  return;
906  }
907 
908  if (active)
910 }
911 
912 } // namespace gui2
void unsubscribe(Callbacks::slot_t client) override
Removes given client from all subscriptions.
Definition: itemmapper.cpp:214
void setOnPropertyChange(Callbacks::item_str_t f, Callbacks::slot_t owner) override
Sets callback to be notified on item's property change.
Definition: itemmapper.cpp:189
Interface to convert coordinates of "scene" to coordinates of "widget".
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
ItemMapper * mapper()
Returns item mapper. Allows subscribing to various events happening to the item.
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190
Custom graphics scene to show QCustomPlot with additional elements on top.
Definition: graphicsscene.h:34
ModelView::SceneAdapterInterface * sceneAdapter() const
Return the pointer of the scene adapter on request.
The handle QGraphicsViewItem on GraphicsScene.
QPointF getLastPos() const
Get the last position of the item.
Manages the whole appearance of a layer on the graphicsscene.
void updateTopSegment() const
Update the view of the top segment.
HandleElementView * firstSegmentHandle() const
Return the side Segment view.
void unsetSegmentHandles()
Unset the side segment elements.
void removeRoughnessFromScene() const
Remove the roughness view item from the scene.
QRectF leftRoughnessHandleRect() const
get the rectangle for the left roughness handles
QRectF sideSegmentRect() const
Return the side segment rectangle.
void putRoughnessOnScene() const
Put the roughnes view on the scene.
LayerElementController * layerBelow() const
Return the layer below the current one in relation.
void unsetRoughness()
Remove the roughness view element pointer.
void unsetLayerAbove(bool silent=true)
Unset the layer above the current one in relation.
std::vector< SegmentElementView * > m_segment_views
void putSegmentHandlesOnScene() const
Put the segment handles on the secene.
QRectF topSegmentRect() const
Return the top segment rectangle.
LayerElementItem * layerElementItem() const
Returns the pointer to the LayerElementItem in the model.
void setLayerBelow(LayerElementController *layer_view_controller)
Set the layer below the current one in relation.
GraphicsScene * scene() const
Return the current set scene.
std::vector< HandleElementView * > m_handle_views
RoughnessElementView * roughness() const
Return the roughness element view.
void putSegementsOnScene() const
Put segments on scene.
void removeRoughnessHandlesFromScene() const
Remove the roughness handles from the sene.
void setSampleItemId(std::string indentifier)
Set the idenfier of the sample item to report.
LayerElementController * p_controller_below
QPainterPath rightRoughnessPath() const
get the right painter path for the roughness view
void setRoughnessInLimits(double roughness, bool active=true) const
Handle the position variation of the right handle.
void rightHandleMoved() const
Handle the position variation of the right handle.
QPainterPath leftRoughnessPath() const
get the left painter path for the roughness view
SegmentElementView * topSegment() const
Return the top Segment view.
void topSegmentMoved() const
Handle the position variation of the top segment.
void setScene(GraphicsScene *scene)
Set the scene.
void setRoughness(RoughnessElementView *roughness_view)
Set the roughness element view.
void widthChanged(std::string id, double value) const
RoughnessElementView * p_roughness_view
HandleElementView * rightRoughnessHandle() const
Return the right roughness handle element view.
ModelView::SceneAdapterInterface * sceneAdapter() const
Get the scene adapter to convert to axes.
void updateSegmentHandles() const
Update the handles of the segment.
void setTopSegment(SegmentElementView *segment_view)
Set the top segment elements.
void unsetRoughnessHandles()
Remove the handle pointers.
void setSideSegment(SegmentElementView *segment_view)
Set the side segment elements.
SegmentElementView * sideSegment() const
Return the side Segment view.
void disconnectFormModel() const
Disconnect from the set item.
void setLayerAbove(LayerElementController *layer_view_controller)
Set the layer above the current one in relation.
void setSegmentHandles(HandleElementView *first_handle, HandleElementView *secondHandle)
Set the side segment elements.
void unsetSampleItemId()
Unset the sample item identifier.
void unsetTopSegment()
Unset the top segment elements.
void leftHandleMoved() const
Handle the position variation of the left handle.
void unsetSideSegment()
Unset the side segment elements.
std::string sampleItemId() const
Return the set sample item identifier.
QRectF firstSegmentHandleRect() const
Get the first segment handle rectangle.
HandleElementView * secondSegmentHandle() const
Return the top Segment view.
void sideSegmentMoved() const
Handle the position variation of the side segment.
void connectToModel() const
Connect to the set item.
void roughnessChanged(std::string id, double value) const
std::vector< HandleElementView * > m_rough_handles_views
void updateSideSegment() const
Update the view of the side segment.
void removeSegmentHandlesFromScene() const
Remove the segment handles on the scene.
LayerElementController * p_controller_above
void heightChanged(std::string id, double value) const
QRectF rightRoughnessHandleRect() const
get the rectangle for the right roughness handles
QRectF secondSegmentHandleRect() const
Get the second segment handle rectangle.
void deleteViewItems()
If loacally created the view elements nees to be locally destroyed.
void handleViewMoved(HandleElementView *handle_view)
The move logic for the handles associated to the segments.
void segmentViewMoved(SegmentElementView *segment_view)
The move logic for the segments.
void updateRoughness() const
Update the whole roughness drawing.
void autoPopulate()
Allow the population of the own elements.
LayerElementController * layerAbove() const
Return the layer above the current one in relation.
void putRoughnessHandlesOnScene() const
Put the roughness handles on the scene.
void setRoughnessHandles(HandleElementView *first_handle_view, HandleElementView *second_handle_view)
Set the roughness handle element views.
void unsetLayerBelow(bool silent=true)
Unset the layer below the current one in relation.
void removeSegmentsFromScene() const
Remove the segments from the scene.
HandleElementView * leftRoughnessHandle() const
Return the left roughness handle element view.
The mvvm session item associated to a layer.
static const std::string P_SIDE_THICKNESS
static const std::string P_TOP_PEN_WIDTH
static const std::string P_R_HANDLE_RADIUS
static const std::string P_SIDE_BRUSH_COLOR
static const std::string P_ROUGHNESS_PEN_COLOR
static const std::string P_TOP_BRUSH_COLOR
static const std::string P_ROUGHNESS_PEN_WIDTH
static const std::string P_TOP_PEN_COLOR
static const std::string P_HEIGHT
static const std::string P_HANDLE_PEN_WIDTH
static const std::string P_TOP_THICKNESS
static const std::string P_R_HANDLE_BRUSH_COLOR
static const std::string P_SIDE_PEN_WIDTH
static const std::string P_HANDLE_RADIUS
static const std::string P_ROUGHNESS_BRUSH_COLOR
static const std::string P_WIDTH
static const std::string P_ROUGHNESS
static const std::string P_SIDE_PEN_COLOR
static const std::string P_X_POS
static const std::string P_R_HANDLE_PEN_COLOR
static const std::string P_R_HANDLE_PEN_WIDTH
static const std::string P_HANDLE_PEN_COLOR
static const std::string P_HANDLE_BRUSH_COLOR
The roughness QGraphicsViewItem.
void setRightPath(QPainterPath right_path)
Set the draw path for the right side.
void setBrush(QBrush brush)
Set the brush.
void setPen(QPen pen)
Set the pen.
void setLeftPath(QPainterPath left_path)
Set the draw path for the left side.
The segment QGraphicsViewItem on the Graphicsscene.
QPointF getLastPos() const
Get the last position of the item.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?
Defines class CLASS?