def setupUi(self): mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") self.form = form form.axId = self.widget(QtGui.QSpinBox, "axesIndex") form.new = self.widget(QtGui.QPushButton, "newAxesButton") form.remove = self.widget(QtGui.QPushButton, "delAxesButton") form.all = self.widget(QtGui.QCheckBox, "allAxes") form.xMin = self.widget(QtGui.QSlider, "posXMin") form.xMax = self.widget(QtGui.QSlider, "posXMax") form.yMin = self.widget(QtGui.QSlider, "posYMin") form.yMax = self.widget(QtGui.QSlider, "posYMax") form.xAlign = self.widget(QtGui.QComboBox, "xAlign") form.yAlign = self.widget(QtGui.QComboBox, "yAlign") form.xOffset = self.widget(QtGui.QSpinBox, "xOffset") form.yOffset = self.widget(QtGui.QSpinBox, "yOffset") form.xAuto = self.widget(QtGui.QCheckBox, "xAuto") form.yAuto = self.widget(QtGui.QCheckBox, "yAuto") form.xSMin = self.widget(QtGui.QLineEdit, "xMin") form.xSMax = self.widget(QtGui.QLineEdit, "xMax") form.ySMin = self.widget(QtGui.QLineEdit, "yMin") form.ySMax = self.widget(QtGui.QLineEdit, "yMax") self.retranslateUi() # Look for active axes if can axId = 0 plt = Plot.getPlot() if plt: while plt.axes != plt.axesList[axId]: axId = axId + 1 form.axId.setValue(axId) self.updateUI() QtCore.QObject.connect(form.axId, QtCore.SIGNAL('valueChanged(int)'), self.onAxesId) QtCore.QObject.connect(form.new, QtCore.SIGNAL("pressed()"), self.onNew) QtCore.QObject.connect(form.remove, QtCore.SIGNAL("pressed()"), self.onRemove) QtCore.QObject.connect(form.xMin, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(form.xMax, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(form.yMin, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(form.yMax, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(form.xAlign, QtCore.SIGNAL("currentIndexChanged(int)"), self.onAlign) QtCore.QObject.connect(form.yAlign, QtCore.SIGNAL("currentIndexChanged(int)"), self.onAlign) QtCore.QObject.connect(form.xOffset, QtCore.SIGNAL("valueChanged(int)"), self.onOffset) QtCore.QObject.connect(form.yOffset, QtCore.SIGNAL("valueChanged(int)"), self.onOffset) QtCore.QObject.connect(form.xAuto, QtCore.SIGNAL("stateChanged(int)"), self.onScales) QtCore.QObject.connect(form.yAuto, QtCore.SIGNAL("stateChanged(int)"), self.onScales) QtCore.QObject.connect(form.xSMin, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect(form.xSMax, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect(form.ySMin, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect(form.ySMax, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect( Plot.getMdiArea(), QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"), self.onMdiArea) return False
def plotStability(self): """ Perform stability hydrostatics. @return True if error happens. """ try: from freecad.plot import Plot plt = Plot.figure('Stability') except ImportError: return True # Generate the sets of axes Plot.grid(True) for i in range(0, 3): ax = Plot.addNewAxes() # Y axis can be placed at right ax.yaxis.tick_right() ax.spines['right'].set_color((0.0, 0.0, 0.0)) ax.spines['left'].set_color('none') ax.yaxis.set_ticks_position('right') ax.yaxis.set_label_position('right') # And X axis can be placed at bottom for loc, spine in ax.spines.items(): if loc in ['bottom', 'top']: spine.set_position(('outward', (i + 1) * 35)) Plot.grid(True) disp = [] draft = [] farea = [] kbt = [] bmt = [] for i in range(len(self.points)): disp.append(self.points[i].disp.getValueAs("kg").Value / 1000.0) draft.append(self.points[i].draft.getValueAs("m").Value) farea.append(self.points[i].farea.getValueAs("m^2").Value) kbt.append(self.points[i].KBt.getValueAs("m").Value) bmt.append(self.points[i].BMt.getValueAs("m").Value) axes = Plot.axesList() for ax in axes: ax.set_position([0.1, 0.2, 0.8, 0.75]) plt.axes = axes[0] serie = Plot.plot(draft, disp, r'$T$') serie.line.set_linestyle('-') serie.line.set_linewidth(2.0) serie.line.set_color((0.0, 0.0, 0.0)) Plot.xlabel(r'$T \; \left[ \mathrm{m} \right]$') Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$') plt.axes.xaxis.label.set_fontsize(15) plt.axes.yaxis.label.set_fontsize(15) plt.axes = axes[1] serie = Plot.plot(farea, disp, r'Floating area') serie.line.set_linestyle('-') serie.line.set_linewidth(2.0) serie.line.set_color((1.0, 0.0, 0.0)) Plot.xlabel(r'$Floating \; area \; \left[ \mathrm{m}^2 \right]$') Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$') plt.axes.xaxis.label.set_fontsize(15) plt.axes.yaxis.label.set_fontsize(15) plt.axes = axes[2] serie = Plot.plot(kbt, disp, r'$KB_T$') serie.line.set_linestyle('-') serie.line.set_linewidth(2.0) serie.line.set_color((0.0, 0.0, 1.0)) Plot.xlabel(r'$KB_T \; \left[ \mathrm{m} \right]$') plt.axes.xaxis.label.set_fontsize(15) plt.axes.yaxis.label.set_fontsize(15) plt.axes = axes[3] serie = Plot.plot(bmt, disp, r'$BM_T$') serie.line.set_linestyle('-') serie.line.set_linewidth(2.0) serie.line.set_color((0.2, 0.8, 0.2)) Plot.xlabel(r'$BM_T \; \left[ \mathrm{m} \right]$') plt.axes.xaxis.label.set_fontsize(15) plt.axes.yaxis.label.set_fontsize(15) Plot.legend(True) plt.update() return False
def updateUI(self): """Setup UI controls values if possible""" plt = Plot.getPlot() # Get again all the subwidgets (to avoid PySide Pitfalls) mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.axId = self.widget(QtGui.QSpinBox, "axesIndex") form.new = self.widget(QtGui.QPushButton, "newAxesButton") form.remove = self.widget(QtGui.QPushButton, "delAxesButton") form.all = self.widget(QtGui.QCheckBox, "allAxes") form.xMin = self.widget(QtGui.QSlider, "posXMin") form.xMax = self.widget(QtGui.QSlider, "posXMax") form.yMin = self.widget(QtGui.QSlider, "posYMin") form.yMax = self.widget(QtGui.QSlider, "posYMax") form.xAlign = self.widget(QtGui.QComboBox, "xAlign") form.yAlign = self.widget(QtGui.QComboBox, "yAlign") form.xOffset = self.widget(QtGui.QSpinBox, "xOffset") form.yOffset = self.widget(QtGui.QSpinBox, "yOffset") form.xAuto = self.widget(QtGui.QCheckBox, "xAuto") form.yAuto = self.widget(QtGui.QCheckBox, "yAuto") form.xSMin = self.widget(QtGui.QLineEdit, "xMin") form.xSMax = self.widget(QtGui.QLineEdit, "xMax") form.ySMin = self.widget(QtGui.QLineEdit, "yMin") form.ySMax = self.widget(QtGui.QLineEdit, "yMax") # Enable/disable them form.axId.setEnabled(bool(plt)) form.new.setEnabled(bool(plt)) form.remove.setEnabled(bool(plt)) form.all.setEnabled(bool(plt)) form.xMin.setEnabled(bool(plt)) form.xMax.setEnabled(bool(plt)) form.yMin.setEnabled(bool(plt)) form.yMax.setEnabled(bool(plt)) form.xAlign.setEnabled(bool(plt)) form.yAlign.setEnabled(bool(plt)) form.xOffset.setEnabled(bool(plt)) form.yOffset.setEnabled(bool(plt)) form.xAuto.setEnabled(bool(plt)) form.yAuto.setEnabled(bool(plt)) form.xSMin.setEnabled(bool(plt)) form.xSMax.setEnabled(bool(plt)) form.ySMin.setEnabled(bool(plt)) form.ySMax.setEnabled(bool(plt)) if not plt: form.axId.setValue(0) return # Ensure that active axes is correct index = min(form.axId.value(), len(plt.axesList) - 1) form.axId.setValue(index) # Set dimensions ax = plt.axes bb = ax.get_position() form.xMin.setValue(int(100 * bb.min[0])) form.xMax.setValue(int(100 * bb.max[0])) form.yMin.setValue(int(100 * bb.min[1])) form.yMax.setValue(int(100 * bb.max[1])) # Set alignment and offset xPos = ax.xaxis.get_ticks_position() yPos = ax.yaxis.get_ticks_position() xOffset = ax.spines['bottom'].get_position()[1] yOffset = ax.spines['left'].get_position()[1] if xPos == 'bottom' or xPos == 'default': form.xAlign.setCurrentIndex(0) else: form.xAlign.setCurrentIndex(1) form.xOffset.setValue(xOffset) if yPos == 'left' or yPos == 'default': form.yAlign.setCurrentIndex(0) else: form.yAlign.setCurrentIndex(1) form.yOffset.setValue(yOffset) # Set scales if ax.get_autoscalex_on(): form.xAuto.setChecked(True) form.xSMin.setEnabled(False) form.xSMax.setEnabled(False) else: form.xAuto.setChecked(False) form.xSMin.setEnabled(True) form.xSMax.setEnabled(True) lim = ax.get_xlim() form.xSMin.setText(str(lim[0])) form.xSMax.setText(str(lim[1])) if ax.get_autoscaley_on(): form.yAuto.setChecked(True) form.ySMin.setEnabled(False) form.ySMax.setEnabled(False) else: form.yAuto.setChecked(False) form.ySMin.setEnabled(True) form.ySMax.setEnabled(True) lim = ax.get_ylim() form.ySMin.setText(str(lim[0])) form.ySMax.setText(str(lim[1]))
def onScales(self): """Executed when axes scales have been modified.""" # Ensure that we can work plt = Plot.getPlot() if not plt: self.updateUI() return # Get again all the subwidgets (to avoid PySide Pitfalls) mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.all = self.widget(QtGui.QCheckBox, "allAxes") form.xAuto = self.widget(QtGui.QCheckBox, "xAuto") form.yAuto = self.widget(QtGui.QCheckBox, "yAuto") form.xSMin = self.widget(QtGui.QLineEdit, "xMin") form.xSMax = self.widget(QtGui.QLineEdit, "xMax") form.ySMin = self.widget(QtGui.QLineEdit, "yMin") form.ySMax = self.widget(QtGui.QLineEdit, "yMax") axesList = [plt.axes] if form.all.isChecked(): axesList = plt.axesList if not self.skip: self.skip = True # X axis if form.xAuto.isChecked(): for ax in axesList: ax.set_autoscalex_on(True) form.xSMin.setEnabled(False) form.xSMax.setEnabled(False) lim = plt.axes.get_xlim() form.xSMin.setText(str(lim[0])) form.xSMax.setText(str(lim[1])) else: form.xSMin.setEnabled(True) form.xSMax.setEnabled(True) try: xMin = float(form.xSMin.text()) except: xMin = plt.axes.get_xlim()[0] form.xSMin.setText(str(xMin)) try: xMax = float(form.xSMax.text()) except: xMax = plt.axes.get_xlim()[1] form.xSMax.setText(str(xMax)) for ax in axesList: ax.set_xlim((xMin, xMax)) # Y axis if form.yAuto.isChecked(): for ax in axesList: ax.set_autoscaley_on(True) form.ySMin.setEnabled(False) form.ySMax.setEnabled(False) lim = plt.axes.get_ylim() form.ySMin.setText(str(lim[0])) form.ySMax.setText(str(lim[1])) else: form.ySMin.setEnabled(True) form.ySMax.setEnabled(True) try: yMin = float(form.ySMin.text()) except: yMin = plt.axes.get_ylim()[0] form.ySMin.setText(str(yMin)) try: yMax = float(form.ySMax.text()) except: yMax = plt.axes.get_ylim()[1] form.ySMax.setText(str(yMax)) for ax in axesList: ax.set_ylim((yMin, yMax)) plt.update() self.skip = False
def plot(self, l, z, v, tank): """ Perform the areas curve plot. @param l Percentages of filling level. @param z Level z coordinates. @param v Volume of fluid. @param tank Active tank instance. @return True if error happens. """ try: from freecad.plot import Plot plt = Plot.figure('Capacity curve') except ImportError: msg = QtGui.QApplication.translate( "ship_console", "Plot module is disabled, so I cannot perform the plot", None) FreeCAD.Console.PrintWarning(msg + '\n') return True # Plot the volume as a function of the level percentage vols = Plot.plot(l, v, 'Capacity') vols.line.set_linestyle('-') vols.line.set_linewidth(2.0) vols.line.set_color((0.0, 0.0, 0.0)) Plot.xlabel(r'$\mathrm{level}$') Plot.ylabel(r'$V \; [\mathrm{m}^3]$') plt.axes.xaxis.label.set_fontsize(20) plt.axes.yaxis.label.set_fontsize(20) Plot.grid(True) # Special percentage formatter for the x axis fmt = '%.0f%%' xticks = mtick.FormatStrFormatter(fmt) plt.axes.xaxis.set_major_formatter(xticks) # Now duplicate the axes ax = Plot.addNewAxes() # Y axis can be placed at right ax.yaxis.tick_right() ax.spines['right'].set_color((0.0, 0.0, 0.0)) ax.spines['left'].set_color('none') ax.yaxis.set_ticks_position('right') ax.yaxis.set_label_position('right') # And X axis can be placed at top ax.xaxis.tick_top() ax.spines['top'].set_color((0.0, 0.0, 1.0)) ax.spines['bottom'].set_color('none') ax.xaxis.set_ticks_position('top') ax.xaxis.set_label_position('top') # Plot the volume as a function of the level z coordinate vols = Plot.plot(z, v, 'level') vols.line.set_linestyle('-') vols.line.set_linewidth(2.0) vols.line.set_color((0.0, 0.0, 1.0)) Plot.xlabel(r'$z \; [\mathrm{m}]$') Plot.ylabel(r'$V \; [\mathrm{m}^3]$') ax.xaxis.label.set_fontsize(20) ax.yaxis.label.set_fontsize(20) ax.xaxis.label.set_color((0.0, 0.0, 1.0)) ax.tick_params(axis='x', colors=(0.0, 0.0, 1.0)) Plot.grid(True) # End plt.update() return False
def plot(self, x, y, disp, xcb, ship): """ Perform the areas curve plot. @param x X coordinates. @param y Transversal areas. @param disp Ship displacement. @param xcb Buoyancy center length. @param ship Active ship instance. @return True if error happens. """ try: from freecad.plot import Plot plt = Plot.figure('Areas curve') except ImportError: msg = QtGui.QApplication.translate( "ship_console", "Plot module is disabled, so I cannot perform the plot", None) FreeCAD.Console.PrintWarning(msg + '\n') return True # Plot areas curve areas = Plot.plot(x, y, 'Transversal areas') areas.line.set_linestyle('-') areas.line.set_linewidth(2.0) areas.line.set_color((0.0, 0.0, 0.0)) # Get perpendiculars data Lpp = ship.Length.getValueAs('m').Value FPx = 0.5 * Lpp APx = -0.5 * Lpp maxArea = max(y) # Plot perpendiculars FP = Plot.plot([FPx, FPx], [0.0, maxArea]) FP.line.set_linestyle('-') FP.line.set_linewidth(1.0) FP.line.set_color((0.0, 0.0, 0.0)) AP = Plot.plot([APx, APx], [0.0, maxArea]) AP.line.set_linestyle('-') AP.line.set_linewidth(1.0) AP.line.set_color((0.0, 0.0, 0.0)) # Add annotations for prependiculars ax = Plot.axes() ax.annotate('AP', xy=(APx + 0.01 * Lpp, 0.01 * maxArea), size=15) ax.annotate('AP', xy=(APx + 0.01 * Lpp, 0.95 * maxArea), size=15) ax.annotate('FP', xy=(FPx + 0.01 * Lpp, 0.01 * maxArea), size=15) ax.annotate('FP', xy=(FPx + 0.01 * Lpp, 0.95 * maxArea), size=15) # Add some additional data addInfo = ("$XCB = {0} \\; \\mathrm{{m}}$\n" "$Area_{{max}} = {1} \\; \\mathrm{{m}}^2$\n" "$\\bigtriangleup = {2} \\; \\mathrm{{tons}}$".format( xcb.getValueAs("m").Value, maxArea, disp.getValueAs("kg").Value / 1000.0)) ax.text(0.0, 0.01 * maxArea, addInfo, verticalalignment='bottom', horizontalalignment='center', fontsize=20) # Write axes titles Plot.xlabel(r'$x \; \mathrm{m}$') Plot.ylabel(r'$Area \; \mathrm{m}^2$') ax.xaxis.label.set_fontsize(20) ax.yaxis.label.set_fontsize(20) # Show grid Plot.grid(True) # End plt.update() return False
def updateUI(self): """ Setup UI controls values if possible """ mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.items = self.widget(QtGui.QListWidget, "items") form.label = self.widget(QtGui.QLineEdit, "label") form.isLabel = self.widget(QtGui.QCheckBox, "isLabel") form.style = self.widget(QtGui.QComboBox, "lineStyle") form.marker = self.widget(QtGui.QComboBox, "markers") form.width = self.widget(QtGui.QDoubleSpinBox, "lineWidth") form.size = self.widget(QtGui.QSpinBox, "markerSize") form.color = self.widget(QtGui.QPushButton, "color") form.remove = self.widget(QtGui.QPushButton, "remove") plt = Plot.getPlot() form.items.setEnabled(bool(plt)) form.label.setEnabled(bool(plt)) form.isLabel.setEnabled(bool(plt)) form.style.setEnabled(bool(plt)) form.marker.setEnabled(bool(plt)) form.width.setEnabled(bool(plt)) form.size.setEnabled(bool(plt)) form.color.setEnabled(bool(plt)) form.remove.setEnabled(bool(plt)) if not plt: self.plt = plt form.items.clear() return self.skip = True # Refill list if self.plt != plt or len(Plot.series()) != form.items.count(): self.plt = plt self.setList() # Ensure that have series if not len(Plot.series()): form.label.setEnabled(False) form.isLabel.setEnabled(False) form.style.setEnabled(False) form.marker.setEnabled(False) form.width.setEnabled(False) form.size.setEnabled(False) form.color.setEnabled(False) form.remove.setEnabled(False) return # Set label serie = Plot.series()[self.item] if serie.name is None: form.isLabel.setChecked(True) form.label.setEnabled(False) form.label.setText("") else: form.isLabel.setChecked(False) form.label.setText(serie.name) # Set line style and marker form.style.setCurrentIndex(0) linestyles = list(Line2D.lineStyles.keys()) for i in range(0, len(linestyles)): style = linestyles[i] if style == serie.line.get_linestyle(): form.style.setCurrentIndex(i) form.marker.setCurrentIndex(0) markers = list(Line2D.markers.keys()) for i in range(0, len(markers)): marker = markers[i] if marker == serie.line.get_marker(): form.marker.setCurrentIndex(i) # Set line width and marker size form.width.setValue(serie.line.get_linewidth()) form.size.setValue(serie.line.get_markersize()) # Set color color = Colors.colorConverter.to_rgb(serie.line.get_color()) form.color.setStyleSheet("background-color: rgb({}, {}, {});".format( int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))) self.skip = False