Beispiel #1
0
    def create(self, title, function, xlength, xname, xunit, xscale, yname,
               yunit, yscale, numxpoints):
        # Initialize
        from FreeCAD.Plot import Plot
        self.title = title
        self.function = function  # This is assumed to be always a SegmentFunction
        self.xlength = xlength
        self.xname = xname
        self.xunit = xunit
        self.xscale = xscale
        self.yname = yname
        self.yunit = yunit
        self.yscale = yscale
        self.numxpoints = numxpoints

        # Create a plot window
        self.win = Plot.figure(title)
        # Get the plot object from the window
        self.thePlot = Plot.getPlot()
        # Format the plot object
        Plot.xlabel("$%s$ [%s]" % (xname, xunit))
        Plot.ylabel("$%s$ [%s]" % (yname, yunit))
        Plot.grid(True)

        # Calculate points
        (self.xpoints,
         self.ypoints) = self.function.evaluate(self.xlength, self.numxpoints)
        # Create plot
        self.plot()
Beispiel #2
0
 def Activated(self):
     from FreeCAD.Plot import Plot
     plt = Plot.getPlot()
     if not plt:
         msg = QtGui.QApplication.translate(
             "plot_console",
             "The grid must be activated on top of a plot document",
             None)
         FreeCAD.Console.PrintError(msg + "\n")
         return
     flag = plt.isGrid()
     Plot.grid(not flag)
Beispiel #3
0
    def plot(self, roll, gz):
        """ Plot the GZ curve.

        Position arguments:
        roll -- List of roll angles (in degrees).
        gz -- List of GZ values (in meters).
        """
        try:
            from FreeCAD.Plot import Plot
        except ImportError:
            try:
                from freecad.plot import Plot
            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
        plt = Plot.figure('GZ')
        self.plt = plt

        gz_plot = Plot.plot(roll, gz, 'GZ curve')
        gz_plot.line.set_linestyle('-')
        gz_plot.line.set_linewidth(1.0)
        gz_plot.line.set_color((0.0, 0.0, 0.0))
        self.gz = gz_plot

        ax = Plot.axes()
        Plot.xlabel(r'$\phi \; [\mathrm{deg}]$')
        Plot.ylabel(r'$GZ \; [\mathrm{m}]$')
        ax.xaxis.label.set_fontsize(20)
        ax.yaxis.label.set_fontsize(20)

        Plot.grid(True)
        plt.update()
        return False
Beispiel #4
0
    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
        except ImportError:
            try:
                from freecad.plot import Plot
            except ImportError:
                msg = QtGui.QApplication.translate("ship_console",
                                                   "Plot module is disabled",
                                                   None)
                FreeCAD.Console.PrintWarning(msg + '\n')
                return True

        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
        return False
Beispiel #5
0
    def plot(self, l, z, v):
        """ Perform the areas curve plot.
        @param l Percentages of filling level.
        @param z Level z coordinates.
        @param v Volume of fluid.
        @return True if error happens.
        """
        try:
            from FreeCAD.Plot import Plot
        except ImportError:
            try:
                from freecad.plot import Plot
            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
        plt = Plot.figure('Capacity curve')
        self.plt = plt

        # 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))
        self.l = vols
        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))
        self.z = vols
        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
Beispiel #6
0
    def plotCoeffs(self):
        """ Perform stability hydrostatics.
        @return True if error happens.
        """
        # Create plot
        try:
            from FreeCAD.Plot import Plot
        except ImportError:
            try:
                from freecad.plot import Plot
            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
        plt = Plot.figure('Coefficients')
        self.plt3 = plt

        # Generate the set 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 = []
        cb = []
        cf = []
        cm = []
        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)
            cb.append(self.points[i].Cb)
            cf.append(self.points[i].Cf)
            cm.append(self.points[i].Cm)

        axes = Plot.axesList()
        for ax in axes:
            ax.set_position([0.1, 0.35, 0.8, 0.65])

        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))
        self.draft3 = serie
        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(cb, disp, r'$Cb$')
        serie.line.set_linestyle('-')
        serie.line.set_linewidth(2.0)
        serie.line.set_color((1.0, 0.0, 0.0))
        self.cb = serie
        Plot.xlabel(r'$Cb$ (Block coefficient)')
        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(cf, disp, r'$Cf$')
        serie.line.set_linestyle('-')
        serie.line.set_linewidth(2.0)
        serie.line.set_color((0.0, 0.0, 1.0))
        self.cf = serie
        Plot.xlabel(r'$Cf$ (floating area coefficient)')
        plt.axes.xaxis.label.set_fontsize(15)
        plt.axes.yaxis.label.set_fontsize(15)
        plt.axes = axes[3]
        serie = Plot.plot(cm, disp, r'$Cm$')
        serie.line.set_linestyle('-')
        serie.line.set_linewidth(2.0)
        serie.line.set_color((0.2, 0.8, 0.2))
        self.cm = serie
        Plot.xlabel(r'$Cm$  (Main section coefficient)')
        plt.axes.xaxis.label.set_fontsize(15)
        plt.axes.yaxis.label.set_fontsize(15)

        Plot.legend(True)
        plt.update()
        return False
Beispiel #7
0
    def plotStability(self):
        """ Perform stability hydrostatics.
        @return True if error happens.
        """
        try:
            from FreeCAD.Plot import Plot
        except ImportError:
            try:
                from freecad.plot import Plot
            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
        plt = Plot.figure('Stability')
        self.plt2 = plt

        # 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.35, 0.8, 0.65])

        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))
        self.draft2 = serie
        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))
        self.farea = serie
        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))
        self.kbt = serie
        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))
        self.bmt = serie
        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
Beispiel #8
0
    def plotVolume(self):
        """ Perform volumetric hydrostatics.
        @return True if error happens.
        """
        try:
            from FreeCAD.Plot import Plot
        except ImportError:
            try:
                from freecad.plot import Plot
            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
        plt = Plot.figure('Volume')
        self.plt1 = plt

        # Generate the set 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 = []
        warea = []
        t1cm = []
        xcb = []
        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)
            warea.append(self.points[i].wet.getValueAs("m^2").Value)
            t1cm.append(self.points[i].mom.getValueAs("kg*m").Value / 1000.0)
            xcb.append(self.points[i].xcb.getValueAs("m").Value)

        axes = Plot.axesList()
        for ax in axes:
            ax.set_position([0.1, 0.35, 0.8, 0.65])

        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))
        self.draft1 = serie
        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(warea, disp, r'Wetted area')
        serie.line.set_linestyle('-')
        serie.line.set_linewidth(2.0)
        serie.line.set_color((1.0, 0.0, 0.0))
        self.warea = serie
        Plot.xlabel(r'$Wetted \; 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(t1cm, disp, r'Moment to trim 1cm')
        serie.line.set_linestyle('-')
        serie.line.set_linewidth(2.0)
        serie.line.set_color((0.0, 0.0, 1.0))
        self.t1cm = serie
        Plot.xlabel(r'$Moment \; to \; trim \; 1 \mathrm{cm} \; \left['
                    r' \mathrm{tons} \; \times \; \mathrm{m} \right]$')
        plt.axes.xaxis.label.set_fontsize(15)
        plt.axes.yaxis.label.set_fontsize(15)
        plt.axes = axes[3]
        serie = Plot.plot(xcb, disp, r'$XCB$')
        serie.line.set_linestyle('-')
        serie.line.set_linewidth(2.0)
        serie.line.set_color((0.2, 0.8, 0.2))
        self.xcb = serie
        Plot.xlabel(r'$XCB \; \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