From aa16e2b1bff6e9adaf7345f45425b5162abd4d52 Mon Sep 17 00:00:00 2001
From: IgorekLoschinin <igor.loschinin2014@yandex.ru>
Date: Wed, 8 Sep 2021 22:20:52 +0300
Subject: [PATCH] ref #97 Added method for update position and draw-circle and
 square.

---
 src/Core/Crawl/controlpos.cpp | 68 +++++++++++++++++++++++++++++------
 src/Core/Crawl/controlpos.h   | 50 +++++++++++++++++++-------
 2 files changed, 96 insertions(+), 22 deletions(-)

diff --git a/src/Core/Crawl/controlpos.cpp b/src/Core/Crawl/controlpos.cpp
index 191e63b..86a38ec 100644
--- a/src/Core/Crawl/controlpos.cpp
+++ b/src/Core/Crawl/controlpos.cpp
@@ -6,6 +6,8 @@
 //#
 
 #include "controlpos.h"
+#include "clasteritem.h"
+#include <QtMath>
 
 namespace CRAWL {
 
@@ -15,28 +17,74 @@ ControlPos::ControlPos() {
 
 void ControlPos::add(ClasterItem *object) {
 
-    GroupObject::updatePosition();
+    Claster::add(object);
+    updatePosition();
 
 }
 
 void ControlPos::remove(ClasterItem *object) {
 
-    GroupObject::updatePosition();
+    Claster::remove(object->guiId());
+    updatePosition();
 
 }
 
-void ControlPos::changeLayout(const _Figure &fig) {
+void ControlPos::changeLayout(const Refresh &fig) {
+    _shape = fig;
+}
 
-    if (fig == CIRCLE) {
-        GroupObject::updatePosition();
+void ControlPos::setDistance(int dist) {
+    _distance = dist;
+}
+
+void ControlPos::updatePosition() {
+
+    switch (_shape) {
+        case CIRCLE:
+            drawCircle();
+            break;
+
+        case SQUARE:
+            drawSquare();
+            break;
+
+        case LINE:
+            break;
+
+        default:
+            break;
+     }
+
+}
+
+void ControlPos::drawCircle() {
+
+    float step =  360 / objects().size();
+    int temp = 1;
+
+    for (ClasterItem* object: objects()) {
+
+        float x = _distance * qCos(step*temp);
+        float y = _distance * qSin(step*temp);
+        GroupObject::updatePosition(object->guiId(), {x, y, 0});
+
+        temp++;
     }
 
-    if (fig == SQUARE) {
-        GroupObject::updatePosition();
-    }
+}
 
-    if (fig == LINE) {
-        GroupObject::updatePosition();
+void ControlPos::drawSquare() {
+
+    float step =  360 / objects().size();
+    int temp = 1;
+
+    for (ClasterItem* object: objects()) {
+
+        float x = _distance * qCos(step*temp);
+        float y = _distance * qSin(step*temp);
+        GroupObject::updatePosition(object->guiId(), {x, y, 0});
+
+        temp++;
     }
 
 }
diff --git a/src/Core/Crawl/controlpos.h b/src/Core/Crawl/controlpos.h
index 1b87a74..8f234c2 100644
--- a/src/Core/Crawl/controlpos.h
+++ b/src/Core/Crawl/controlpos.h
@@ -14,7 +14,18 @@
 namespace CRAWL {
 
 /**
- * @brief The ControlPos class
+ * @brief The Refresh enum Lists the shapes to convert the group object to.
+ */
+enum Refresh {
+    CIRCLE,
+    SPHERE,
+    SQUARE,
+    CUBE,
+    LINE
+};
+
+/**
+ * @brief The ControlPos class The class that control position of group objects.
  */
 class ControlPos: public GroupObject {
 public:
@@ -25,22 +36,37 @@ public:
     void add(ClasterItem *object);
     void remove(ClasterItem *object);
 
+    /**
+     * @brief changeLayout This method defines the shape of the group object.
+     * @param fig This is the name of the figure to change the group object.
+     */
+    void changeLayout(const Refresh &fig);
+
+    /**
+     * @brief setDistance This method sets, depending on the shape selected, the radius for the circle or the indentation for the square.
+     * @param dist This is the radius or margin.
+     */
+    void setDistance(int dist);
+
 private:
 
-    /**
-     * @brief The _Figure enum
-     */
-    enum _Figure {
-        CIRCLE,
-        SQUARE,
-        LINE
-    };
+    int _distance;
+    Refresh _shape;
 
     /**
-     * @brief changeLayout
-     * @param fig
+     * @brief updatePosition This method updates the coordinates of the positions of all objects.
      */
-    void changeLayout(const _Figure &fig);
+    void updatePosition();
+
+    /**
+     * @brief drawCircle This method updates the coordinates to a circle shape.
+     */
+    void drawCircle();
+
+    /**
+     * @brief drawSquare This method updates the coordinates to a square shape.
+     */
+    void drawSquare();
 
 };