~mrp/freecad.log_cabin

4d245aae6bfb18f991bd5a02e59e9da31f239140 — Mark Penner 1 year, 6 months ago 5381b15
add task panel for setting properties when creating a log wall
M freecad/log_cabin/__init__.py => freecad/log_cabin/__init__.py +1 -0
@@ 27,5 27,6 @@ import FreeCAD

__version__ = "0.0.0"
ICONPATH = os.path.join(os.path.dirname(__file__), "resources/icons")
UIPATH = os.path.join(os.path.dirname(__file__), "resources/ui")

FreeCAD.__unit_test__ += ["freecad.log_cabin.test_api"]

M freecad/log_cabin/gui_commands.py => freecad/log_cabin/gui_commands.py +25 -10
@@ 28,6 28,7 @@ from FreeCAD import Units
import FreeCADGui as Gui

from freecad.log_cabin import ICONPATH
from freecad.log_cabin import UIPATH


class CreateLog:


@@ 70,31 71,45 @@ class CreateLogWall:
    def Activated(self):
        """Create Walls when command is activated"""

        ui = LogWallPanel()
        Gui.Control.showDialog(ui)

    def IsActive(self):
        """set command to only be active if there is an active document"""
        return not App.activeDocument() is None


class LogWallPanel:
    """task panel for creating or editing a log wall"""

    def __init__(self, obj=None):
        self.form = Gui.PySideUic.loadUi(os.path.join(UIPATH, "log_wall_dialog.ui"))
        self.form.wall_height.setProperty("value", Units.Quantity("9ft"))
        self.form.logs_tall.setProperty("value", 10)

    def accept(self):
        from .api import make_log_wall

        logs_tall = 10
        height = Units.Quantity("9 ft")
        height = Units.Quantity(self.form.wall_height.text())
        logs_tall = self.form.logs_tall.value()
        start_with_half_log = self.form.half_log.isChecked()

        sel = Gui.Selection.getSelection()
        if sel:
            n = 0
            for obj in sel:
                if getattr(obj, "Shape", False):
                    start_with_half_log = True if n % 2 == 0 else False
                    make_log_wall(obj, height, logs_tall, start_with_half_log)
                    n += 1
                    start_with_half_log = not start_with_half_log
        else:
            from Draft import make_line

            p1 = App.Vector(0, 0, 0)
            p2 = App.Vector(3000, 0, 0)
            line = make_line(p1, p2)
            make_log_wall(line, height, logs_tall, False)
            make_log_wall(line, height, logs_tall, start_with_half_log)

        App.activeDocument().recompute()

    def IsActive(self):
        """set command to only be active if there is an active document"""
        return not App.activeDocument() is None
        Gui.Control.closeDialog()


class JoinLogWalls:

A freecad/log_cabin/resources/ui/log_wall_dialog.ui => freecad/log_cabin/resources/ui/log_wall_dialog.ui +84 -0
@@ 0,0 1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>309</width>
    <height>108</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <layout class="QFormLayout" name="formLayout_2">
   <item row="0" column="0">
    <widget class="QLabel" name="label">
     <property name="text">
      <string>Height</string>
     </property>
    </widget>
   </item>
   <item row="0" column="1">
    <widget class="Gui::QuantitySpinBox" name="wall_height">
     <property name="sizePolicy">
      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
       <horstretch>0</horstretch>
       <verstretch>0</verstretch>
      </sizepolicy>
     </property>
     <property name="unit" stdset="0">
      <string notr="true"/>
     </property>
    </widget>
   </item>
   <item row="1" column="0">
    <widget class="QLabel" name="label_3">
     <property name="text">
      <string>Number of logs</string>
     </property>
    </widget>
   </item>
   <item row="1" column="1">
    <widget class="Gui::IntSpinBox" name="logs_tall">
     <property name="sizePolicy">
      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
       <horstretch>0</horstretch>
       <verstretch>0</verstretch>
      </sizepolicy>
     </property>
    </widget>
   </item>
   <item row="2" column="0">
    <widget class="QLabel" name="label_4">
     <property name="text">
      <string>Start with half log</string>
     </property>
    </widget>
   </item>
   <item row="2" column="1">
    <widget class="QCheckBox" name="half_log">
     <property name="text">
      <string/>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <customwidgets>
  <customwidget>
   <class>Gui::QuantitySpinBox</class>
   <extends>QWidget</extends>
   <header>Gui/QuantitySpinBox.h</header>
  </customwidget>
  <customwidget>
   <class>Gui::IntSpinBox</class>
   <extends>QSpinBox</extends>
   <header>Gui/SpinBox.h</header>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>