Draft: clean up OrthoArray code

Avoid `Draft.py` in the `make_ortho_array` function because
it creates a circular dependency.

Use internal functions to abstract the orthogonal arrays.
The `_make_ortho_array` is a simple wrapper over the general
`make_array` function.

The result is four variants:
- `make_ortho_array`
- `make_ortho_array2d`, without the Z component
- `make_rect_array`, strictly rectangular components
- `make_rect_array2d`, strictly rectangular without the Z component

Also use functions to perform checking of the inputs,
whether these are vectors, numbers (integer and floats)
or integers.

Now the make function accepts as input a `"String"` which must be
the `Label` of an object in the document, so it is easier to create
arrays quickly from the Python console.

Clean up the GuiCommand and task panel code, and avoid printing
messages to the terminal, as this is already done
by the make function.
This commit is contained in:
vocx-fc
2020-05-24 21:29:08 -05:00
committed by Yorik van Havre
parent 8573bc01e9
commit 5dcb4ea104
3 changed files with 287 additions and 174 deletions

View File

@@ -33,9 +33,10 @@ import FreeCADGui as Gui
import Draft_rc # include resources, icons, ui files
import DraftVecUtils
import draftutils.utils as utils
from FreeCAD import Units as U
from draftutils.messages import _msg, _err, _log
from draftutils.translate import _tr
from FreeCAD import Units as U
# The module is used to prevent complaints from code checkers (flake8)
bool(Draft_rc.__name__)
@@ -186,7 +187,8 @@ class TaskPanelOrthoArray:
self.n_x, self.n_y, self.n_z)
if self.valid_input:
self.create_object()
self.print_messages()
# The internal function already displays messages
# self.print_messages()
self.finish()
def validate_input(self, selection,
@@ -237,14 +239,12 @@ class TaskPanelOrthoArray:
sel_obj = self.selection[0]
# This creates the object immediately
# obj = Draft.makeArray(sel_obj,
# self.v_x, self.v_y, self.v_z,
# self.n_x, self.n_y, self.n_z,
# self.use_link)
# if obj:
# obj.Fuse = self.fuse
# obj = Draft.make_ortho_array(sel_obj,
# self.v_x, self.v_y, self.v_z,
# self.n_x, self.n_y, self.n_z,
# self.use_link)
# Instead, we build the commands to execute through the parent
# Instead, we build the commands to execute through the caller
# of this class, the GuiCommand.
# This is needed to schedule geometry manipulation
# that would crash Coin3D if done in the event callback.