Skip to content

Commit

Permalink
Draft: Reorganizing DraftEdit and future Draft command modules
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Aug 13, 2019
1 parent 537a011 commit 16c26cb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/Mod/Arch/InitGui.py
Expand Up @@ -64,9 +64,6 @@ def IsActive(self):
FreeCADGui.addCommand('Arch_RebarTools', RebarGroupCommand())
self.archtools[2] = "Arch_RebarTools"

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

# draft tools
self.drafttools = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc","Draft_Ellipse",
Expand Down
24 changes: 19 additions & 5 deletions src/Mod/Draft/DraftEdit.py
Expand Up @@ -27,16 +27,24 @@
__author__ = "Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline, Dmitry Chigrin"
__url__ = "http://www.freecadweb.org"

import FreeCAD, FreeCADGui, Draft, DraftTools, math
import FreeCAD
import Draft
import math

from FreeCAD import Vector
from DraftTrackers import *

from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
from DraftTools import translate
# Do not import GUI-related modules if GUI is not there
if FreeCAD.GuiUp:
import FreeCADGui
import DraftTools
from DraftTrackers import *
from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
from DraftTools import translate


class Edit():

"The Draft_Edit FreeCAD command definition"

def __init__(self):
Expand Down Expand Up @@ -1125,3 +1133,9 @@ def updatePanelSheet(self,v):
self.obj.TagPosition = self.invpl.multVec(v)
else:
self.obj.Group[self.editing-1].Placement.Base = self.invpl.multVec(v)



if FreeCAD.GuiUp:
# setup command
FreeCADGui.addCommand('Draft_Edit', Edit())
6 changes: 6 additions & 0 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -46,6 +46,12 @@
from DraftTrackers import *
from pivy import coin

#---------------------------------------------------------------------------
# Commands that have been migrated to their own modules
#---------------------------------------------------------------------------

import DraftEdit

#---------------------------------------------------------------------------
# Preflight stuff
#---------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions src/Mod/Draft/InitGui.py
Expand Up @@ -65,17 +65,13 @@ 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

3 comments on commit 16c26cb

@carlopav
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Yorik, thanks for taking care of this.

@yorikvanhavre
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure this is the best way, but definitely 1) we want Draft commands available across other workbenches and 2) we want it to be easy, ie. just one "import DraftTools" to create them all... We might get further, better ideas on how to achieve that...

@carlopav
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's good for the moment, since draft commands (AKA DraftTools) are by their role in between app and gui (they get user input and create or modify entities using code from Draft library), so, if mixing was your concern, that should not harm. Am I wrong?

Please sign in to comment.