Skip to content

Commit

Permalink
[Draft] Update DraftEdit PR with Yorik suggestions
Browse files Browse the repository at this point in the history
Cleanings of import at the beginning of new module.
Moved command setup in InitGui and removed import DraftEdit from DraftTools.
  • Loading branch information
carlopav authored and yorikvanhavre committed Jun 17, 2019
1 parent a4e2df1 commit c351b90
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
57 changes: 40 additions & 17 deletions src/Mod/Draft/DraftEdit.py
@@ -1,22 +1,40 @@
import sys, os, FreeCAD, FreeCADGui, WorkingPlane, math, re, Draft, Part, Draft_rc, DraftVecUtils
from FreeCAD import Vector
# -*- coding: utf8 -*-

#***************************************************************************
#* *
#* Copyright (c) 2009, 2010 *
#* Yorik van Havre <yorik@uncreated.net>, Ken Cline <cline@frii.com> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************

__title__="FreeCAD Draft Edit Tool"
__author__ = "Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline, Dmitry Chigrin"
__url__ = "http://www.freecadweb.org"

import FreeCAD, FreeCADGui, Draft, DraftTools, math

if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtGui,QtCore
from DraftTools import translate
from PySide.QtCore import QT_TRANSLATE_NOOP
else:
def translate(ctxt,txt):
return txt
def QT_TRANSLATE_NOOP(ctxt,txt):
return txt

from DraftSnap import *
from FreeCAD import Vector
from DraftTrackers import *
from pivy import coin

import DraftTools
from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
from DraftTools import translate

class Edit():
"The Draft_Edit FreeCAD command definition"
Expand Down Expand Up @@ -400,6 +418,7 @@ def addPointToWire(self, newPoint, edgeIndex):
self.resetTrackers()

def addPointToCurve(self,point,info=None):
import Part
if not (Draft.getType(self.obj) in ["BSpline","BezCurve"]): return
pts = self.obj.Points
if Draft.getType(self.obj) == "BezCurve":
Expand Down Expand Up @@ -549,7 +568,7 @@ def updateWire(self,v):
if Draft.getType(self.obj) in ["BezCurve"]:
pts = self.recomputePointsBezier(pts,self.editing,v,self.obj.Degree,moveTrackers=False)
# check that the new point lies on the plane of the wire
import DraftGeomUtils
import DraftGeomUtils, DraftVecUtils
if self.obj.Closed:
n = DraftGeomUtils.getNormal(self.obj.Shape)
dv = editPnt.sub(pts[self.editing])
Expand Down Expand Up @@ -620,6 +639,8 @@ def recomputePointsBezier(self,pts,idx,v,degree,moveTrackers=True):
self.finish()

def resetTrackersBezier(self):
#in future move tracker definition to DraftTrackers
from pivy import coin
knotmarkers = (coin.SoMarkerSet.DIAMOND_FILLED_9_9,#sharp
coin.SoMarkerSet.SQUARE_FILLED_9_9, #tangent
coin.SoMarkerSet.HOURGLASS_FILLED_9_9) #symmetric
Expand Down Expand Up @@ -738,6 +759,7 @@ def setRectanglePts(self):
self.by = self.by.negative()

def updateRectangle(self,v):
import DraftVecUtils
delta = v.sub(self.obj.Placement.Base)
if self.editing == 0:
p = self.obj.Placement
Expand Down Expand Up @@ -834,6 +856,7 @@ def updateCircle(self,v):
self.updateCirclePts(0,1,1,1)

elif self.arc3Pt == False:
import Part
if self.editing == 0:#center point
import DraftVecUtils
p1 = self.obj.Shape.Vertexes[0].Point
Expand Down
3 changes: 0 additions & 3 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -46,8 +46,6 @@
from DraftTrackers import *
from pivy import coin

import DraftEdit

#---------------------------------------------------------------------------
# Preflight stuff
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -5822,7 +5820,6 @@ def IsActive(self):
FreeCADGui.addCommand('Draft_Trimex',Trimex())
FreeCADGui.addCommand('Draft_Scale',Scale())
FreeCADGui.addCommand('Draft_Drawing',Drawing())
FreeCADGui.addCommand('Draft_Edit',DraftEdit.Edit())
FreeCADGui.addCommand('Draft_Edit_Improved',EditImproved())
FreeCADGui.addCommand('Draft_AddPoint',AddPoint())
FreeCADGui.addCommand('Draft_DelPoint',DelPoint())
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Draft/InitGui.py
Expand Up @@ -67,12 +67,16 @@ def QT_TRANSLATE_NOOP(scope, text):
# import Draft tools, icons
try:
import os,Draft_rc,DraftTools, DraftGui
import DraftEdit
from DraftTools import translate
FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.addIconPath(":/icons")
except Exception as inst:
print(inst)
FreeCAD.Console.PrintError("Error: Initializing one or more of the Draft modules failed, Draft will not work as expected.\n")

# setup commands
FreeCADGui.addCommand('Draft_Edit',DraftEdit.Edit())

# setup menus
self.cmdList = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_ArcTools","Draft_Ellipse",
Expand Down

0 comments on commit c351b90

Please sign in to comment.