Skip to content

Commit 0f2d761

Browse files
committed
Update rips module, proto files, and Python examples
1 parent 4679986 commit 0f2d761

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed

docs/rips/PythonExamples/surfaces_and_visualization/create_polygon.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,17 @@
3333
print("Coordinates for {}:".format(p.name))
3434
for coord in p.coordinates:
3535
print(coord)
36+
37+
# Customize appearance
38+
appearance = p.appearance()
39+
if appearance is not None:
40+
appearance.line_color = "#ff0000"
41+
appearance.line_thickness = 5
42+
appearance.show_spheres = True
43+
appearance.sphere_color = "#0000ff"
44+
appearance.update()
45+
print(
46+
"Appearance updated: line_color={}, line_thickness={}".format(
47+
appearance.line_color, appearance.line_thickness
48+
)
49+
)

docs/rips/PythonExamples/wells_and_fractures/import_well_paths_and_logs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
for well_path in well_paths:
3030
print("Imported from individual files: " + well_path.name)
3131

32+
# Set well path colors using hex color strings
33+
all_well_paths = resInsight.project.well_paths()
34+
colors = ["#ff0000", "#00ff00", "#0000ff", "#ffff00"]
35+
for i, well_path in enumerate(all_well_paths):
36+
well_path.well_path_color = colors[i % len(colors)]
37+
well_path.update()
38+
print("Set color of " + well_path.name + " to " + well_path.well_path_color)
39+
3240

3341
well_path_names = resInsight.project.import_well_log_files(
3442
well_log_folder="D:/Projects/ResInsight-regression-test/ModelData/Norne_PLT_LAS"

docs/rips/generated/generated_classes.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,11 +1084,13 @@ class WellPath(PdmObjectBase):
10841084
10851085
Attributes:
10861086
name (str): Name
1087+
well_path_color (str): Well Path Color
10871088
"""
10881089
__custom_init__ = None #: Assign a custom init routine to be run at __init__
10891090

10901091
def __init__(self, pb2_object: Optional[PdmObject_pb2.PdmObject]=None, channel: Optional[grpc.Channel]=None) -> None:
10911092
self.name: str = ""
1093+
self.well_path_color: str = "#ff55ff"
10921094
PdmObjectBase.__init__(self, pb2_object, channel)
10931095
if WellPath.__custom_init__ is not None:
10941096
WellPath.__custom_init__(self, pb2_object=pb2_object, channel=channel)
@@ -1490,6 +1492,16 @@ def __init__(self, pb2_object: Optional[PdmObject_pb2.PdmObject]=None, channel:
14901492
if Polygon.__custom_init__ is not None:
14911493
Polygon.__custom_init__(self, pb2_object=pb2_object, channel=channel)
14921494

1495+
def appearance(self) -> Optional[RimPolygonAppearance]:
1496+
"""Appearance
1497+
1498+
Returns:
1499+
RimPolygonAppearance
1500+
"""
1501+
children = self.children("Appearance", RimPolygonAppearance)
1502+
return children[0] if len(children) > 0 else None
1503+
1504+
14931505
class PolygonCollection(PdmObjectBase):
14941506
__custom_init__ = None #: Assign a custom init routine to be run at __init__
14951507

@@ -1980,6 +1992,35 @@ def __init__(self, pb2_object: Optional[PdmObject_pb2.PdmObject]=None, channel:
19801992
if MudWeightWindowParameters.__custom_init__ is not None:
19811993
MudWeightWindowParameters.__custom_init__(self, pb2_object=pb2_object, channel=channel)
19821994

1995+
class RimPolygonAppearance(PdmObjectBase):
1996+
"""
1997+
Attributes:
1998+
is_closed (bool): Closed Polygon
1999+
line_color (str): Line Color
2000+
line_thickness (int): Line Thickness
2001+
lock_polygon (bool): Lock Polygon to Plane
2002+
polygon_plane_depth (float): Polygon Plane Depth
2003+
show_lines (bool): Show Lines
2004+
show_spheres (bool): Show Spheres
2005+
sphere_color (str): Sphere Color
2006+
sphere_radius_factor (float): Sphere Radius Factor
2007+
"""
2008+
__custom_init__ = None #: Assign a custom init routine to be run at __init__
2009+
2010+
def __init__(self, pb2_object: Optional[PdmObject_pb2.PdmObject]=None, channel: Optional[grpc.Channel]=None) -> None:
2011+
self.is_closed: bool = True
2012+
self.line_color: str = "#ffa500"
2013+
self.line_thickness: int = 3
2014+
self.lock_polygon: bool = False
2015+
self.polygon_plane_depth: float = 0.000000000000000e+00
2016+
self.show_lines: bool = True
2017+
self.show_spheres: bool = False
2018+
self.sphere_color: str = "#ffa500"
2019+
self.sphere_radius_factor: float = 1.500000000000000e-01
2020+
PdmObjectBase.__init__(self, pb2_object, channel)
2021+
if RimPolygonAppearance.__custom_init__ is not None:
2022+
RimPolygonAppearance.__custom_init__(self, pb2_object=pb2_object, channel=channel)
2023+
19832024
class ReservoirGridEnsemble(NamedObject):
19842025
"""
19852026
Grid Ensemble from File Set
@@ -3805,6 +3846,7 @@ def class_dict() -> Dict[str, Type[PdmObjectBase]]:
38053846
classes['ResampleData'] = ResampleData
38063847
classes['Reservoir'] = Reservoir
38073848
classes['ReservoirGridEnsemble'] = ReservoirGridEnsemble
3849+
classes['RimPolygonAppearance'] = RimPolygonAppearance
38083850
classes['RimStatisticalCalculation'] = RimStatisticalCalculation
38093851
classes['RoffCase'] = RoffCase
38103852
classes['SimulationWell'] = SimulationWell
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
"""
2+
Tests for polygon appearance functionality.
3+
4+
These tests verify that polygon appearance properties can be read and modified
5+
via the Python API.
6+
"""
7+
8+
import os
9+
import sys
10+
11+
import pytest
12+
13+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
14+
15+
import rips
16+
17+
18+
@pytest.fixture
19+
def project(rips_instance):
20+
"""Get the current project."""
21+
return rips_instance.project
22+
23+
24+
class TestPolygonAppearance:
25+
"""Tests for PolygonAppearance functionality."""
26+
27+
@pytest.fixture
28+
def polygon(self, project):
29+
"""Create a test polygon."""
30+
polygon_collection = project.descendants(rips.PolygonCollection)[0]
31+
coordinates = [
32+
[100.0, 200.0, 300.0],
33+
[200.0, 200.0, 300.0],
34+
[200.0, 300.0, 300.0],
35+
[100.0, 300.0, 300.0],
36+
]
37+
p = polygon_collection.create_polygon(
38+
name="Test Polygon", coordinates=coordinates
39+
)
40+
return p
41+
42+
def test_access_appearance(self, polygon):
43+
"""Test that appearance child object is accessible."""
44+
appearance = polygon.appearance()
45+
assert appearance is not None, "Appearance should be accessible"
46+
47+
def test_default_values(self, polygon):
48+
"""Test that default appearance values are correct."""
49+
appearance = polygon.appearance()
50+
assert appearance.is_closed is True
51+
assert appearance.show_lines is True
52+
assert appearance.show_spheres is False
53+
assert appearance.line_thickness == 3
54+
assert appearance.lock_polygon is False
55+
56+
def test_set_line_color(self, polygon):
57+
"""Test setting line color."""
58+
appearance = polygon.appearance()
59+
appearance.line_color = "#ff0000"
60+
appearance.update()
61+
62+
# Re-read to verify persistence
63+
appearance2 = polygon.appearance()
64+
assert appearance2.line_color == "#ff0000"
65+
66+
def test_set_sphere_color(self, polygon):
67+
"""Test setting sphere color."""
68+
appearance = polygon.appearance()
69+
appearance.sphere_color = "#00ff00"
70+
appearance.update()
71+
72+
appearance2 = polygon.appearance()
73+
assert appearance2.sphere_color == "#00ff00"
74+
75+
def test_set_line_thickness(self, polygon):
76+
"""Test setting line thickness."""
77+
appearance = polygon.appearance()
78+
appearance.line_thickness = 5
79+
appearance.update()
80+
81+
appearance2 = polygon.appearance()
82+
assert appearance2.line_thickness == 5
83+
84+
def test_set_show_spheres(self, polygon):
85+
"""Test toggling sphere visibility."""
86+
appearance = polygon.appearance()
87+
appearance.show_spheres = True
88+
appearance.update()
89+
90+
appearance2 = polygon.appearance()
91+
assert appearance2.show_spheres is True
92+
93+
def test_set_sphere_radius_factor(self, polygon):
94+
"""Test setting sphere radius factor."""
95+
appearance = polygon.appearance()
96+
appearance.sphere_radius_factor = 0.5
97+
appearance.update()
98+
99+
appearance2 = polygon.appearance()
100+
assert abs(appearance2.sphere_radius_factor - 0.5) < 1e-6
101+
102+
def test_set_is_closed(self, polygon):
103+
"""Test setting closed polygon state."""
104+
appearance = polygon.appearance()
105+
appearance.is_closed = False
106+
appearance.update()
107+
108+
appearance2 = polygon.appearance()
109+
assert appearance2.is_closed is False
110+
111+
def test_set_lock_polygon(self, polygon):
112+
"""Test setting lock polygon to plane."""
113+
appearance = polygon.appearance()
114+
appearance.lock_polygon = True
115+
appearance.polygon_plane_depth = 500.0
116+
appearance.update()
117+
118+
appearance2 = polygon.appearance()
119+
assert appearance2.lock_polygon is True
120+
assert abs(appearance2.polygon_plane_depth - 500.0) < 1e-6
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
import os
3+
4+
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
5+
6+
import dataroot
7+
8+
9+
def test_well_path_color(rips_instance, initialize_test):
10+
"""Test reading and setting well path colors via Python API."""
11+
case_root_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC"
12+
case_path = case_root_path + "/TEST10K_FLT_LGR_NNC.EGRID"
13+
rips_instance.project.load_case(path=case_path)
14+
15+
well_path_files = [
16+
case_root_path + "/wellpath_a.dev",
17+
case_root_path + "/wellpath_b.dev",
18+
]
19+
rips_instance.project.import_well_paths(well_path_files)
20+
wells = rips_instance.project.well_paths()
21+
assert len(wells) == 2
22+
23+
# Read default color
24+
well_a = wells[0]
25+
well_b = wells[1]
26+
assert well_a.well_path_color is not None
27+
assert well_b.well_path_color is not None
28+
29+
# Set colors using hex strings
30+
well_a.well_path_color = "#ff0000"
31+
well_a.update()
32+
33+
well_b.well_path_color = "#0000ff"
34+
well_b.update()
35+
36+
# Re-fetch and verify colors persist
37+
wells = rips_instance.project.well_paths()
38+
assert wells[0].well_path_color == "#ff0000"
39+
assert wells[1].well_path_color == "#0000ff"

0 commit comments

Comments
 (0)