Skip to content

Commit

Permalink
Fixed bug where removing constraint in GUI could remove the wrong con…
Browse files Browse the repository at this point in the history
…straint object with the same type, fixed "new geo col" behavior and auto range geometry
  • Loading branch information
mlauer154 committed Feb 12, 2024
1 parent 213c14a commit 3f0578b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions pymead/core/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def add_constraint(self, constraint: GeoCon):
def _remove_distance_constraint_from_directed_edge(self, constraint: DistanceConstraint):
edges_removed = None
edge_data_12 = self.get_edge_data(constraint.p1, constraint.p2)
if edge_data_12 is not None and "distance" in edge_data_12.keys():
if edge_data_12 is not None and "distance" in edge_data_12.keys() and edge_data_12["distance"] is constraint:
angle_constraint_present = False
for geo_con in constraint.p2.geo_cons:
if (isinstance(geo_con, RelAngle3Constraint) or
Expand All @@ -539,7 +539,7 @@ def _remove_distance_constraint_from_directed_edge(self, constraint: DistanceCon
return edges_removed

edge_data_21 = self.get_edge_data(constraint.p2, constraint.p1)
if edge_data_21 is not None and "distance" in edge_data_21.keys():
if edge_data_21 is not None and "distance" in edge_data_21.keys() and edge_data_21["distance"] is constraint:
angle_constraint_present = False
for geo_con in constraint.p1.geo_cons:
if (isinstance(geo_con, RelAngle3Constraint) or
Expand All @@ -561,7 +561,7 @@ def _remove_angle_constraint_from_directed_edge(
self, constraint: RelAngle3Constraint or AntiParallel3Constraint or Perp3Constraint):
edges_removed = None
edge_data_21 = self.get_edge_data(constraint.p2, constraint.p1)
if edge_data_21 is not None and "angle" in edge_data_21.keys():
if edge_data_21 is not None and "angle" in edge_data_21.keys() and edge_data_21["angle"] is constraint:
if "distance" in edge_data_21.keys():
edge_data_21.pop("angle")
else:
Expand All @@ -577,7 +577,7 @@ def _remove_angle_constraint_from_directed_edge(
return edges_removed

edge_data_23 = self.get_edge_data(constraint.p2, constraint.p3)
if edge_data_23 is not None and "angle" in edge_data_23.keys():
if edge_data_23 is not None and "angle" in edge_data_23.keys() and edge_data_23["angle"] is constraint:
if "distance" in edge_data_23.keys():
edge_data_23.pop("angle")
else:
Expand Down
14 changes: 10 additions & 4 deletions pymead/gui/airfoil_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ def getPointRange(self):
"""
point_seq = PointSequence(points=[pt for pt in self.geo_col.container()["points"].values()])
pseq_arr = point_seq.as_array()
min_x = pseq_arr[:, 0].min()
max_x = pseq_arr[:, 0].max()
min_y = pseq_arr[:, 1].min()
max_y = pseq_arr[:, 1].max()
if len(pseq_arr) > 0:
min_x = pseq_arr[:, 0].min()
max_x = pseq_arr[:, 0].max()
min_y = pseq_arr[:, 1].min()
max_y = pseq_arr[:, 1].max()
else:
min_x = -0.05
max_x = 1.05
min_y = -0.25
max_y = 0.25
return [min_x, max_x], [min_y, max_y]

def drawPoint(self, x, y):
Expand Down
37 changes: 18 additions & 19 deletions pymead/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def __init__(self, path=None, parent=None):
else:
raise ValueError(f"Current theme options are 'dark' and 'light'. Theme chosen was {theme}")

# self.auto_range_geometry()
self.auto_range_geometry()
self.statusBar().clearMessage()
self.permanent_widget = PermanentWidget(self)
self.statusBar().addPermanentWidget(self.permanent_widget)
Expand Down Expand Up @@ -647,8 +647,7 @@ def load_geo_col(self):
def new_geo_col(self):
dialog = NewGeoColDialog(self)
if dialog.exec_():
self.load_geo_col_no_dialog(os.path.join(GUI_DEFAULT_AIRFOIL_DIR, "default_airfoil.jmea"))
self.mea.file_name = None
self.load_geo_col_no_dialog()
self.setWindowTitle(f"pymead")

def edit_bounds(self):
Expand Down Expand Up @@ -936,34 +935,34 @@ def plot_field(self):
self.cbar.getAxis("right").setWidth(20 + 2 * get_setting("axis-label-point-size") +
2 * get_setting("cbar-tick-point-size"))

def load_geo_col_no_dialog(self, file_name):
self.permanent_widget.progress_bar.setValue(0)
self.permanent_widget.progress_bar.show()
self.statusBar().showMessage("Loading MEA...")
n_func_strs = count_func_strs(file_name)
def load_geo_col_no_dialog(self, file_name: str = None):
# self.permanent_widget.progress_bar.setValue(0)
# self.permanent_widget.progress_bar.show()
# self.statusBar().showMessage("Loading MEA...")

self.airfoil_canvas.clear()
self.parameter_tree.clear()
self.parameter_tree.addContainers()

self.permanent_widget.progress_bar.setValue(10)
self.statusBar().showMessage("Adding airfoils...")
# self.permanent_widget.progress_bar.setValue(10)
# self.statusBar().showMessage("Adding airfoils...")
# for a in self.mea.airfoils.values():
# a.update()
# self.v.clear()
# self.param_tree_instance.t.clear()
geo_col_dict = load_data(file_name)
if file_name is not None:
geo_col_dict = load_data(file_name)
else:
geo_col_dict = GeometryCollection().get_dict_rep()
self.geo_col = GeometryCollection.set_from_dict_rep(geo_col_dict, canvas=self.airfoil_canvas,
tree=self.parameter_tree, gui_obj=self)

self.permanent_widget.progress_bar.setValue(20)
# self.permanent_widget.progress_bar.setValue(20)
# for idx, airfoil in enumerate(self.mea.airfoils.values()):
# self.mea.add_airfoil_graph_to_airfoil(airfoil, idx, None, w=self.w, v=self.v, gui_obj=self)
self.permanent_widget.progress_bar.setValue(25)
ProgressInfo = namedtuple("ProgressInfo", ("start", "end", "n"))
progress_info = ProgressInfo(25, 85, n_func_strs)
# self.permanent_widget.progress_bar.setValue(25)
# self.param_tree_instance = MEAParamTree(self.mea, self.statusBar(), parent=self, progress_info=progress_info)
self.permanent_widget.progress_bar.setValue(85)
# self.permanent_widget.progress_bar.setValue(85)
# for a in self.mea.airfoils.values():
# a.airfoil_graph.param_tree = self.param_tree_instance
# a.airfoil_graph.airfoil_parameters = a.airfoil_graph.param_tree.p.param('Airfoil Parameters')
Expand All @@ -982,9 +981,9 @@ def load_geo_col_no_dialog(self, file_name):
# self.main_layout.replaceWidget(widget0, self.design_tree_widget)
# widget0.deleteLater()
# self.mea_start_dict = self.copy_mea_dict()
self.permanent_widget.progress_bar.setValue(100)
self.statusBar().showMessage("Airfoil system load complete.", 2000)
self.permanent_widget.progress_bar.hide()
# self.permanent_widget.progress_bar.setValue(100)
# self.statusBar().showMessage("Airfoil system load complete.", 2000)
# self.permanent_widget.progress_bar.hide()
self.geo_col.tree.geo_col = self.geo_col
self.geo_col.canvas.geo_col = self.geo_col
self.auto_range_geometry()
Expand Down

0 comments on commit 3f0578b

Please sign in to comment.