Commits

Panagiotis Mavrogiorgos committed b4eb138

Initial commit

Comments (0)

Files changed (10)

controllers/__init__.py

Empty file added.

controllers/controllers.py

+#!/usr/bin/env python
+#coding:utf-8
+
+from csvmodels import Reader
+from models.models import Nodes, Reactions
+
+
+def get_rmode_nodes(filename):
+    s = []
+    sa = s.append
+
+    with open(filename, "r") as f:
+        reader = Reader(Nodes, f)
+        for row in reader:
+            node = row.node
+            X = row.X
+            Y = row.Y
+            sa("{0:5d}{1:15.3f}{2:10.3f}".format(node, X, Y))
+
+    s = "\n".join(s)
+    return s
+
+
+def get_smode_nodes(filename):
+    s = []
+    sa = s.append
+
+    with open(filename, "r") as f:
+        reader = Reader(Nodes, f)
+        for row in reader:
+            node = row.node
+            X = row.X
+            Y = row.Y
+            Z = row.Z
+            sa("{0:5d}{1:15.3f}{2:10.3f}{3:10.3f}".format(node, X, Y, Z))
+
+    s = "\n".join(s)
+    return s
+
+
+def get_smode_reactions(filename):
+    s = []
+    sa = s.append
+
+    with open(filename, "r") as f:
+        reader = Reader(Reactions, f)
+        rows = reader.get_rows()
+
+    with open(filename, "r") as f:
+        reader = Reader(Reactions, f)
+        columns = reader.get_columns()
+
+    number_of_cases = len(set(columns["case"]))
+
+    for i, row in enumerate(rows):
+        node = row.node
+        case = 3 + i % number_of_cases
+        Fx = row.Fx
+        Fy = row.Fy
+        Fz = row.Fz
+        Mx = row.Mx
+        My = row.My
+        Mz = row.Mz
+
+        sa("{0:5d}{1:>15d}{2:10.2f}{3:10.2f}{4:10.2f}"
+            "{5:10.2f}{6:10.2f}{7:10.2f}".format(
+                node, case, Fx, Fy, Fz, Mx, My, Mz))
+
+    s = "\n".join(s)
+    return s
+
+
+def get_rmode_reactions(filename):
+    s = []
+    sa = s.append
+
+    with open(filename, "r") as f:
+        reader = Reader(Reactions, f)
+        rows = reader.get_rows()
+
+    with open(filename, "r") as f:
+        reader = Reader(Reactions, f)
+        columns = reader.get_columns()
+
+    number_of_cases = len(set(columns["case"]))
+
+    for i, row in enumerate(rows):
+        node = row.node
+        case = 3 + i % number_of_cases
+        Fx = row.Fx
+        Fy = row.Fy
+        Fz = row.Fz
+        Mx = row.Mx
+        My = row.My
+        Mz = row.Mz
+
+        sa("{0:5d}{8:>15d}{1:>15d}{2:10.2f}{3:10.2f}{4:10.2f}"
+            "{5:10.2f}{6:10.2f}{7:10.2f}".format(
+                node, case, Fx, Fy, Fz, Mx, My, Mz, 1))
+
+    s = "\n".join(s)
+    return s
+../csvmodels/csvmodels/

models/__init__.py

Empty file added.
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from csvmodels import RowModel, FloatColumn, StringColumn, IntegerColumn
+
+
+class Nodes(RowModel):
+    node = IntegerColumn()
+    X = FloatColumn()
+    Y = FloatColumn(multiplier=-1)
+    Z = FloatColumn(multiplier=-1)
+    support = StringColumn()
+
+    _dialect = {
+        "has_header_row": True,
+        "delimiter": ";",
+        }
+
+
+class Reactions(RowModel):
+    node = IntegerColumn()
+    case = StringColumn()
+    Fx = FloatColumn(multiplier=-1)
+    Fy = FloatColumn()
+    Fz = FloatColumn()
+    Mx = FloatColumn(multiplier=-1)
+    My = FloatColumn()
+    Mz = FloatColumn()
+
+    _dialect = {
+        "has_header_row": True,
+        "delimiter": ";",
+        }
+
+Some scripts for moving data from Robot and Next
+csvmodels
+PyQt4
+#!/usr/bin/env python
+#coding:utf-8
+# Author: Panagiotis Mavrogiorgos -- pmav99 <> gmail
+# Created: 28/07/2012
+
+import sys
+import os.path as osp
+
+from PyQt4.QtGui import (QApplication, QDialog, QDialogButtonBox, QGridLayout,
+                         QLabel, QFrame, QLineEdit, QWidget, QStyle,
+                         QFileDialog, QIcon, QTextEdit,
+                         QVBoxLayout, QTabWidget, QMainWindow, QPushButton)
+
+from various.pyqt_helpers import get_std_icon
+
+from controllers.controllers import (get_rmode_nodes, get_rmode_reactions,
+                                     get_smode_nodes, get_smode_reactions)
+
+
+class MyTextDialog(QDialog):
+    def __init__(self, parent, text):
+        super().__init__(parent)
+
+        self.setGeometry(100, 100, 700, 500)
+        text_widget = QTextEdit()
+        text_widget.setFontFamily("Courier")
+        text_widget.setPlainText(text)
+
+        box_layout = QVBoxLayout(self)
+        box_layout.addWidget(text_widget)
+
+        self.setLayout(box_layout)
+
+
+class Frame(QFrame):
+    def __init__(self, parent):
+        super(Frame, self).__init__(parent)
+
+        grid = QGridLayout(self)
+
+        rmode_nodes_label = QLabel("R-Mode nodes", self)
+        smode_nodes_label = QLabel("S-Mode nodes", self)
+        rmode_reactions_label = QLabel("R-Mode reactions", self)
+        smode_reactions_label = QLabel("S-Mode reactions", self)
+
+        rmode_nodes_lineedit = QLineEdit(self)
+        smode_nodes_lineedit = QLineEdit(self)
+        rmode_reactions_lineedit = QLineEdit(self)
+        smode_reactions_lineedit = QLineEdit(self)
+
+        rmode_nodes_button = QPushButton(get_std_icon("SP_DialogOpenButton"), "")
+        smode_nodes_button = QPushButton(get_std_icon("SP_DialogOpenButton"), "")
+        rmode_reactions_button = QPushButton(get_std_icon("SP_DialogOpenButton"), "")
+        smode_reactions_button = QPushButton(get_std_icon("SP_DialogOpenButton"), "")
+
+        rmode_nodes_process = QPushButton("Process")
+        smode_nodes_process = QPushButton("Process")
+        rmode_reactions_process = QPushButton("Process")
+        smode_reactions_process = QPushButton("Process")
+
+        grid.addWidget(rmode_nodes_label, 0, 0)
+        grid.addWidget(smode_nodes_label, 1, 0)
+        grid.addWidget(rmode_reactions_label, 2, 0)
+        grid.addWidget(smode_reactions_label, 3, 0)
+
+        grid.addWidget(rmode_nodes_lineedit, 0, 1)
+        grid.addWidget(smode_nodes_lineedit, 1, 1)
+        grid.addWidget(rmode_reactions_lineedit, 2, 1)
+        grid.addWidget(smode_reactions_lineedit, 3, 1)
+
+        grid.addWidget(rmode_nodes_button, 0, 2)
+        grid.addWidget(smode_nodes_button, 1, 2)
+        grid.addWidget(rmode_reactions_button, 2, 2)
+        grid.addWidget(smode_reactions_button, 3, 2)
+
+        grid.addWidget(rmode_nodes_process, 0, 3)
+        grid.addWidget(smode_nodes_process, 1, 3)
+        grid.addWidget(rmode_reactions_process, 2, 3)
+        grid.addWidget(smode_reactions_process, 3, 3)
+
+        # Bind buttons
+        rmode_nodes_button.pressed.connect(
+            lambda: self.on_open_file(rmode_nodes_lineedit))
+        smode_nodes_button.pressed.connect(
+            lambda: self.on_open_file(smode_nodes_lineedit))
+        rmode_reactions_button.pressed.connect(
+            lambda: self.on_open_file(rmode_reactions_lineedit))
+        smode_reactions_button.pressed.connect(
+            lambda: self.on_open_file(smode_reactions_lineedit))
+
+        rmode_nodes_process.pressed.connect(
+            lambda: self.on_process(rmode_nodes_lineedit.text(), get_rmode_nodes))
+        smode_nodes_process.pressed.connect(
+            lambda: self.on_process(smode_nodes_lineedit.text(), get_smode_nodes))
+        rmode_reactions_process.pressed.connect(
+            lambda: self.on_process(rmode_reactions_lineedit.text(), get_rmode_reactions))
+        smode_reactions_process.pressed.connect(
+            lambda: self.on_process(smode_reactions_lineedit.text(), get_smode_reactions))
+
+        self.setLayout(grid)
+
+    def on_process(self, filename, function):
+        text = function(filename)
+        dialog = MyTextDialog(self, text)
+        if dialog.exec_():
+            pass
+
+    def on_open_file(self, widget):
+        extensions = "*.csv"
+        caption = "Choose the csv file"
+        filename = (QFileDialog.getOpenFileName(self, caption=caption,
+                                                filter=extensions))
+        if filename != "":
+            widget.setText(osp.abspath(filename))
+
+
+class MainWindow(QMainWindow):
+    def __init__(self):
+        super(MainWindow, self).__init__()
+
+        frame = Frame(self)
+        self.setCentralWidget(frame)
+
+
+def run():
+    app = QApplication(sys.argv)
+    main = MainWindow()
+    main.show()
+    sys.exit(app.exec_())
+
+
+if __name__ == "__main__":
+    run()

various/__init__.py

Empty file added.

various/pyqt_helpers.py

+#!/usr/bin/env python
+#coding:utf-8
+
+from PyQt4.QtGui import QWidget, QIcon, QStyle
+
+
+def get_std_icon(name, size=None):
+    """
+    Get standard platform icon
+    """
+    if not name.startswith('SP_'):
+        name = 'SP_' + name
+    icon = QWidget().style().standardIcon(getattr(QStyle, name))
+    if size is None:
+        return icon
+    else:
+        return QIcon(icon.pixmap(size, size))