diff --git a/components/geometry/base/geom_modes.py b/components/geometry/base/geom_modes.py index 60a2129..56d493e 100644 --- a/components/geometry/base/geom_modes.py +++ b/components/geometry/base/geom_modes.py @@ -295,12 +295,40 @@ def _onKeyPressed(self, _evt): if BaseEditMode._onKeyPressed(self, _evt): return True key = _evt.key - + if key == ois.KC_C: _selected = self._logic._getSheet().getSelected() + if len(_selected) == 1 and isinstance(_selected[0], GeometryTriangle): + + obj = _selected[0] + circlePoints = obj._calculateCirclePoints() + + CoordinateC = circlePoints[0] + center = self._logic.createPoint(CoordinateC) + sheet = self._logic._getSheet() + sheet.addChild(center) + center._updateView() + + CoordinateT = circlePoints[1] + + sideObjects = self._logic._getSheet()._getObjectsUnderMouse(True, True, CoordinateT) + line = comutils._getFirstObjectTypeFromList(sideObjects, [GeometryLineSection]) + + tangent = self._logic.createPoint(CoordinateT) + sheet = self._logic._getSheet() + sheet.addChild(tangent) + + tangent._updateView() + + _selected = center, tangent + + obj._setCenterPoints(_selected) + obj._setIsCircleDrawed(True) + self.active_object = self._logic.createCircle() if self.active_object.makeBasedOnObjects(_selected): self._logic._getSheet().addChild(self.active_object) + else: self.active_object.delete() self.active_object = None diff --git a/components/geometry/base/geom_objects.py b/components/geometry/base/geom_objects.py index 80ebeeb..aa741a6 100644 --- a/components/geometry/base/geom_objects.py +++ b/components/geometry/base/geom_objects.py @@ -948,7 +948,8 @@ def __init__(self): self.__manualObject = None # manual object to store and render geometry self.pts = [] # triangle vertex points self.sides = [] # triangle sides - + self.isCircleDrawed = False + self.circlePoints = [] def __del__(self): suit.core.objects.ObjectDepth.__del__(self) GeometryAbstractObject.__del__(self) @@ -1013,6 +1014,16 @@ def _update(self, _timeSinceLastFrame): self.__manualObject.triangle(2, 1, 0) self.__manualObject.end() + + # update circle points position + if self.isCircleDrawed: + circlePointsCoordinats = self._calculateCirclePoints() + circle = self.circlePoints[0] + tangent = self.circlePoints[1] + circle.setPosition(render_engine.pos2dTo3dIsoPos(circlePointsCoordinats[0])) + tangent.setPosition(render_engine.pos2dTo3dIsoPos(circlePointsCoordinats[1])) + else: + self.isCircleDrawed = False suit.core.objects.ObjectDepth._update(self, _timeSinceLastFrame) @@ -1146,8 +1157,59 @@ def build_text_idtf(self): return u"%s(%s;%s;%s)" % (u'Треугк', idtf1, idtf2, idtf3) else: - return None - + return None + + def _calculateCirclePoints(self): + """Calculate points for incircle and draw it on objects sheet + """ + + x1 = render_engine.pos3dTo2dWindow(self.pts[0].getPosition())[0] + y1 = render_engine.pos3dTo2dWindow(self.pts[0].getPosition())[1] + x2 = render_engine.pos3dTo2dWindow(self.pts[1].getPosition())[0] + y2 = render_engine.pos3dTo2dWindow(self.pts[1].getPosition())[1] + x3 = render_engine.pos3dTo2dWindow(self.pts[2].getPosition())[0] + y3 = render_engine.pos3dTo2dWindow(self.pts[2].getPosition())[1] + + + p13 = math.sqrt(math.pow(x1 - x3, 2) + math.pow(y1 - y3, 2)) + p12 = math.sqrt(math.pow(x1 - x2, 2) + math.pow(y1 - y2, 2)) + p32 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2)) + + cx = (p32 * x1 + p13 * x2 + p12 * x3) / (p12 + p13 + p32) + cy = (p32 * y1 + p13 * y2 + p12 * y3) / (p12 + p13 + p32) + + halfPerimeter = (p12 + p13 + p32) / 2 + + tx = (x1 - x3) * (halfPerimeter - p12) / p13 + x3 + ty = (y1 - y3) * (halfPerimeter - p12) / p13 + y3 + + # create center point + CoordinateC = cx, cy + + # create tangent point + CoordinateT = tx, ty + + return [CoordinateC, CoordinateT] + + def _setCenterPoints(self, circlePoints): + """set list of incircle points + """ + self.circlePoints = circlePoints + + def _getCenterPoints(self): + """get list of incircle points + """ + return self.circlePoints + + def _setIsCircleDrawed(self, isCircleDrawed): + """set flag indicating if incircle drawed + """ + self.isCircleDrawed = isCircleDrawed + + def _getIsCircleDrawed(self): + """get flag indicating if incircle drawed + """ + return self.isCircleDrawed class GeometryQuadrangle(suit.core.objects.ObjectDepth, GeometryAbstractObject):