Module: MSPhysics::Dialog

Defined in:
RubyExtension/MSPhysics/dialog.rb

Overview

Since:

  • 1.0.0

Constant Summary collapse

USE_HTML_DIALOG =

Since:

  • 1.0.0

::Sketchup.version.to_i > 16 ? true : false
DEFAULT_EDITOR_THEME =

Since:

  • 1.0.0

'tomorrow_night'
DEFAULT_EDITOR_FONT =

Since:

  • 1.0.0

12
DEFAULT_EDITOR_WRAP =

Since:

  • 1.0.0

'free'
DEFAULT_EDITOR_PRINT_MARGIN =

Since:

  • 1.0.0

true
DEFAULT_EDITOR_SIZE =

Since:

  • 1.0.0

[800,600]
DEFAULT_DIALOG_HELP_BOX =

Since:

  • 1.0.0

true
DEFAULT_DIALOG_SCALE =

Since:

  • 1.0.0

1.0
PRECISION =

Since:

  • 1.0.0

3
TITLE =

Since:

  • 1.0.0

'MSPhysics UI'

Class Method Summary collapse

Class Method Details

.add_sound(path) ⇒ String

Add sound to UI.

Parameters:

  • path (String)

Returns:

  • (String)

    Name of added file.

Raises:

  • (TypeError)

    if file path is invalid.

  • (TypeError)

    if file is over 100 megabytes.

Since:

  • 1.0.0



1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
# File 'RubyExtension/MSPhysics/dialog.rb', line 1894

def add_sound(path)
  unless File.exist?(path)
    raise(TypeError, "Invalid path!", caller)
  end
  name = File.basename(path, File.extname(path)).gsub(/\'/, ' ')
  size = File.size(path) * 1.0e-6
  if size > 100
    raise(TypeError, "Selected file, \"#{File.basename(path)}\", is #{sprintf("%0.2f", size)} megabytes in size. File size must be no more than 100 megabytes!", caller)
  end
  ext = File.extname(path).downcase[1..-1]
  if MSPhysics::EMBEDDED_MUSIC_FORMATS.include?(ext) || MSPhysics::EMBEDDED_SOUND_FORMATS.include?(ext)
    file = File.new(path, 'rb')
    Sketchup.active_model.set_attribute('MSPhysics Sounds', name, file.read.unpack('l*'))
    Sketchup.active_model.set_attribute('MSPhysics Sound Types', name, ext)
    file.close
    music = MSPhysics::Music.get_by_name(name)
    MSPhysics::Music.destroy(music) if music
    name
  else
    raise(TypeError, "File format is not supported!", caller)
  end
end

.closeObject

Close the UI.

Since:

  • 1.0.0



1852
1853
1854
# File 'RubyExtension/MSPhysics/dialog.rb', line 1852

def close
  @dialog.close if @dialog
end

.execute_js(code) ⇒ Object

Execute JavaScript in the UI dialog.

Parameters:

  • code (String)

Since:

  • 1.0.0



44
45
46
47
48
# File 'RubyExtension/MSPhysics/dialog.rb', line 44

def execute_js(code)
  if @dialog && @init_called
    @dialog.execute_script(code)
  end
end

.fix_numeric_value(value) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Remove uncertain decimal places.

Parameters:

  • value (Numeric)

Returns:

  • (String)

Since:

  • 1.0.0



1033
1034
1035
1036
1037
1038
1039
# File 'RubyExtension/MSPhysics/dialog.rb', line 1033

def fix_numeric_value(value)
  if AMS::IS_RUBY_VERSION_18
    sprintf("%.8f", value.to_f).to_f
  else
    value.round(8)
  end
end

.format_value(value, precision = 2) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Format value into string.

Parameters:

  • value (Numeric)
  • precision (Integer) (defaults to: 2)

Returns:

  • (String)

Since:

  • 1.0.0



1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
# File 'RubyExtension/MSPhysics/dialog.rb', line 1017

def format_value(value, precision = 2)
  precision = AMS.clamp(precision.to_i, 0, 10)
  if precision == 0
    fv = value.to_i.to_s
  elsif value.to_f.zero?
    fv = '0.' + '0' * precision
  else
    fv = sprintf("%.#{precision}f", value.to_f)
  end
  return fv.to_f == value.to_f ? fv : '~ ' + fv
end

.get_joint_default_value(joint, attr_name) ⇒ Object?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get default value of a particular attribute in joint.

Parameters:

  • joint (Sketchup::Group, Sketchup::ComonentInstance)
  • attr_name (String)

Returns:

  • (Object, nil)

Since:

  • 1.0.0



861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'RubyExtension/MSPhysics/dialog.rb', line 861

def get_joint_default_value(joint, attr_name)
  jdict = 'MSPhysics Joint'
  attr = joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS)
  ang_ratio = MSPhysics::ANGLE_CONVERSION[attr]
  ang_ratio = 1.0 unless ang_ratio
  iang_ratio = 1.0 / ang_ratio
  attr = joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS)
  pos_ratio = MSPhysics::POSITION_CONVERSION[attr]
  pos_ratio = 1.0 unless pos_ratio
  ipos_ratio = 1.0 / pos_ratio
  joint_type = joint.get_attribute(jdict, 'Type')
  res = case joint_type
    when 'Hinge'
      case attr_name
        when 'Min'; MSPhysics::Hinge::DEFAULT_MIN * iang_ratio
        when 'Max'; MSPhysics::Hinge::DEFAULT_MAX * iang_ratio
        when 'Enable Limits'; MSPhysics::Hinge::DEFAULT_LIMITS_ENABLED
        when 'Mode'; MSPhysics::Hinge::DEFAULT_MODE
        when 'Friction'; MSPhysics::Hinge::DEFAULT_FRICTION
        when 'Accel'; MSPhysics::Hinge::DEFAULT_ACCEL
        when 'Damp'; MSPhysics::Hinge::DEFAULT_DAMP
        when 'Strength'; MSPhysics::Hinge::DEFAULT_STRENGTH
        when 'Spring Constant'; MSPhysics::Hinge::DEFAULT_SPRING_CONSTANT
        when 'Spring Drag'; MSPhysics::Hinge::DEFAULT_SPRING_DRAG
        when 'Start Angle'; MSPhysics::Hinge::DEFAULT_START_ANGLE * iang_ratio
        when 'Controller'; MSPhysics::Hinge::DEFAULT_CONTROLLER
      end
    when 'Motor'
      case attr_name
        when 'Accel'; MSPhysics::Motor::DEFAULT_ACCEL
        when 'Damp'; MSPhysics::Motor::DEFAULT_DAMP
        when 'Enable Free Rotate'; MSPhysics::Motor::DEFAULT_FREE_ROTATE_ENABLED
        when 'Controller'; MSPhysics::Motor::DEFAULT_CONTROLLER
      end
    when 'Servo'
      case attr_name
        when 'Min'; MSPhysics::Servo::DEFAULT_MIN * iang_ratio
        when 'Max'; MSPhysics::Servo::DEFAULT_MAX * iang_ratio
        when 'Enable Limits'; MSPhysics::Servo::DEFAULT_LIMITS_ENABLED
        when 'Rate'; MSPhysics::Servo::DEFAULT_RATE * iang_ratio
        when 'Power'; MSPhysics::Servo::DEFAULT_POWER
        when 'Reduction Ratio'; MSPhysics::Servo::DEFAULT_REDUCTION_RATIO
        when 'Controller'; MSPhysics::Servo::DEFAULT_CONTROLLER
      end
    when 'Slider'
      case attr_name
        when 'Min'; MSPhysics::Slider::DEFAULT_MIN * ipos_ratio
        when 'Max'; MSPhysics::Slider::DEFAULT_MAX * ipos_ratio
        when 'Enable Limits'; MSPhysics::Slider::DEFAULT_LIMITS_ENABLED
        when 'Friction'; MSPhysics::Slider::DEFAULT_FRICTION
        when 'Controller'; MSPhysics::Slider::DEFAULT_CONTROLLER
      end
    when 'Piston'
      case attr_name
        when 'Min'; MSPhysics::Piston::DEFAULT_MIN * ipos_ratio
        when 'Max'; MSPhysics::Piston::DEFAULT_MAX * ipos_ratio
        when 'Enable Limits'; MSPhysics::Piston::DEFAULT_LIMITS_ENABLED
        when 'Rate'; MSPhysics::Piston::DEFAULT_RATE * ipos_ratio
        when 'Power'; MSPhysics::Piston::DEFAULT_POWER
        when 'Reduction Ratio'; MSPhysics::Piston::DEFAULT_REDUCTION_RATIO
        when 'Controller'; MSPhysics::Piston::DEFAULT_CONTROLLER
        when 'Controller Mode'; MSPhysics::Piston::DEFAULT_CONTROLLER_MODE
      end
    when 'Spring'
      case attr_name
        when 'Min'; MSPhysics::Spring::DEFAULT_MIN * ipos_ratio
        when 'Max'; MSPhysics::Spring::DEFAULT_MAX * ipos_ratio
        when 'Enable Limits'; MSPhysics::Spring::DEFAULT_LIMITS_ENABLED
        when 'Enable Rotation'; MSPhysics::Spring::DEFAULT_ROTATION_ENABLED
        when 'Mode'; MSPhysics::Spring::DEFAULT_MODE
        when 'Accel'; MSPhysics::Spring::DEFAULT_ACCEL
        when 'Damp'; MSPhysics::Spring::DEFAULT_DAMP
        when 'Strength'; MSPhysics::Spring::DEFAULT_STRENGTH
        when 'Spring Constant'; MSPhysics::Spring::DEFAULT_SPRING_CONSTANT
        when 'Spring Drag'; MSPhysics::Spring::DEFAULT_SPRING_DRAG
        when 'Start Position'; MSPhysics::Spring::DEFAULT_START_POSITION * ipos_ratio
        when 'Controller'; MSPhysics::Spring::DEFAULT_CONTROLLER
      end
    when 'UpVector'
      case attr_name
        when 'Accel'; MSPhysics::UpVector::DEFAULT_ACCEL
        when 'Damp'; MSPhysics::UpVector::DEFAULT_DAMP
        when 'Strength'; MSPhysics::UpVector::DEFAULT_STRENGTH
        when 'Controller'; MSPhysics::UpVector::DEFAULT_PIN_DIR
      end
    when 'Corkscrew'
      case attr_name
        when 'Min Position'; MSPhysics::Corkscrew::DEFAULT_MIN_POSITION * ipos_ratio
        when 'Max Position'; MSPhysics::Corkscrew::DEFAULT_MAX_POSITION * ipos_ratio
        when 'Enable Linear Limits'; MSPhysics::Corkscrew::DEFAULT_LINEAR_LIMITS_ENABLED
        when 'Linear Friction'; MSPhysics::Corkscrew::DEFAULT_LINEAR_FRICTION
        when 'Min Angle'; MSPhysics::Corkscrew::DEFAULT_MIN_ANGLE * iang_ratio
        when 'Max Angle'; MSPhysics::Corkscrew::DEFAULT_MAX_ANGLE * iang_ratio
        when 'Enable Angular Limits'; MSPhysics::Corkscrew::DEFAULT_ANGULAR_LIMITS_ENABLED
        when 'Angular Friction'; MSPhysics::Corkscrew::DEFAULT_ANGULAR_FRICTION
      end
    when 'BallAndSocket'
      case attr_name
        when 'Max Cone Angle'; MSPhysics::BallAndSocket::DEFAULT_MAX_CONE_ANGLE * iang_ratio
        when 'Enable Cone Limits'; MSPhysics::BallAndSocket::DEFAULT_CONE_LIMITS_ENABLED
        when 'Min Twist Angle'; MSPhysics::BallAndSocket::DEFAULT_MIN_TWIST_ANGLE * iang_ratio
        when 'Max Twist Angle'; MSPhysics::BallAndSocket::DEFAULT_MAX_TWIST_ANGLE * iang_ratio
        when 'Enable Twist Limits'; MSPhysics::BallAndSocket::DEFAULT_TWIST_LIMITS_ENABLED
        when 'Friction'; MSPhysics::BallAndSocket::DEFAULT_FRICTION
        when 'Controller'; MSPhysics::BallAndSocket::DEFAULT_CONTROLLER
      end
    when 'Universal'
      case attr_name
        when 'Min1'; MSPhysics::Universal::DEFAULT_MIN * iang_ratio
        when 'Max1'; MSPhysics::Universal::DEFAULT_MAX * iang_ratio
        when 'Enable Limits1'; MSPhysics::Universal::DEFAULT_LIMITS_ENABLED
        when 'Min2'; MSPhysics::Universal::DEFAULT_MIN * iang_ratio
        when 'Max2'; MSPhysics::Universal::DEFAULT_MAX * iang_ratio
        when 'Enable Limits2'; MSPhysics::Universal::DEFAULT_LIMITS_ENABLED
        when 'Friction'; MSPhysics::Universal::DEFAULT_FRICTION
        when 'Controller'; MSPhysics::Universal::DEFAULT_CONTROLLER
      end
    when 'CurvySlider'
      case attr_name
        when 'Enable Alignment'; MSPhysics::CurvySlider::DEFAULT_ALIGNMENT_ENABLED
        when 'Enable Rotation'; MSPhysics::CurvySlider::DEFAULT_ROTATION_ENABLED
        when 'Enable Loop'; MSPhysics::CurvySlider::DEFAULT_LOOP_ENABLED
        when 'Linear Friction'; MSPhysics::CurvySlider::DEFAULT_LINEAR_FRICTION
        when 'Angular Friction'; MSPhysics::CurvySlider::DEFAULT_ANGULAR_FRICTION
        when 'Alignment Power'; MSPhysics::CurvySlider::DEFAULT_ALIGNMENT_POWER
        when 'Controller'; MSPhysics::CurvySlider::DEFAULT_CONTROLLER
      end
    when 'CurvyPiston'
      case attr_name
        when 'Enable Alignment'; MSPhysics::CurvyPiston::DEFAULT_ALIGNMENT_ENABLED
        when 'Enable Rotation'; MSPhysics::CurvyPiston::DEFAULT_ROTATION_ENABLED
        when 'Enable Loop'; MSPhysics::CurvyPiston::DEFAULT_LOOP_ENABLED
        when 'Angular Friction'; MSPhysics::CurvyPiston::DEFAULT_ANGULAR_FRICTION
        when 'Rate'; MSPhysics::CurvyPiston::DEFAULT_RATE * ipos_ratio
        when 'Power'; MSPhysics::CurvyPiston::DEFAULT_POWER
        when 'Alignment Power'; MSPhysics::CurvyPiston::DEFAULT_ALIGNMENT_POWER
        when 'Reduction Ratio'; MSPhysics::CurvyPiston::DEFAULT_REDUCTION_RATIO
        when 'Controller'; MSPhysics::CurvyPiston::DEFAULT_CONTROLLER
        when 'Controller Mode'; MSPhysics::CurvyPiston::DEFAULT_CONTROLLER_MODE
      end
    when 'Plane'
      case attr_name
        when 'Linear Friction'; MSPhysics::Plane::DEFAULT_LINEAR_FRICTION
        when 'Angular Friction'; MSPhysics::Plane::DEFAULT_ANGULAR_FRICTION
        when 'Enable Rotation'; MSPhysics::CurvySlider::DEFAULT_ROTATION_ENABLED
      end
  end
  res = fix_numeric_value(res) if res.is_a?(Numeric)
  res
end

.load_editor_settingsObject

Load editor settings from registry.

Since:

  • 1.0.0



1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
# File 'RubyExtension/MSPhysics/dialog.rb', line 1942

def load_editor_settings
  begin
    @editor_theme = Sketchup.read_default('MSPhysics', 'Editor Theme', DEFAULT_EDITOR_THEME).to_s
    @editor_font = Sketchup.read_default('MSPhysics', 'Editor Font', DEFAULT_EDITOR_FONT).to_i
    @editor_wrap = Sketchup.read_default('MSPhysics', 'Editor Wrap', DEFAULT_EDITOR_WRAP).to_s
    @editor_print_margin = Sketchup.read_default('MSPhysics', 'Editor Print Margin', DEFAULT_EDITOR_PRINT_MARGIN) ? true : false
    @editor_size = Kernel.eval(Sketchup.read_default('MSPhysics', 'Editor Size', DEFAULT_EDITOR_SIZE.inspect))
    if !@editor_size.is_a?(Array) || !@editor_size.x.is_a?(Integer) || !@editor_size.y.is_a?(Integer)
      @editor_size = DEFAULT_EDITOR_SIZE.dup
    end
    @dialog_help_box = Sketchup.read_default('MSPhysics', 'Dialog Help Box', DEFAULT_DIALOG_HELP_BOX) ? true : false
    @dialog_scale = Sketchup.read_default('MSPhysics', 'Dialog Scale', DEFAULT_DIALOG_SCALE).to_f
  rescue Exception => err
    @editor_theme = DEFAULT_EDITOR_THEME
    @editor_font = DEFAULT_EDITOR_FONT
    @editor_wrap = DEFAULT_EDITOR_WRAP
    @editor_print_margin = DEFAULT_EDITOR_PRINT_MARGIN
    @editor_size = DEFAULT_EDITOR_SIZE.dup
    @dialog_help_box = DEFAULT_DIALOG_HELP_BOX
    @dialog_scale = DEFAULT_DIALOG_SCALE
  end
end

.locate_error(error) ⇒ Boolean

Open MSPhysics UI and set pointer to the location of an error.

Parameters:

Returns:

  • (Boolean)

    success

Since:

  • 1.0.0



1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
# File 'RubyExtension/MSPhysics/dialog.rb', line 1865

def locate_error(error)
  AMS.validate_type(error, MSPhysics::ScriptException)
  return false unless error.entity.valid?
  model = Sketchup.active_model
  @app_observer.selection_observer_active = false
  model.selection.clear
  model.selection.add(error.entity)
  @app_observer.selection_observer_active = true
  @last_active_body_tab = 3
  msg = "setTimeout(function() { update_placement(3, true); }, 100);"
  msg << "setTimeout(function() { editor_set_cursor(#{error.line}, 0); editor_select_current_line(); }, 200);" if error.line
  if @dialog
    update_state
    execute_js(msg)
  else
    self.open
    t = ::UI.start_timer(0.25, false) {
      ::UI.stop_timer(t)
      execute_js(msg)
    }
  end
  true
end

.openObject

Open UI.

Since:

  • 1.0.0



1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
# File 'RubyExtension/MSPhysics/dialog.rb', line 1042

def open
  return if @dialog

  dbs = MSPhysics::DEFAULT_BODY_SETTINGS
  @material = MSPhysics::Material.new('Temp', dbs[:density], dbs[:static_friction], dbs[:kinetic_friction], dbs[:elasticity], dbs[:softness])

  iws = [520, 520]
  if USE_HTML_DIALOG
    @dialog = ::UI::HtmlDialog.new({
      :dialog_title => TITLE,
      :preferences_key => TITLE,
      :scrollable => false,
      :resizable => true,
      :width => iws.x,
      :height => iws.y,
      :left => 800,
      :top => 600,
      :min_width => 50,
      :min_height => 50,
      :max_width => -1,
      :max_height => -1,
      :style => ::UI::HtmlDialog::STYLE_DIALOG
    })
  else
    @dialog = ::UI::WebDialog.new(TITLE, false, TITLE, iws.x, iws.y, 800, 600, true)
  end

  # Callbacks
  @dialog.add_action_callback('init') { |acs, params|
    unless @init_called
      @init_called = true
      ds = eval(params)
      if AMS::IS_PLATFORM_WINDOWS && @handle
        ws = AMS::Window.get_size(@handle)
        cr = AMS::Window.get_client_rect(@handle)
        cs = [cr[2] - cr[0], cr[3] - cr[1]]
        @border_size.x = ws.x - cs.x
        @border_size.y = ws.y - cs.y
      else
        @border_size.x = 2
        @border_size.y = 24
      end
      @app_observer.selection_observer_active = true
    end
    execute_js("set_viewport_scale(#{@dialog_scale}); g_use_webdialog = #{!USE_HTML_DIALOG};")
    update_state
  }

  @dialog.add_action_callback('editor_changed') { |acs, params|
    if @selected_body && @selected_body.valid?
      code = USE_HTML_DIALOG ? params : @dialog.get_element_value('temp_script_area')
      @selected_body.set_attribute('MSPhysics Script', 'Value', code)
    end
  }

  @dialog.add_action_callback('cursor_changed') { |acs, params|
    if @selected_body && @selected_body.valid?
      @selected_body.set_attribute('MSPhysics Script', 'Cursor', params)
    end
  }

  @dialog.add_action_callback('open_link') { |acs, params|
    dir = File.dirname(__FILE__)
    intro = 'file:///'
    if params == 'http://mspdoc/index'
      fpath = File.join(dir, 'doc/index.html')
      if File.exist?(fpath)
        fpath = intro + File.expand_path(fpath)
      else
        fpath = "http://www.rubydoc.info/github/AntonSynytsia/MSPhysics/master/index"
      end
    elsif params == 'http://amsdoc/index'
      fpath = File.join(dir, '../ams_Lib/doc/index.html')
      if File.exist?(fpath)
        fpath = intro + File.expand_path(fpath)
      else
        fpath = "http://www.rubydoc.info/github/AntonSynytsia/AMS-Library/master/index"
      end
    elsif params == 'http://rubydoc/index'
      fpath = "http://ruby-doc.org/core-#{RUBY_VERSION}/"
    elsif params == 'http://mspdoc/controller'
      fpath = File.join(dir, 'doc/file.ControllersOverview.html')
      if File.exist?(fpath)
        fpath = intro + File.expand_path(fpath)
      else
        fpath = "http://www.rubydoc.info/github/AntonSynytsia/MSPhysics/master/file/RubyExtension/MSPhysics/ControllersOverview.md"
      end
    else
      fpath = params
    end
    ::UI.openURL(fpath)
  }

  @dialog.add_action_callback('check_input_changed') { |acs, params|
    settings = MSPhysics::Settings
    id, value = data = eval(params)
    dict, attr = id.split(/\-/, 2)
    words = attr.split(/\_/)
    for i in 0...words.size
      words[i].capitalize!
    end
    option = words.join(' ')
    case dict
    when 'simulation'
      settings = MSPhysics::Settings
      case attr
      when 'animate_scenes_reversed'
        settings.animate_scenes_reversed = value
      when 'continuous_collision'
        settings.continuous_collision_check_enabled = value
      when 'full_screen_mode'
        settings.full_screen_mode_enabled = value
      when 'game_mode'
        settings.game_mode_enabled = value
      when 'hide_joint_layer'
        settings.hide_joint_layer_enabled = value
      when 'undo_on_end'
        settings.undo_on_end_enabled = value
      when 'ignore_hidden_instances'
        settings.ignore_hidden_instances = value
      when 'collision_wireframe'
        settings.collision_wireframe_visible = value
      when 'axes'
        settings.axes_visible = value
      when 'aabb'
        settings.aabb_visible = value
      when 'contact_points'
        settings.contact_points_visible = value
      when 'contact_forces'
        settings.contact_forces_visible = value
      when 'bodies'
        settings.bodies_visible = value
      end
    when 'body', 'internal_body'
      if @selected_body && @selected_body.valid?
        @selected_body.set_attribute('MSPhysics Body', option, value)
      end
    when 'editor'
      if attr == 'print_margin'
        @editor_print_margin = value
      elsif attr == 'read_only'
        @editor_read_only = value
      end
    when 'dialog'
      if attr == 'help_box'
        @dialog_help_box = value
      end
    when 'joint', *MSPhysics::JOINT_FILE_NAMES
      if @selected_joint && @selected_joint.valid?
        if dict == 'fixed' && attr =~ /adjust_to/i
          mode = attr.split(/\-/, 2)[1]
          ctype = (mode == 'none' ? 0 : (mode == 'child' ? 1 : 2))
          @selected_joint.set_attribute('MSPhysics Joint', 'Adjust To', ctype)
        else
          @selected_joint.set_attribute('MSPhysics Joint', option, value)
        end
      end
    end
  }

  @dialog.add_action_callback('button_clicked') { |acs, params|
    case params
    when 'sound-add'
      path = ::UI.openpanel('Add Sound File', @default_sound_path)
      if path
        path.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18
        @default_sound_path = path
        begin
          add_sound(path)
          update_sound_state
        rescue TypeError => err
          err_message = err.message
          err_message.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18
          ::UI.messagebox(err_message)
        end
      end
    when 'sound-remove'
      if @selected_sound
        remove_sound(@selected_sound)
        @selected_sound = nil
        update_sound_state
      end
    when 'sound-remove_all'
      dict = Sketchup.active_model.attribute_dictionary('MSPhysics Sounds', false)
      num_sounds = dict ? dict.length : 0
      if num_sounds < 2 || ::UI.messagebox('Are you sure you want to remove all sounds?', MB_YESNO) == IDYES
        remove_all_sounds
        @selected_sound = nil
        update_sound_state
      end
    when 'sound-play'
      if @selected_sound
        music = MSPhysics::Music.get_by_name(@selected_sound)
        unless music
          begin
            buf = Sketchup.active_model.get_attribute('MSPhysics Sounds', @selected_sound).pack('l*')
            music = MSPhysics::Music.create_from_buffer(buf, buf.size)
            buf = nil
            MSPhysics::Music.set_name(music, @selected_sound)
          rescue Exception => err
            ::UI.messagebox("Can't play selected sound, \"#{@selected_sound}\", as it seems to be invalid!")
          end
        end
        MSPhysics::Music.play(music, 0) if music
      end
    when 'sound-toggle_pause'
      if MSPhysics::Music.is_paused?
        MSPhysics::Music.resume
      else
        MSPhysics::Music.pause
      end
    when 'sound-stop'
      MSPhysics::Music.stop
    when 'motor-generate_slider'
      if @selected_joint && @selected_joint.valid?
        jdict = 'MSPhysics Joint'
        name = @selected_joint.name.to_s
        name = 'Motor-' + @selected_joint.get_attribute(jdict, 'ID').to_s if name.empty?
        controller = "slider(#{name.inspect}, 0.0, -1.0, 1.0)"
        @selected_joint.set_attribute(jdict, 'Controller', controller)
        execute_js("$('#motor-controller').val(#{controller.inspect});")
      end
    when 'servo-generate_slider'
      if @selected_joint && @selected_joint.valid?
        jdict = 'MSPhysics Joint'
        attr = @selected_joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS)
        ang_ratio = MSPhysics::ANGLE_CONVERSION[attr]
        ang_ratio = 1.0 unless ang_ratio
        iang_ratio = 1.0 / ang_ratio
        name = @selected_joint.name.to_s
        name = 'Servo-' + @selected_joint.get_attribute(jdict, 'ID').to_s if name.empty?
        min = @selected_joint.get_attribute(jdict, 'Min', fix_numeric_value(MSPhysics::Servo::DEFAULT_MIN * iang_ratio)).to_f
        max = @selected_joint.get_attribute(jdict, 'Max', fix_numeric_value(MSPhysics::Servo::DEFAULT_MAX * iang_ratio)).to_f
        controller = "slider(#{name.inspect}, 0.0, #{min}, #{max})"
        @selected_joint.set_attribute(jdict, 'Controller', controller)
        execute_js("$('#servo-controller').val(#{controller.inspect});")
      end
    when 'piston-generate_slider'
      if @selected_joint && @selected_joint.valid?
        jdict = 'MSPhysics Joint'
        attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS)
        pos_ratio = MSPhysics::POSITION_CONVERSION[attr]
        pos_ratio = 1.0 unless pos_ratio
        ipos_ratio = 1.0 / pos_ratio
        name = @selected_joint.name.to_s
        name = 'Piston-' + @selected_joint.get_attribute(jdict, 'ID').to_s if name.empty?
        if @selected_joint.get_attribute(jdict, 'Controller Mode', MSPhysics::Piston::DEFAULT_CONTROLLER_MODE).to_i == 0
          min = @selected_joint.get_attribute(jdict, 'Min', fix_numeric_value(MSPhysics::Piston::DEFAULT_MIN * ipos_ratio)).to_f
          max = @selected_joint.get_attribute(jdict, 'Max', fix_numeric_value(MSPhysics::Piston::DEFAULT_MAX * ipos_ratio)).to_f
          controller = "slider(#{name.inspect}, 0.0, #{min}, #{max})"
          @selected_joint.set_attribute(jdict, 'Controller', controller)
          execute_js("$('#piston-controller').val(#{controller.inspect});")
        else
          controller = "slider(#{name.inspect}, 0.0, -1.0, 1.0)"
          @selected_joint.set_attribute(jdict, 'Controller', controller)
          execute_js("$('#piston-controller').val(#{controller.inspect});")
        end
      end
    when 'curvy_piston-generate_slider'
      if @selected_joint && @selected_joint.valid?
        jdict = 'MSPhysics Joint'
        attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS)
        pos_ratio = MSPhysics::POSITION_CONVERSION[attr]
        pos_ratio = 1.0 unless pos_ratio
        ipos_ratio = 1.0 / pos_ratio
        name = @selected_joint.name.to_s
        name = 'CurvyPiston-' + @selected_joint.get_attribute(jdict, 'ID').to_s if name.empty?
        if @selected_joint.get_attribute(jdict, 'Controller Mode', MSPhysics::CurvyPiston::DEFAULT_CONTROLLER_MODE).to_i == 0
          loop = @selected_joint.get_attribute(jdict, 'Enable Loop', MSPhysics::CurvyPiston::DEFAULT_LOOP_ENABLED)
          min = 0.0
          max = MSPhysics::JointConnectionTool.get_curve_length(@selected_joint, nil, loop).to_m * ipos_ratio
          controller = "slider(#{name.inspect}, 0.0, #{min}, #{ sprintf("%0.3f", max) })"
          @selected_joint.set_attribute(jdict, 'Controller', controller)
          execute_js("$('#curvy_piston-controller').val(#{controller.inspect});")
        else
          controller = "slider(#{name.inspect}, 0.0, -1.0, 1.0)"
          @selected_joint.set_attribute(jdict, 'Controller', controller)
          execute_js("$('#curvy_piston-controller').val(#{controller.inspect});")
        end
      end
    when 'body-assign_props_to_all'
      if @selected_body && @selected_body.valid? && (@selected_body.name.size > 0 || ::UI.messagebox("This body is unnamed. Would you like to assign identical properties to all the unnamed bodies?", MB_YESNO) == IDYES)
        execute_js("if (document.activeElement instanceof HTMLInputElement) document.activeElement.blur();")
        dict = @selected_body.attribute_dictionary('MSPhysics Body')
        if dict
          props = MSPhysics::BODY_STATES - ['Body Script'] + ['Shape', 'Shape Dir', 'Type', 'Material', 'Mass Control', 'Magnet Mode', 'Density', 'Mass', 'Static Friction', 'Kinetic Friction', 'Elasticity', 'Softness', 'Magnet Force', 'Magnet Range', 'Magnet Strength', 'Linear Damping', 'Angular Damping', 'Emitter Rate', 'Emitter Delay', 'Emitter Lifetime', 'Thruster Controller', 'Emitter Controller']
          model = Sketchup.active_model
          op = 'MSPhysics Body - Assign Properties to All'
          Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op)
          model.definitions.each { |cd|
            cd.instances.each { |inst|
              next if inst == @selected_body || inst.get_attribute('MSPhysics', 'Type', 'Body') != 'Body' || inst.name != @selected_body.name
              props.each { |prop|
                value = dict[prop]
                if value.nil?
                  inst.delete_attribute('MSPhysics Body', prop)
                else
                  inst.set_attribute('MSPhysics Body', prop, value)
                end
              }
            }
          }
          model.commit_operation
        end
      end
    when 'body-assign_script_to_all'
      if @selected_body && @selected_body.valid? && (@selected_body.name.size > 0 || ::UI.messagebox("This body is unnamed. Would you like to assign identical script to all the unnamed bodies?", MB_YESNO) == IDYES)
        execute_js("if (document.activeElement instanceof HTMLInputElement) document.activeElement.blur();")
        dict = @selected_body.attribute_dictionary('MSPhysics Script')
        script_enabled = @selected_body.get_attribute('MSPhysics Body', 'Enable Script')
        if dict
          props = ['Value', 'Cursor']
          model = Sketchup.active_model
          op = 'MSPhysics Body - Assign Script to All'
          Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op)
          model.definitions.each { |cd|
            cd.instances.each { |inst|
              next if inst == @selected_body || inst.get_attribute('MSPhysics', 'Type', 'Body') != 'Body' || inst.name != @selected_body.name
              props.each { |prop|
                if dict[prop].nil?
                  inst.delete_attribute('MSPhysics Script', prop)
                else
                  inst.set_attribute('MSPhysics Script', prop, dict[prop])
                end
              }
              if script_enabled.nil?
                inst.delete_attribute('MSPhysics Body', 'Enable Script')
              else
                inst.set_attribute('MSPhysics Body', 'Enable Script', script_enabled)
              end
            }
          }
          model.commit_operation
        end
      end
    when 'joint-assign_to_all'
      if @selected_joint && @selected_joint.valid?
        execute_js("if (document.activeElement instanceof HTMLInputElement) document.activeElement.blur();")
        dict = @selected_joint.attribute_dictionary('MSPhysics Joint')
        name = @selected_joint.name
        name = dict['ID'].to_s if name.empty?
        type = dict['Type']
        if dict && name.size > 0 && type
          model = Sketchup.active_model
          op = 'MSPhysics Joint - Assign to All'
          Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op)
          msgbox_displayed = false
          change_controllers = false
          model.definitions.each { |cd|
            cd.instances.each { |inst|
              next if inst == @selected_joint || inst.get_attribute('MSPhysics', 'Type', 'Body') != 'Joint' || inst.get_attribute('MSPhysics Joint', 'Type') != type
              inst_name = inst.name.empty? ? inst.get_attribute('MSPhysics Joint', 'ID').to_s : inst.name
              next if inst_name != name
              dict.each { |key, value|
                next if key == 'ID' || key == 'Type'
                if key == 'Controller'
                  if !msgbox_displayed
                    change_controllers = ::UI.messagebox("Should the controllers be changed as well?", MB_YESNO) == IDYES
                    msgbox_displayed = true
                  end
                  inst.set_attribute('MSPhysics Joint', key, value) if change_controllers
                elsif value.nil?
                  inst.delete_attribute('MSPhysics Joint', key)
                else
                  inst.set_attribute('MSPhysics Joint', key, value)
                end
              }
            }
          }
          model.commit_operation
        end
      end
    end
  }

  @dialog.add_action_callback('numeric_input_changed') { |acs, params|
    id, value = eval(params)
    dict, attr = id.split(/\-/, 2)
    words = attr.split(/\_/)
    for i in 0...words.size
      words[i].capitalize!
    end
    option = words.join(' ')
    case dict
    when 'simulation'
      case attr
      when 'gravity'
        MSPhysics::Settings.gravity = value
        value = MSPhysics::Settings.gravity
      when 'material_thickness'
        value = AMS.clamp(value, 0.0, 1.0)
        MSPhysics::Settings.material_thickness = value / 32.0
      when 'animate_scenes_delay'
        MSPhysics::Settings.animate_scenes_delay = value
        value = MSPhysics::Settings.animate_scenes_delay
      end
    when 'body'
      if @selected_body && @selected_body.valid?
        method = "#{attr}="
        if @material.respond_to?(method)
          value = @material.method(method).call(value)
          if value != @activated_value
            execute_js("$('#body-material').val('Custom'); $('#body-material').trigger('chosen:updated');")
            @selected_body.set_attribute('MSPhysics Body', 'Material', 'Custom')
          end
        elsif %w(magnet_range emitter_rate emitter_delay emitter_lifetime).include?(attr)
          value = AMS.clamp(value, 0.0, nil)
        elsif attr == 'linear_damping' || attr == 'angular_damping'
          value = AMS.clamp(value, 0.0, 1.0)
        end
        @selected_body.set_attribute('MSPhysics Body', option, value.to_i.is_a?(Bignum) ? value.to_s : value)
      end
    when 'joint', *MSPhysics::JOINT_FILE_NAMES
      if @selected_joint && @selected_joint.valid?
        if %w(stiffness reduction_ratio strength).include?(attr) || %(hinge-damp spring-damp).include?(id)
          value = AMS.clamp(value, 0.0, 1.0)
        elsif %w(accel damp breaking_force rate power alignment_power friction linear_friction angular_friction).include?(attr)
          value = AMS.clamp(value, 0.0, nil)
        end
        @selected_joint.set_attribute('MSPhysics Joint', option, value.to_i.is_a?(Bignum) ? value.to_s : value)
      end
    when 'gear'
      if @selected_joint && @selected_joint.valid?
        joint = @geared_joints[attr]
        if joint && joint.valid?
          gear_type = attr.split(/\_/).first.to_i
          MSPhysics::JointConnectionTool.set_gear_ratio(@selected_joint, joint, gear_type, value)
        end
      end
    end
    execute_js("$('##{id}').val('#{ format_value(value, PRECISION) }');")
    @activated_value = nil
  }

  @dialog.add_action_callback('Integer_input_changed') { |acs, params|
    id, value = eval(params)
    dict, attr = id.split(/\-/, 2)
    words = attr.split(/\_/)
    for i in 0...words.size
      words[i].capitalize!
    end
    option = words.join(' ')
    case dict
    when 'simulation'
      if attr == 'update_rate'
        MSPhysics::Settings.update_rate = value
        value = MSPhysics::Settings.update_rate
      end
    when 'body'
      if @selected_body && @selected_body.valid?
        @selected_body.set_attribute('MSPhysics Body', option, value.to_i.is_a?(Bignum) ? value.to_s : value)
      end
    when 'joint', *MSPhysics::JOINT_FILE_NAMES
    end
    execute_js("$('##{id}').val('#{ value.to_i }')")
  }

  @dialog.add_action_callback('numeric_input_focused') { |acs, params|
    dict, attr = params.split(/\-/, 2)
    words = attr.split(/\_/)
    for i in 0...words.size
      words[i].capitalize!
    end
    option = words.join(' ')
    value = case dict
    when 'simulation'
      case attr
      when 'gravity'
        MSPhysics::Settings.gravity
      when 'material_thickness'
        MSPhysics::Settings.material_thickness * 32.0
      end
    when 'body'
      if @selected_body && @selected_body.valid?
        default = MSPhysics::DEFAULT_BODY_SETTINGS
        @selected_body.get_attribute('MSPhysics Body', option, default[attr.to_sym])
      end
    when 'joint', *MSPhysics::JOINT_FILE_NAMES
      if @selected_joint && @selected_joint.valid?
        begin
          #default = eval("MSPhysics::#{dict.split(/\_/).map { |w| w.capitalize }.join}::DEFAULT_#{attr.upcase}")
          default = get_joint_default_value(@selected_joint, option)
        rescue Exception => err
          default = 0
        end
        @selected_joint.get_attribute('MSPhysics Joint', option, default)
      end
    when 'gear'
      if @selected_joint && @selected_joint.valid?
        joint = @geared_joints[attr]
        if joint && joint.valid?
          gear_type = attr.split(/\_/).first.to_i
          MSPhysics::JointConnectionTool.get_gear_ratio(@selected_joint, joint, gear_type)
        end
      end
    end
    if value.is_a?(Numeric)
      execute_js("$('##{params}').val(#{value});")
      @activated_value = value
    end
  }

  @dialog.add_action_callback('slider_input_changed') { |acs, params|
    id, value = eval(params)
    dict, attr = id.split(/\-/, 2)
    case dict
      when 'simulation'
        case attr
          when 'key_nav_velocity'
            MSPhysics::Settings.key_nav_velocity = value
          when 'key_nav_omega'
            MSPhysics::Settings.key_nav_omega = value
          when 'key_nav_atime'
            MSPhysics::Settings.key_nav_atime = value
        end
    end
    execute_js("$('##{id}').val('#{value}');")
  }

  @dialog.add_action_callback('controller_input_changed') { |acs, params|
    id = USE_HTML_DIALOG ? params[0] : params
    dict, attr = id.split(/\-/, 2)
    words = attr.split(/\_/)
    for i in 0...words.size
      words[i].capitalize!
    end
    option = words.join(' ')
    case dict
    when 'simulation'
    when 'body'
      if @selected_body && @selected_body.valid?
        code = USE_HTML_DIALOG ? params[1] : @dialog.get_element_value(id)
        @selected_body.set_attribute('MSPhysics Body', option, code)
      end
    when 'joint', *MSPhysics::JOINT_FILE_NAMES
      if @selected_joint && @selected_joint.valid?
        code = USE_HTML_DIALOG ? params[1] : @dialog.get_element_value(id)
        @selected_joint.set_attribute('MSPhysics Joint', option, code)
      end
    end
  }

  @dialog.add_action_callback('text_input_changed') { |acs, params|
    id = USE_HTML_DIALOG ? params[0] : params
    dict, attr = id.split(/\-/, 2)
    words = attr.split(/\_/)
    for i in 0...words.size
      words[i].capitalize!
    end
    option = words.join(' ')
    case dict
    when 'body'
      if @selected_body && @selected_body.valid?
        code = USE_HTML_DIALOG ? params[1] : @dialog.get_element_value(id)
        if attr == 'name'
          @selected_body.name = code
        end
      end
    when 'joint'
      if @selected_joint && @selected_joint.valid?
        code = USE_HTML_DIALOG ? params[1] : @dialog.get_element_value(id)
        if attr == 'name'
          @selected_joint.name = code
        else
          @selected_joint.set_attribute('MSPhysics Joint', option, code)
        end
      end
    end
  }

  @dialog.add_action_callback('select_input_changed') { |acs, params|
    id, value = eval(params)
    dict, attr = id.split(/\-/, 2)
    words = attr.split(/\_/)
    for i in 0...words.size
      words[i].capitalize!
    end
    option = words.join(' ')
    case dict
    when 'dialog'
      case attr
      when 'scale'
        @dialog_scale = value.to_f
      end
    when 'simulation'
      case attr
      when 'update_timestep'
        MSPhysics::Settings.update_timestep = 1.0 / value.to_i
      when 'solver_model'
        MSPhysics::Settings.solver_model = value.to_i
      when 'joint_algorithm'
        MSPhysics::Settings.joint_algorithm = value.to_i
      when 'animate_scenes_state'
        MSPhysics::Settings.animate_scenes_state = value.to_i
      when 'key_nav_state'
        MSPhysics::Settings.key_nav_state = value.to_i
      end
    when 'body'
      if @selected_body && @selected_body.valid?
        model = Sketchup.active_model
        if attr == 'material'
          op = 'MSPhysics Body - Change Material'
          Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op)
          @selected_body.set_attribute('MSPhysics Body', option, value)
          if value == MSPhysics::DEFAULT_BODY_SETTINGS[:material_name]
            ['Material', 'Density', 'Static Friction', 'Kinetic Friction', 'Enable Friction', 'Elasticity', 'Softness'].each { |opt|
              @selected_body.delete_attribute('MSPhysics Body', opt)
            }
          else
            material = MSPhysics::Materials.material_by_name(value)
            if material
              @selected_body.set_attribute('MSPhysics Body', 'Density', material.density)
              @selected_body.set_attribute('MSPhysics Body', 'Static Friction', material.static_friction)
              @selected_body.set_attribute('MSPhysics Body', 'Kinetic Friction', material.kinetic_friction)
              @selected_body.set_attribute('MSPhysics Body', 'Enable Friction', true)
              @selected_body.set_attribute('MSPhysics Body', 'Elasticity', material.elasticity)
              @selected_body.set_attribute('MSPhysics Body', 'Softness', material.softness)
            end
          end
          update_state
          model.commit_operation
        elsif %w(type magnet_mode mass_control shape shape_dir).include?(attr)
          @selected_body.set_attribute('MSPhysics Body', option, value.to_i)
        else
          @selected_body.set_attribute('MSPhysics Body', option, value)
        end
      end
    when 'editor'
      if attr == 'theme'
        @editor_theme = value.to_s
      elsif attr == 'font'
        @editor_font = value.to_i
      elsif attr == 'wrap'
        @editor_wrap = value.to_s
      end
    when 'joint', *MSPhysics::JOINT_FILE_NAMES
      if @selected_joint && @selected_joint.valid?
        if attr == 'mode'
          value = value.to_i
        end
        @selected_joint.set_attribute('MSPhysics Joint', option, value)
      end
    end
  }

  @dialog.add_action_callback('slider_changed') { |acs, params|
    id, value = eval(params)
    dict, attr = id.split(/\-/, 2)
    case dict
      when 'simulation'
        case attr
          when 'key_nav_velocity'
            MSPhysics::Settings.key_nav_velocity = value
          when 'key_nav_omega'
            MSPhysics::Settings.key_nav_omega = value
          when 'key_nav_atime'
            MSPhysics::Settings.key_nav_atime = value
        end
    end
  }

  @dialog.add_action_callback('placement_changed') { |acs, params|
    tab, dw, dh, bresize = eval(params)
    last_tab = @active_tab
    @active_tab = tab
    @last_active_body_tab = tab if tab == 2 || tab == 3
    next unless bresize
    update_dialog_style
    wsx = nil
    wsy = nil
    ui_scale = Sketchup.version.to_i > 16 ? ::UI.scale_factor : 1.0
    if tab == 3 && @selected_body && @selected_body.valid? && @selected_body.parent.is_a?(Sketchup::Model)
      wsx = @border_size.x + @editor_size.x * @dialog_scale * ui_scale
      wsy = @border_size.y + @editor_size.y * @dialog_scale * ui_scale
    else
      wsx = @border_size.x + dw * @dialog_scale * ui_scale
      wsy = @border_size.y + dh * @dialog_scale * ui_scale
    end
    if wsx && wsy
      if AMS::IS_PLATFORM_WINDOWS && @handle
        AMS::Window.set_size(@handle, wsx.round, wsy.round, false)
      else
        @dialog.set_size(wsx.round, wsy.round)
      end
    end
    update_simulation_sliders if tab == 1
  }

  @dialog.add_action_callback('editor_size_changed') { |acs, params|
    if @selected_body && @selected_body.valid? && @selected_body.parent.is_a?(Sketchup::Model)
      if !AMS::IS_PLATFORM_WINDOWS || !@handle || AMS::Window.is_restored?(@handle)
        cw, ch = eval(params)
        @editor_size.x = cw
        @editor_size.y = ch
      end
    end
  }

  @dialog.add_action_callback('mouse_enter') { |acs, params|
    update_simulation_state
  }

  @dialog.add_action_callback('sound_select_changed') { |acs, params|
    @selected_sound = params
    cmd = ''
    ext = Sketchup.active_model.get_attribute('MSPhysics Sound Types', @selected_sound)
    if MSPhysics::EMBEDDED_MUSIC_FORMATS.include?(ext)
      cmd << "$('#sound-command_music').val('simulation.play_music(#{@selected_sound.inspect})');"
    else
      cmd << "$('#sound-command_music').val('Not Supported');"
    end
    if MSPhysics::EMBEDDED_SOUND_FORMATS.include?(ext)
      cmd << "$('#sound-command_sound').val('simulation.play_sound(#{@selected_sound.inspect})');"
    else
      cmd << "$('#sound-command_sound').val('Not Supported');"
    end
    execute_js(cmd)
  }

  @dialog.add_action_callback('joint_label_selected') { |acs, params|
    if (params =~ /Internal::/) == 0
      fid = params.split('Internal::', 2)[1]
      jdata = @body_internal_joints[fid]
      if jdata && jdata[0] && jdata[0].valid?
        @selected_joint = jdata[0]
        @app_observer.selection_observer_active = false
        sel = Sketchup.active_model.selection
        sel.clear
        sel.add(@selected_body) if @selected_body && @selected_body.valid?
        sel.add(@selected_joint)
        @app_observer.selection_observer_active = true
        update_joint_state
        execute_js("setTimeout(function() { update_placement(4, true); }, 200);")
      end
    elsif (params =~ /Connected::/) == 0
      fid = params.split('Connected::', 2)[1]
      jdata = @body_connected_joints[fid]
      if jdata && jdata[0] && jdata[0].valid?
        @selected_joint = jdata[0]
        @app_observer.selection_observer_active = false
        sel = Sketchup.active_model.selection
        sel.clear
        sel.add(@selected_body) if @selected_body && @selected_body.valid?
        sel.add(@selected_joint)
        @app_observer.selection_observer_active = true
        update_joint_state
        execute_js("setTimeout(function() { update_placement(4, true); }, 200);")
      end
    elsif (params =~ /Geared::/) == 0
      fid = params.split('Geared::', 2)[1]
      joint = @geared_joints[fid]
      if joint && joint.valid?
        @selected_joint = joint
        @app_observer.selection_observer_active = false
        sel = Sketchup.active_model.selection
        sel.clear
        sel.add(@selected_body) if @selected_body && @selected_body.valid?
        sel.add(@selected_joint)
        @app_observer.selection_observer_active = true
        update_joint_state
        execute_js("setTimeout(function() { update_placement(4, true); }, 200);")
      end
    end
  }

  # Set content
  dir = File.dirname(__FILE__)
  dir.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18
  url = File.join(dir, 'html/dialog.html')
  @dialog.set_file(url)

  # Show dialog
  if AMS::IS_PLATFORM_WINDOWS || USE_HTML_DIALOG
    @dialog.show
  else
    @dialog.show_modal
  end

  # Assign the on_close callback. Important: This must be called after
  # showing dialog in order to work on Mac OS X.
  do_on_close = Proc.new {
    execute_js("update_editor_size(); blur_input();")

    @dialog = nil
    @handle = nil
    @init_called = false
    @selected_body = nil
    @selected_joint = nil
    @active_tab = 1
    @activated_value = nil
    @selected_sound = nil
    @app_observer.selection_observer_active = false

    true
  }
  if USE_HTML_DIALOG
    @dialog.set_can_close() { do_on_close.call }
  else
    @dialog.set_on_close() { do_on_close.call }
  end

  # Find dialog window handle
  @handle = AMS::IS_PLATFORM_WINDOWS ? AMS::Sketchup.find_window_by_caption(TITLE) : nil
  AMS::Sketchup.ignore_dialog(@handle) if @handle

  # Set dialog style
  update_dialog_style
end

.open?Boolean

Determine whether UI is open.

Returns:

  • (Boolean)

Since:

  • 1.0.0



1858
1859
1860
# File 'RubyExtension/MSPhysics/dialog.rb', line 1858

def open?
  @dialog ? true : false
end

.remove_all_soundsObject

Remove all sounds from UI.

Since:

  • 1.0.0



1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
# File 'RubyExtension/MSPhysics/dialog.rb', line 1929

def remove_all_sounds
  dict = Sketchup.active_model.attribute_dictionary('MSPhysics Sounds', false)
  if dict
    dict.each_key { |name|
      music = MSPhysics::Music.get_by_name(name)
      MSPhysics::Music.destroy(music) if music
    }
  end
  Sketchup.active_model.attribute_dictionaries.delete('MSPhysics Sounds')
  Sketchup.active_model.attribute_dictionaries.delete('MSPhysics Sound Types')
end

.remove_sound(name) ⇒ Object

Remove sound from UI.

Parameters:

  • name (String)

Since:

  • 1.0.0



1919
1920
1921
1922
1923
1924
1925
1926
# File 'RubyExtension/MSPhysics/dialog.rb', line 1919

def remove_sound(name)
  music = MSPhysics::Music.get_by_name(name)
  MSPhysics::Music.destroy(music) if music
  dict1 = Sketchup.active_model.attribute_dictionary('MSPhysics Sounds', false)
  dict1.delete_key(name.to_s) if dict1
  dict2 = Sketchup.active_model.attribute_dictionary('MSPhysics Sound Types', false)
  dict2.delete_key(name.to_s) if dict2
end

.save_editor_settingsObject

Save editor settings into registry.

Since:

  • 1.0.0



1966
1967
1968
1969
1970
1971
1972
1973
1974
# File 'RubyExtension/MSPhysics/dialog.rb', line 1966

def save_editor_settings
  Sketchup.write_default('MSPhysics', 'Editor Theme', @editor_theme.to_s)
  Sketchup.write_default('MSPhysics', 'Editor Font', @editor_font.to_i)
  Sketchup.write_default('MSPhysics', 'Editor Wrap', @editor_wrap.to_s)
  Sketchup.write_default('MSPhysics', 'Editor Print Margin', @editor_print_margin)
  Sketchup.write_default('MSPhysics', 'Editor Size', @editor_size.inspect)
  Sketchup.write_default('MSPhysics', 'Dialog Help Box', @dialog_help_box)
  Sketchup.write_default('MSPhysics', 'Dialog Scale', @dialog_scale)
end

.update_body_statevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Update UI properties tab.

Since:

  • 1.0.0



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'RubyExtension/MSPhysics/dialog.rb', line 139

def update_body_state
  return if @dialog.nil? || !@init_called
  model = Sketchup.active_model
  return unless model
  bodies = []
  model.selection.each { |ent|
    next unless ent.is_a?(Sketchup::Group) || ent.is_a?(Sketchup::ComponentInstance)
    bodies << ent if ent.get_attribute('MSPhysics', 'Type', 'Body') == 'Body'
  }
  cmd = ""
  @body_internal_joints.clear
  @body_connected_joints.clear
  cmd << "$('#body-internal_joints_table').empty();"
  cmd << "$('#body-connected_joints_table').empty();"
  if bodies.size == 1
    @selected_body = bodies[0]
    # Top level entities have access to the full body properties.
    # Only top level entities may contain scripts.
    # Child entities have access to Ignore state only.
    default = MSPhysics::DEFAULT_BODY_SETTINGS
    if model.active_entities == model.entities
      # Display tabs
      cmd << "$('#tab2-none').css('display', 'none');"
      cmd << "$('#tab2-content1').css('display', 'block');"
      cmd << "$('#tab2-content2').css('display', 'none');"
      cmd << "$('#tab3-none').css('display', 'none');"
      cmd << "$('#tab3-content').css('display', 'block');"
      # Display script
      script = @selected_body.get_attribute('MSPhysics Script', 'Value', '').inspect
      cmd << "editor_set_script(#{script});"
      cursor = nil
      begin
        cursor = eval(@selected_body.get_attribute('MSPhysics Script', 'Cursor', '[1,0]'))
      rescue Exception => err
        cursor = [1,0]
      end
      cmd << "editor_set_cursor(#{cursor.x}, #{cursor.y});"
      cmd << "window.aceEditor.setTheme('ace/theme/#{@editor_theme}');"
      cmd << "document.getElementById('editor').style.fontSize='#{@editor_font}px';"
      cmd << "window.aceEditor.setOption('wrap', '#{@editor_wrap}');"
      cmd << "window.aceEditor.setShowPrintMargin(#{@editor_print_margin});"
      cmd << "window.aceEditor.setReadOnly(#{@editor_read_only});"
      cmd << "$('#editor-theme').val('#{@editor_theme}');"
      cmd << "$('#editor-theme').trigger('chosen:updated');"
      cmd << "$('#editor-font').val('#{@editor_font}');"
      cmd << "$('#editor-font').trigger('chosen:updated');"
      cmd << "$('#editor-wrap').val('#{@editor_wrap}');"
      cmd << "$('#editor-wrap').trigger('chosen:updated');"
      cmd << "$('#editor-print_margin').prop('checked', #{ @editor_print_margin });"
      cmd << "$('#editor-read_only').prop('checked', #{ @editor_read_only });"
      # Display entity id and index
      cmd << "$('#body-entity_id').val('#{ @selected_body.entityID }');"
      cmd << "$('#body-entity_index').val('#{ model.entities.to_a.index(@selected_body) }');"
      # Display Controllers
      ['Thruster Controller', 'Emitter Controller'].each { |option|
        property = option.downcase.gsub(/\s/, '_')
        script = @selected_body.get_attribute('MSPhysics Body', option)
        script = '0.0' if script.nil?
        cmd << "$('#body-#{ property }').val(#{script.inspect});"
      }
      # Display type
      type = @selected_body.get_attribute('MSPhysics Body', 'Type', default[:type]).to_i
      cmd << "$('#body-type').val('#{type}');"
      cmd << "$('#body-type').trigger('chosen:updated');"
      # Display shape
      shape_id = @selected_body.get_attribute('MSPhysics Body', 'Shape', default[:shape_id])
      if shape_id.is_a?(String)
        MSPhysics::SHAPES.each { |k, v|
          if shape_id == v
            shape_id = k
            break
          end
        }
        shape_id = default[:shape_id] if shape_id.is_a?(String)
      end
      cmd << "$('#body-shape').val('#{shape_id}');"
      cmd << "$('#body-shape').trigger('chosen:updated');"
      # Display shape up direction
      shape_dir = @selected_body.get_attribute('MSPhysics Body', 'Shape Dir', default[:shape_dir]).to_i
      cmd << "$('#body-shape_dir').val('#{shape_dir}');"
      cmd << "$('#body-shape_dir').trigger('chosen:updated');"
      # Display material
      cmd << "$('#body-material').empty();"
      cmd << "$('#body-material').append('<option value=\"#{default[:material_name]}\">#{default[:material_name]}</option>');"
      cmd << "$('#body-material').append('<option value=\"Custom\">Custom</option>');"
      materials = MSPhysics::Materials.sort { |a, b| a.name <=> b.name }
      materials.each { |material|
        cmd << "$('#body-material').append('<option value=\"#{material.name}\">#{material.name}</option>');"
      }
      material = @selected_body.get_attribute('MSPhysics Body', 'Material', default[:material_name]).to_s
      cmd << "$('#body-material').val('#{material}');"
      cmd << "$('#body-material').trigger('chosen:updated');"
      # Display state and other check-box properties
      MSPhysics::BODY_STATES.each { |option|
        property = option.downcase.gsub(/\s/, '_')
        default_state = default[property.to_sym]
        state = @selected_body.get_attribute('MSPhysics Body', option, default_state) ? true : false
        cmd << "$('#body-#{ property }').prop('checked', #{ state });"
      }
      # Display name
      cmd << "$('#body-name').val(#{@selected_body.name.inspect});"
      # Display numeric properties
      ['Density', 'Mass', 'Static Friction', 'Kinetic Friction', 'Elasticity', 'Softness', 'Magnet Force', 'Magnet Range', 'Magnet Strength', 'Linear Damping', 'Angular Damping', 'Emitter Rate', 'Emitter Delay', 'Emitter Lifetime'].each { |option|
        property = option.downcase.gsub(/\s/, '_')
        attr = @selected_body.get_attribute('MSPhysics Body', option)
        if attr.is_a?(String)
          attr = attr.to_f
        elsif !attr.is_a?(Numeric)
          attr = default[property.to_sym]
        end
        cmd << "$('#body-#{ property }').val('#{ format_value(attr, PRECISION) }');"
      }
      # Display mass control
      mass_control = @selected_body.get_attribute('MSPhysics Body', 'Mass Control', default[:mass_control]).to_i
      cmd << "$('#body-mass_control').val('#{mass_control}');"
      cmd << "$('#body-mass_control').trigger('chosen:updated');"
      if mass_control == 2
        cmd << "$('#body-control_by_density').css('display', 'none');"
        cmd << "$('#body-control_by_mass').css('display', 'table-row');"
      else
        cmd << "$('#body-control_by_density').css('display', 'table-row');"
        cmd << "$('#body-control_by_mass').css('display', 'none');"
      end
      # Display magnet mode
      magnet_mode = @selected_body.get_attribute('MSPhysics Body', 'Magnet Mode', default[:magnet_mode]).to_i
      cmd << "$('#body-magnet_mode').val('#{magnet_mode}');"
      cmd << "$('#body-magnet_mode').trigger('chosen:updated');"
      if magnet_mode == 2
        cmd << "$('#body-magnet_mode1a').css('display', 'none');"
        cmd << "$('#body-magnet_mode1b').css('display', 'none');"
        cmd << "$('#body-magnet_mode2').css('display', 'table-row');"
      else
        cmd << "$('#body-magnet_mode1a').css('display', 'table-row');"
        cmd << "$('#body-magnet_mode1b').css('display', 'table-row');"
        cmd << "$('#body-magnet_mode2').css('display', 'none');"
      end
      # Display internal joints
      identical_joints = {}
      AMS::Group.get_entities(@selected_body).each { |e|
        if (e.is_a?(Sketchup::ComponentInstance) || e.is_a?(Sketchup::Group)) && e.get_attribute('MSPhysics', 'Type', 'Body') == 'Joint'
          jtype = e.get_attribute('MSPhysics Joint', 'Type')
          jid = e.get_attribute('MSPhysics Joint', 'ID')
          jname = e.name.to_s
          jname = jid.to_s if jname.empty?
          fname = jtype + '-' + jname
          fid = jtype + '-' + jid.to_s
          if @body_internal_joints[fid]
            if identical_joints[fid]
              identical_joints[fid] += 1
            else
              identical_joints[fid] = 1
            end
            fid2 = fid + '-' + identical_joints[fid].to_s
            fname2 = fname + ' (' + identical_joints[fid].to_s + ')'
            @body_internal_joints[fid2] = [e, fname2]
          else
            @body_internal_joints[fid] = [e, fname]
          end
        end
      }
      if @body_internal_joints.empty?
        cmd << "$('#body-internal_joints_div').css('display', 'none');"
      else
        cmd << "$('#body-internal_joints_div').css('display', 'block');"
        cmd << "$('#body-internal_joints_table').append(\""
        count = 0
        cmd << "<tr>"
        @body_internal_joints.keys.sort.each { |fid|
          ent, fname = @body_internal_joints[fid]
          if count == 3
            cmd << "</tr><tr>"
            count = 0
          end
          cmd << "<td><label class=\\\"joint-label#{ent == @selected_joint ? "-selected" : ""}\\\" id=\\\"Internal::#{fid}\\\">#{fname.inspect[1...-1]}</label></td>"
          count += 1
        }
        cmd << "</tr>"
        cmd << "\");"
      end
      identical_joints.clear
      # Display connected joints
      MSPhysics::JointConnectionTool.get_connected_joints(@selected_body).each { |joint, jtra, jparent|
        jtype = joint.get_attribute('MSPhysics Joint', 'Type')
        jid = joint.get_attribute('MSPhysics Joint', 'ID')
        jname = joint.name.to_s
        jname = jid.to_s if jname.empty?
        fname = jtype + '-' + jname
        fid = jtype + '-' + jid.to_s
        if @body_connected_joints[fid]
          if identical_joints[fid]
            identical_joints[fid] += 1
          else
            identical_joints[fid] = 1
          end
          fid2 = fid + '-' + identical_joints[fid].to_s
          fname2 = fname + ' (' + identical_joints[fid].to_s + ')'
          @body_connected_joints[fid2] = [joint, fname2]
        else
          @body_connected_joints[fid] = [joint, fname]
        end
      }
      if @body_connected_joints.empty?
        cmd << "$('#body-connected_joints_div').css('display', 'none');"
      else
        cmd << "$('#body-connected_joints_div').css('display', 'block');"
        cmd << "$('#body-connected_joints_table').append(\""
        count = 0
        cmd << "<tr>"
        @body_connected_joints.keys.sort.each { |fid|
          ent, fname = @body_connected_joints[fid]
          if count == 3
            cmd << "</tr><tr>"
            count = 0
          end
          cmd << "<td><label class=\\\"joint-label#{ent == @selected_joint ? "-selected" : ""}\\\" id=\\\"Connected::#{fid}\\\">#{fname.inspect[1...-1]}</label></td>"
          count += 1
        }
        cmd << "</tr>"
        cmd << "\");"
      end
      identical_joints.clear
      # Assign click events to these joints.
      cmd << "assign_joint_click_event();"
    else
      # Display tabs
      cmd << "$('#tab3-none').css('display', 'block');"
      cmd << "$('#tab3-content').css('display', 'none');"
      cmd << "$('#tab2-none').css('display', 'none');"
      cmd << "$('#tab2-content1').css('display', 'none');"
      cmd << "$('#tab2-content2').css('display', 'block');"
      # Display Ignore state
      state = @selected_body.get_attribute('MSPhysics Body', 'Ignore', nil) ? true : false
      cmd << "$('#internal_body-ignore').prop('checked', #{state});"
    end
    cmd << "update_placement(#{@last_active_body_tab}, false);"
  else
    @selected_body = nil
    cmd << "$('#tab2-none').css('display', 'block');"
    cmd << "$('#tab2-content1').css('display', 'none');"
    cmd << "$('#tab2-content2').css('display', 'none');"
    cmd << "$('#tab3-none').css('display', 'block');"
    cmd << "$('#tab3-content').css('display', 'none');"
  end
  execute_js(cmd)
end

.update_dialog_styleBoolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update dialog style.

Returns:

  • (Boolean)

    success

Since:

  • 1.0.0



70
71
72
73
74
75
76
77
78
79
# File 'RubyExtension/MSPhysics/dialog.rb', line 70

def update_dialog_style
  return false if !AMS::IS_PLATFORM_WINDOWS || @handle.nil?
  style = AMS::Window.get_long(@handle, -16)
  new_style = @active_tab == 3 && @selected_body && @selected_body.valid? && @selected_body.parent.is_a?(Sketchup::Model) ? style | 0x00050000 : style & ~0x01050000
  AMS::Window.lock_update(@handle)
  AMS::Window.set_long(@handle, -16, new_style)
  AMS::Window.lock_update(nil)
  AMS::Window.set_pos(@handle, 0, 0, 0, 0, 0, 0x0237)
  true
end

.update_joint_statevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Update UI joint tab.

Since:

  • 1.0.0



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# File 'RubyExtension/MSPhysics/dialog.rb', line 388

def update_joint_state
  return if @dialog.nil? || !@init_called
  model = Sketchup.active_model
  return unless model
  joints = []
  model.selection.each { |ent|
    next unless ent.is_a?(Sketchup::Group) || ent.is_a?(Sketchup::ComponentInstance)
    joints << ent if ent.get_attribute('MSPhysics', 'Type', 'Body') == 'Joint'
  }
  cmd = ''
  cmd << "$('#tab4-none').css('display', 'block');"
  cmd << "$('#tab4-general').css('display', 'none');"
  cmd << "$('#tab4-fixed').css('display', 'none');"
  cmd << "$('#tab4-hinge').css('display', 'none');"
  cmd << "$('#tab4-motor').css('display', 'none');"
  cmd << "$('#tab4-servo').css('display', 'none');"
  cmd << "$('#tab4-slider').css('display', 'none');"
  cmd << "$('#tab4-piston').css('display', 'none');"
  cmd << "$('#tab4-spring').css('display', 'none');"
  cmd << "$('#tab4-up_vector').css('display', 'none');"
  cmd << "$('#tab4-corkscrew').css('display', 'none');"
  cmd << "$('#tab4-ball_and_socket').css('display', 'none');"
  cmd << "$('#tab4-universal').css('display', 'none');"
  cmd << "$('#tab4-curvy_slider').css('display', 'none');"
  cmd << "$('#tab4-curvy_piston').css('display', 'none');"
  cmd << "$('#tab4-plane').css('display', 'none');"

  @geared_joints.clear
  MSPhysics::JOINT_FILE_NAMES.each { |jname|
    cmd << "$('##{jname}-geared_joints_field').empty();"
    cmd << "$('##{jname}-geared_joints_field').css('display', 'none');"
  }

  if joints.size == 1
    @selected_joint = joints[0]
    jdict = 'MSPhysics Joint'
    attr = @selected_joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS)
    ang_ratio = MSPhysics::ANGLE_CONVERSION[attr]
    ang_ratio = 1.0 unless ang_ratio
    iang_ratio = 1.0 / ang_ratio
    attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS)
    pos_ratio = MSPhysics::POSITION_CONVERSION[attr]
    pos_ratio = 1.0 unless pos_ratio
    ipos_ratio = 1.0 / pos_ratio

    cmd << "$('#tab4-none').css('display', 'none');"
    cmd << "$('#tab4-general').css('display', 'block');"

    attr = @selected_joint.name.to_s
    attr = @selected_joint.get_attribute(jdict, 'ID') if attr.empty?
    unless attr
      attr = JointTool.generate_uniq_id
      @selected_joint.set_attribute('MSPhysics Joint', 'ID', attr)
    end
    cmd << "$('#joint-name').val(#{attr.inspect});"
    attr = @selected_joint.get_attribute(jdict, 'Stiffness', MSPhysics::Joint::DEFAULT_STIFFNESS)
    cmd << "$('#joint-stiffness').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
    attr = @selected_joint.get_attribute(jdict, 'Bodies Collidable', MSPhysics::Joint::DEFAULT_BODIES_COLLIDABLE)
    cmd << "$('#joint-bodies_collidable').prop('checked', #{attr ? true : false});"
    attr = @selected_joint.get_attribute(jdict, 'Breaking Force', MSPhysics::Joint::DEFAULT_BREAKING_FORCE)
    cmd << "$('#joint-breaking_force').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"

    joint_type = @selected_joint.get_attribute(jdict, 'Type')
    joint_type2 = nil
    case joint_type
    when 'Fixed'
      joint_type2 = 'fixed'
      cmd << "$('#tab4-fixed').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Adjust To', 0)
      mode = attr == 2 ? 'parent' : (attr == 1 ? 'child' : 'none')
      cmd << "$('#fixed-adjust_to-#{mode}').prop('checked', true);"
    when 'Hinge'
      joint_type2 = 'hinge'
      cmd << "$('#tab4-hinge').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS).to_s
      cmd << "$('#hinge-angle_units').val('#{attr}');"
      cmd << "$('#hinge-angle_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min', fix_numeric_value(MSPhysics::Hinge::DEFAULT_MIN * iang_ratio))
      cmd << "$('#hinge-min').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max', fix_numeric_value(MSPhysics::Hinge::DEFAULT_MAX * iang_ratio))
      cmd << "$('#hinge-max').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Limits', MSPhysics::Hinge::DEFAULT_LIMITS_ENABLED)
      cmd << "$('#hinge-enable_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Mode', MSPhysics::Hinge::DEFAULT_MODE).to_i
      cmd << "$('#hinge-mode').val('#{attr}');"
      cmd << "$('#hinge-mode').trigger('chosen:updated');"
      if attr == 2
        cmd << "$('.hinge-mode_s0').css('display', 'none');"
        cmd << "$('.hinge-mode_s1').css('display', 'none');"
        cmd << "$('.hinge-mode_s2').css('display', 'table-row');"
        cmd << "$('.hinge-mode_s12').css('display', 'table-row');"
        cmd << "$('#hinge-start_angle').css('display', 'table-row');"
      elsif attr == 1
        cmd << "$('.hinge-mode_s0').css('display', 'none');"
        cmd << "$('.hinge-mode_s1').css('display', 'table-row');"
        cmd << "$('.hinge-mode_s2').css('display', 'none');"
        cmd << "$('.hinge-mode_s12').css('display', 'table-row');"
        cmd << "$('#hinge-start_angle').css('display', 'table-row');"
      else
        cmd << "$('.hinge-mode_s0').css('display', 'table-row');"
        cmd << "$('.hinge-mode_s1').css('display', 'none');"
        cmd << "$('.hinge-mode_s2').css('display', 'none');"
        cmd << "$('.hinge-mode_s12').css('display', 'none');"
        cmd << "$('#hinge-start_angle').css('display', 'none');"
      end
      attr = @selected_joint.get_attribute(jdict, 'Friction', fix_numeric_value(MSPhysics::Hinge::DEFAULT_FRICTION))
      cmd << "$('#hinge-friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Accel', fix_numeric_value(MSPhysics::Hinge::DEFAULT_ACCEL))
      cmd << "$('#hinge-accel').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Damp', fix_numeric_value(MSPhysics::Hinge::DEFAULT_DAMP))
      cmd << "$('#hinge-damp').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Strength', fix_numeric_value(MSPhysics::Hinge::DEFAULT_STRENGTH))
      cmd << "$('#hinge-strength').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Spring Constant', fix_numeric_value(MSPhysics::Hinge::DEFAULT_SPRING_CONSTANT))
      cmd << "$('#hinge-spring_constant').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Spring Drag', fix_numeric_value(MSPhysics::Hinge::DEFAULT_SPRING_DRAG))
      cmd << "$('#hinge-spring_drag').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Start Angle', fix_numeric_value(MSPhysics::Hinge::DEFAULT_START_ANGLE * iang_ratio))
      cmd << "$('#hinge-start_angle').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::Hinge::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#hinge-controller').val(#{attr.inspect});"
    when 'Motor'
      joint_type2 = 'motor'
      cmd << "$('#tab4-motor').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Accel', fix_numeric_value(MSPhysics::Motor::DEFAULT_ACCEL))
      cmd << "$('#motor-accel').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Damp', fix_numeric_value(MSPhysics::Motor::DEFAULT_DAMP))
      cmd << "$('#motor-damp').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Free Rotate', MSPhysics::Motor::DEFAULT_FREE_ROTATE_ENABLED)
      cmd << "$('#motor-enable_free_rotate').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::Motor::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#motor-controller').val(#{attr.inspect});"
    when 'Servo'
      joint_type2 = 'servo'
      cmd << "$('#tab4-servo').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS).to_s
      cmd << "$('#servo-angle_units').val('#{attr}');"
      cmd << "$('#servo-angle_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min', fix_numeric_value(MSPhysics::Servo::DEFAULT_MIN * iang_ratio))
      cmd << "$('#servo-min').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max', fix_numeric_value(MSPhysics::Servo::DEFAULT_MAX * iang_ratio))
      cmd << "$('#servo-max').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Limits', MSPhysics::Servo::DEFAULT_LIMITS_ENABLED)
      cmd << "$('#servo-enable_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Rate', fix_numeric_value(MSPhysics::Servo::DEFAULT_RATE * iang_ratio))
      cmd << "$('#servo-rate').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Power', fix_numeric_value(MSPhysics::Servo::DEFAULT_POWER))
      cmd << "$('#servo-power').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Reduction Ratio', fix_numeric_value(MSPhysics::Servo::DEFAULT_REDUCTION_RATIO))
      cmd << "$('#servo-reduction_ratio').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::Servo::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#servo-controller').val(#{attr.inspect});"
    when 'Slider'
      joint_type2 = 'slider'
      cmd << "$('#tab4-slider').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS).to_s
      cmd << "$('#slider-position_units').val('#{attr}');"
      cmd << "$('#slider-position_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min', fix_numeric_value(MSPhysics::Slider::DEFAULT_MIN * ipos_ratio))
      cmd << "$('#slider-min').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max', fix_numeric_value(MSPhysics::Slider::DEFAULT_MAX * ipos_ratio))
      cmd << "$('#slider-max').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Limits', MSPhysics::Slider::DEFAULT_LIMITS_ENABLED)
      cmd << "$('#slider-enable_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Friction', fix_numeric_value(MSPhysics::Slider::DEFAULT_FRICTION))
      cmd << "$('#slider-friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::Slider::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#slider-controller').val(#{attr.inspect});"
    when 'Piston'
      joint_type2 = 'piston'
      cmd << "$('#tab4-piston').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS).to_s
      cmd << "$('#piston-position_units').val('#{attr}');"
      cmd << "$('#piston-position_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min', fix_numeric_value(MSPhysics::Piston::DEFAULT_MIN * ipos_ratio))
      cmd << "$('#piston-min').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max', fix_numeric_value(MSPhysics::Piston::DEFAULT_MAX * ipos_ratio))
      cmd << "$('#piston-max').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Limits', MSPhysics::Piston::DEFAULT_LIMITS_ENABLED)
      cmd << "$('#piston-enable_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Rate', fix_numeric_value(MSPhysics::Piston::DEFAULT_RATE * ipos_ratio))
      cmd << "$('#piston-rate').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Power', fix_numeric_value(MSPhysics::Piston::DEFAULT_POWER))
      cmd << "$('#piston-power').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Reduction Ratio', fix_numeric_value(MSPhysics::Piston::DEFAULT_REDUCTION_RATIO))
      cmd << "$('#piston-reduction_ratio').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::Piston::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#piston-controller').val(#{attr.inspect});"
      attr = @selected_joint.get_attribute(jdict, 'Controller Mode', MSPhysics::Piston::DEFAULT_CONTROLLER_MODE)
      cmd << "$('#piston-controller_mode').val('#{AMS.clamp(attr.to_i, 0, 2)}');"
      cmd << "$('#piston-controller_mode').trigger('chosen:updated');"
    when 'Spring'
      joint_type2 = 'spring'
      cmd << "$('#tab4-spring').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS).to_s
      cmd << "$('#spring-position_units').val('#{attr}');"
      cmd << "$('#spring-position_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min', fix_numeric_value(MSPhysics::Spring::DEFAULT_MIN * ipos_ratio))
      cmd << "$('#spring-min').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max', fix_numeric_value(MSPhysics::Spring::DEFAULT_MAX * ipos_ratio))
      cmd << "$('#spring-max').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Limits', MSPhysics::Spring::DEFAULT_LIMITS_ENABLED)
      cmd << "$('#spring-enable_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Enable Rotation', MSPhysics::Spring::DEFAULT_ROTATION_ENABLED)
      cmd << "$('#spring-enable_rotation').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Mode', MSPhysics::Spring::DEFAULT_MODE).to_i
      cmd << "$('#spring-mode').val('#{attr}');"
      cmd << "$('#spring-mode').trigger('chosen:updated');"
      if attr == 1
        cmd << "$('.spring-mode_s0').css('display', 'none');"
        cmd << "$('.spring-mode_s1').css('display', 'table-row');"
      else
        cmd << "$('.spring-mode_s0').css('display', 'table-row');"
        cmd << "$('.spring-mode_s1').css('display', 'none');"
      end
      attr = @selected_joint.get_attribute(jdict, 'Accel', fix_numeric_value(MSPhysics::Spring::DEFAULT_ACCEL))
      cmd << "$('#spring-accel').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Damp', fix_numeric_value(MSPhysics::Spring::DEFAULT_DAMP))
      cmd << "$('#spring-damp').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Strength', fix_numeric_value(MSPhysics::Spring::DEFAULT_STRENGTH))
      cmd << "$('#spring-strength').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Spring Constant', fix_numeric_value(MSPhysics::Spring::DEFAULT_SPRING_CONSTANT))
      cmd << "$('#spring-spring_constant').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Spring Drag', fix_numeric_value(MSPhysics::Spring::DEFAULT_SPRING_DRAG))
      cmd << "$('#spring-spring_drag').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Start Position', fix_numeric_value(MSPhysics::Spring::DEFAULT_START_POSITION * ipos_ratio))
      cmd << "$('#spring-start_position').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::Spring::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#spring-controller').val(#{attr.inspect});"
    when 'UpVector'
      joint_type2 = 'up_vector'
      cmd << "$('#tab4-up_vector').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Accel', fix_numeric_value(MSPhysics::UpVector::DEFAULT_ACCEL))
      cmd << "$('#up_vector-accel').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Damp', fix_numeric_value(MSPhysics::UpVector::DEFAULT_DAMP))
      cmd << "$('#up_vector-damp').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Strength', MSPhysics::UpVector::DEFAULT_STRENGTH)
      cmd << "$('#up_vector-strength').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::UpVector::DEFAULT_PIN_DIR.to_a.to_s)
      cmd << "$('#up_vector-controller').val(#{attr.inspect});"
    when 'Corkscrew'
      joint_type2 = 'corkscrew'
      cmd << "$('#tab4-corkscrew').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS).to_s
      cmd << "$('#corkscrew-position_units').val('#{attr}');"
      cmd << "$('#corkscrew-position_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min Position', fix_numeric_value(MSPhysics::Corkscrew::DEFAULT_MIN_POSITION * ipos_ratio))
      cmd << "$('#corkscrew-min_position').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max Position', fix_numeric_value(MSPhysics::Corkscrew::DEFAULT_MAX_POSITION * ipos_ratio))
      cmd << "$('#corkscrew-max_position').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Linear Limits', MSPhysics::Corkscrew::DEFAULT_LINEAR_LIMITS_ENABLED)
      cmd << "$('#corkscrew-enable_linear_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Linear Friction', fix_numeric_value(MSPhysics::Corkscrew::DEFAULT_LINEAR_FRICTION))
      cmd << "$('#corkscrew-linear_friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS).to_s
      cmd << "$('#corkscrew-angle_units').val('#{attr}');"
      cmd << "$('#corkscrew-angle_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min Angle', fix_numeric_value(MSPhysics::Corkscrew::DEFAULT_MIN_ANGLE * iang_ratio))
      cmd << "$('#corkscrew-min_angle').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max Angle', fix_numeric_value(MSPhysics::Corkscrew::DEFAULT_MAX_ANGLE * iang_ratio))
      cmd << "$('#corkscrew-max_angle').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Angular Limits', MSPhysics::Corkscrew::DEFAULT_ANGULAR_LIMITS_ENABLED)
      cmd << "$('#corkscrew-enable_angular_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Angular Friction', fix_numeric_value(MSPhysics::Corkscrew::DEFAULT_ANGULAR_FRICTION))
      cmd << "$('#corkscrew-angular_friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
    when 'BallAndSocket'
      joint_type2 = 'ball_and_socket'
      cmd << "$('#tab4-ball_and_socket').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS).to_s
      cmd << "$('#ball_and_socket-angle_units').val('#{attr}');"
      cmd << "$('#ball_and_socket-angle_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Max Cone Angle', fix_numeric_value(MSPhysics::BallAndSocket::DEFAULT_MAX_CONE_ANGLE * iang_ratio))
      cmd << "$('#ball_and_socket-max_cone_angle').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Cone Limits', MSPhysics::BallAndSocket::DEFAULT_CONE_LIMITS_ENABLED)
      cmd << "$('#ball_and_socket-enable_cone_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Min Twist Angle', fix_numeric_value(MSPhysics::BallAndSocket::DEFAULT_MIN_TWIST_ANGLE * iang_ratio))
      cmd << "$('#ball_and_socket-min_twist_angle').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max Twist Angle', fix_numeric_value(MSPhysics::BallAndSocket::DEFAULT_MAX_TWIST_ANGLE * iang_ratio))
      cmd << "$('#ball_and_socket-max_twist_angle').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Twist Limits', MSPhysics::BallAndSocket::DEFAULT_TWIST_LIMITS_ENABLED)
      cmd << "$('#ball_and_socket-enable_twist_limits').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Friction', fix_numeric_value(MSPhysics::BallAndSocket::DEFAULT_FRICTION))
      cmd << "$('#ball_and_socket-friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::BallAndSocket::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#ball_and_socket-controller').val(#{attr.inspect});"
    when 'Universal'
      joint_type2 = 'universal'
      cmd << "$('#tab4-universal').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Angle Units', MSPhysics::DEFAULT_ANGLE_UNITS).to_s
      cmd << "$('#universal-angle_units').val('#{attr}');"
      cmd << "$('#universal-angle_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Min1', fix_numeric_value(MSPhysics::Universal::DEFAULT_MIN * iang_ratio))
      cmd << "$('#universal-min1').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max1', fix_numeric_value(MSPhysics::Universal::DEFAULT_MAX * iang_ratio))
      cmd << "$('#universal-max1').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Limits1', MSPhysics::Universal::DEFAULT_LIMITS_ENABLED)
      cmd << "$('#universal-enable_limits1').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Min2', fix_numeric_value(MSPhysics::Universal::DEFAULT_MIN * iang_ratio))
      cmd << "$('#universal-min2').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Max2', fix_numeric_value(MSPhysics::Universal::DEFAULT_MAX * iang_ratio))
      cmd << "$('#universal-max2').val('#{ format_value(attr.to_f, PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Limits2', MSPhysics::Universal::DEFAULT_LIMITS_ENABLED)
      cmd << "$('#universal-enable_limits2').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Friction', fix_numeric_value(MSPhysics::Universal::DEFAULT_FRICTION))
      cmd << "$('#universal-friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::Universal::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#universal-controller').val(#{attr.inspect});"
    when 'CurvySlider'
      joint_type2 = 'curvy_slider'
      cmd << "$('#tab4-curvy_slider').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Alignment', MSPhysics::CurvySlider::DEFAULT_ALIGNMENT_ENABLED)
      cmd << "$('#curvy_slider-enable_alignment').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Enable Rotation', MSPhysics::CurvySlider::DEFAULT_ROTATION_ENABLED)
      cmd << "$('#curvy_slider-enable_rotation').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Enable Loop', MSPhysics::CurvySlider::DEFAULT_LOOP_ENABLED)
      cmd << "$('#curvy_slider-enable_loop').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Linear Friction', fix_numeric_value(MSPhysics::CurvySlider::DEFAULT_LINEAR_FRICTION))
      cmd << "$('#curvy_slider-linear_friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Angular Friction', fix_numeric_value(MSPhysics::CurvySlider::DEFAULT_ANGULAR_FRICTION))
      cmd << "$('#curvy_slider-angular_friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Alignment Power', fix_numeric_value(MSPhysics::CurvySlider::DEFAULT_ALIGNMENT_POWER))
      cmd << "$('#curvy_slider-alignment_power').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::CurvySlider::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#curvy_slider-controller').val(#{attr.inspect});"
    when 'CurvyPiston'
      joint_type2 = 'curvy_piston'
      cmd << "$('#tab4-curvy_piston').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Position Units', MSPhysics::DEFAULT_POSITION_UNITS).to_s
      cmd << "$('#curvy_piston-position_units').val('#{attr}');"
      cmd << "$('#curvy_piston-position_units').trigger('chosen:updated');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Alignment', MSPhysics::CurvyPiston::DEFAULT_ALIGNMENT_ENABLED)
      cmd << "$('#curvy_piston-enable_alignment').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Enable Rotation', MSPhysics::CurvyPiston::DEFAULT_ROTATION_ENABLED)
      cmd << "$('#curvy_piston-enable_rotation').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Enable Loop', MSPhysics::CurvyPiston::DEFAULT_LOOP_ENABLED)
      cmd << "$('#curvy_piston-enable_loop').prop('checked', #{attr ? true : false});"
      attr = @selected_joint.get_attribute(jdict, 'Angular Friction', fix_numeric_value(MSPhysics::CurvyPiston::DEFAULT_ANGULAR_FRICTION))
      cmd << "$('#curvy_piston-angular_friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Rate', fix_numeric_value(MSPhysics::CurvyPiston::DEFAULT_RATE * ipos_ratio))
      cmd << "$('#curvy_piston-rate').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Power', fix_numeric_value(MSPhysics::CurvyPiston::DEFAULT_POWER))
      cmd << "$('#curvy_piston-power').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Alignment Power', fix_numeric_value(MSPhysics::CurvyPiston::DEFAULT_ALIGNMENT_POWER))
      cmd << "$('#curvy_piston-alignment_power').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Reduction Ratio', fix_numeric_value(MSPhysics::CurvyPiston::DEFAULT_REDUCTION_RATIO))
      cmd << "$('#curvy_piston-reduction_ratio').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, 1.0), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Controller', MSPhysics::CurvyPiston::DEFAULT_CONTROLLER.to_s)
      cmd << "$('#curvy_piston-controller').val(#{attr.inspect});"
      attr = @selected_joint.get_attribute(jdict, 'Controller Mode', MSPhysics::CurvyPiston::DEFAULT_CONTROLLER_MODE)
      cmd << "$('#curvy_piston-controller_mode').val('#{AMS.clamp(attr.to_i, 0, 2)}');"
      cmd << "$('#curvy_piston-controller_mode').trigger('chosen:updated');"
    when 'Plane'
      joint_type2 = 'plane'
      cmd << "$('#tab4-plane').css('display', 'block');"
      attr = @selected_joint.get_attribute(jdict, 'Linear Friction', fix_numeric_value(MSPhysics::Plane::DEFAULT_LINEAR_FRICTION))
      cmd << "$('#plane-linear_friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Angular Friction', fix_numeric_value(MSPhysics::Plane::DEFAULT_ANGULAR_FRICTION))
      cmd << "$('#plane-angular_friction').val('#{ format_value(AMS.clamp(attr.to_f, 0.0, nil), PRECISION) }');"
      attr = @selected_joint.get_attribute(jdict, 'Enable Rotation', MSPhysics::Plane::DEFAULT_ROTATION_ENABLED)
      cmd << "$('#plane-enable_rotation').prop('checked', #{attr ? true : false});"
    end
    # Display geared joints
    if joint_type2 && false
      identical_joints = {}
      geared_data = {}
      if Sketchup.version.to_i > 6
        sjparent = model.active_path ? model.active_path.last : nil
      else
        sjparent = model.active_entities.is_a?(Sketchup::Model) ? nil : model.active_entities.parent.instances.first
      end
      MSPhysics::JointConnectionTool.get_geared_joints(@selected_joint, sjparent, true, false).each { |joint, jparent, jtra, gear_id, gear_type, gear_ratio|
        jtype = joint.get_attribute('MSPhysics Joint', 'Type')
        jname = joint.name.to_s
        jname = gear_id.to_s if jname.empty?
        fname = jtype + '-' + jname
        fid = gear_type.to_s + '-' + gear_id.to_s
        geared_data[gear_type] = {} unless geared_data[gear_type]
        if @geared_joints[fid]
          if identical_joints[fid]
            identical_joints[fid] += 1
          else
            identical_joints[fid] = 1
          end
          fid2 = fid + '-' + identical_joints[fid].to_s
          fname2 = fname + ' (' + identical_joints[fid].to_s + ')'
          @geared_joints[fid2] = joint
          geared_data[gear_type][fid2] = [joint, fname2, gear_ratio]
        else
          @geared_joints[fid] = joint
          geared_data[gear_type][fid] = [joint, fname, gear_ratio]
        end
      }
      identical_joints.clear
      unless geared_data.empty?
        cmd << "$('##{joint_type2}-geared_joints_field').css('display', 'block');"
        cmd << "$('##{joint_type2}-geared_joints_field').append(\""
        cmd2 = ""
        geared_data.each { |gear_type, data|
          words = DOUBLE_JOINT_TYPES[gear_type].split(/\_/)
          for i in 0...words.size
            words[i].capitalize!
          end
          gear_name = words.join(' ')
          cmd << "<label class=\\\"heading\\\">#{gear_name}</label>"
          cmd << "<div class=\\\"spacing_tab\\\">"
          cmd << "<table class=\\\"struct_table\\\">"
          data.keys.sort.each { |fid|
            joint, fname, gear_ratio = data[fid]
            cmd << "<tr>"
            cmd << "<td colspan=\\\"1\\\"><label>With</label></td>"
            cmd << "<td colspan=\\\"4\\\"><label class=\\\"joint-label#{joint == @selected_joint ? "-selected" : ""}\\\" id=\\\"Geared::#{fid}\\\">#{fname.inspect[1...-1]}</label></td>"
            cmd << "<td colspan=\\\"1\\\"><label>Ratio</label></td>"
            cmd << "<td colspan=\\\"4\\\"><input class=\\\"custom-text numeric-input\\\" id=\\\"gear-#{fid}\\\"></input></td>"
            cmd << "</tr>"
            cmd2 << "$('#gear-#{fid}').val('#{ format_value(gear_ratio.nil? ? 1.0 : gear_ratio, PRECISION) }');"
          }
          cmd << "</table>"
          cmd << "</div>"
        }
        cmd << "\");"
        cmd << "assign_joint_click_event(); update_input_events();"
        cmd << cmd2
        geared_data.clear
      end
    end
    # Activate Joint tab
    cmd << "update_placement(4, false);"# unless @selected_body
  else
    @selected_joint = nil
  end
  execute_js(cmd)
end

.update_simulation_slidersvoid

This method returns an undefined value.

Since:

  • 1.0.0



125
126
127
128
129
130
131
132
133
134
# File 'RubyExtension/MSPhysics/dialog.rb', line 125

def update_simulation_sliders
  return if @dialog.nil? || !@init_called
  model = Sketchup.active_model
  return unless model
  cmd = ''
  cmd << "if (g_kns_velocity != null) { g_kns_velocity.setValue(#{MSPhysics::Settings.key_nav_velocity}); };"
  cmd << "if (g_kns_omega != null) { g_kns_omega.setValue(#{MSPhysics::Settings.key_nav_omega}); };"
  cmd << "if (g_kns_atime != null) { g_kns_atime.setValue(#{MSPhysics::Settings.key_nav_atime}); };"
  execute_js(cmd)
end

.update_simulation_statevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Update UI simulation tab.

Since:

  • 1.0.0



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'RubyExtension/MSPhysics/dialog.rb', line 84

def update_simulation_state
  return if @dialog.nil? || !@init_called
  model = Sketchup.active_model
  return unless model
  cmd = ''
  cmd << "$('#simulation-animate_scenes_state').val('#{MSPhysics::Settings.animate_scenes_state}');"
  cmd << "$('#simulation-animate_scenes_state').trigger('chosen:updated');"
  cmd << "$('#simulation-animate_scenes_reversed').prop('checked', #{MSPhysics::Settings.animate_scenes_reversed?});"
  cmd << "$('#simulation-animate_scenes_delay').val('#{ format_value(MSPhysics::Settings.animate_scenes_delay, PRECISION) }');"
  cmd << "$('#simulation-key_nav_state').val('#{MSPhysics::Settings.key_nav_state}');"
  cmd << "$('#simulation-key_nav_state').trigger('chosen:updated');"
  cmd << "$('#simulation-solver_model').val('#{MSPhysics::Settings.solver_model}');"
  cmd << "$('#simulation-solver_model').trigger('chosen:updated');"
  cmd << "$('#simulation-joint_algorithm').val('#{MSPhysics::Settings.joint_algorithm}');"
  cmd << "$('#simulation-joint_algorithm').trigger('chosen:updated');"
  cmd << "$('#simulation-update_timestep').val('#{(1.0 / MSPhysics::Settings.update_timestep).round}');"
  cmd << "$('#simulation-update_timestep').trigger('chosen:updated');"
  cmd << "$('#simulation-continuous_collision').prop('checked', #{MSPhysics::Settings.continuous_collision_check_enabled?});"
  cmd << "$('#simulation-full_screen_mode').prop('checked', #{MSPhysics::Settings.full_screen_mode_enabled?});"
  cmd << "$('#simulation-game_mode').prop('checked', #{MSPhysics::Settings.game_mode_enabled?});"
  cmd << "$('#simulation-hide_joint_layer').prop('checked', #{MSPhysics::Settings.hide_joint_layer_enabled?});"
  cmd << "$('#simulation-undo_on_end').prop('checked', #{MSPhysics::Settings.undo_on_end_enabled?});"
  cmd << "$('#simulation-ignore_hidden_instances').prop('checked', #{MSPhysics::Settings.ignore_hidden_instances?});"
  cmd << "$('#simulation-collision_wireframe').prop('checked', #{MSPhysics::Settings.collision_wireframe_visible?});"
  cmd << "$('#simulation-axes').prop('checked', #{MSPhysics::Settings.axes_visible?});"
  cmd << "$('#simulation-aabb').prop('checked', #{MSPhysics::Settings.aabb_visible?});"
  cmd << "$('#simulation-contact_points').prop('checked', #{MSPhysics::Settings.contact_points_visible?});"
  cmd << "$('#simulation-contact_forces').prop('checked', #{MSPhysics::Settings.contact_forces_visible?});"
  cmd << "$('#simulation-bodies').prop('checked', #{MSPhysics::Settings.bodies_visible?});"
  cmd << "$('#simulation-gravity').val('#{ format_value(MSPhysics::Settings.gravity, PRECISION) }');"
  cmd << "$('#simulation-material_thickness').val('#{ format_value(MSPhysics::Settings.material_thickness * 32.0, PRECISION) }');"
  cmd << "$('#simulation-update_rate').val('#{MSPhysics::Settings.update_rate}');"
  cmd << "$('#dialog-help_box').prop('checked', #{ @dialog_help_box });"
  cmd << "display_help_box(#{@dialog_help_box});"
  cmd << "$('#dialog-scale').val('#{@dialog_scale}');"
  cmd << "$('#dialog-scale').trigger('chosen:updated');"
  execute_js(cmd)
  update_simulation_sliders
end

.update_sound_statevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Update UI sound tab.

Since:

  • 1.0.0



824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'RubyExtension/MSPhysics/dialog.rb', line 824

def update_sound_state
  return if @dialog.nil? || !@init_called
  model = Sketchup.active_model
  return unless model
  cmd = ""
  cmd << "$('#sound-list').empty();"
  dict = model.attribute_dictionary('MSPhysics Sounds', false)
  if dict
    dict.each_key { |name|
      ext = model.get_attribute('MSPhysics Sound Types', name)
      cmd << "$('#sound-list').append('<option value=#{name.inspect}>#{name}#{ext.is_a?(String) ? '.' + ext : ''}</option>');"
    }
  end
  if @selected_sound
    ext = model.get_attribute('MSPhysics Sound Types', @selected_sound)
    if MSPhysics::EMBEDDED_MUSIC_FORMATS.include?(ext)
      cmd << "$('#sound-command_music').val('simulation.play_music(#{@selected_sound.inspect})');"
    else
      cmd << "$('#sound-command_music').val('Not Supported');"
    end
    if MSPhysics::EMBEDDED_SOUND_FORMATS.include?(ext)
      cmd << "$('#sound-command_sound').val('simulation.play_sound(#{@selected_sound.inspect})');"
    else
      cmd << "$('#sound-command_sound').val('Not Supported');"
    end
  else
    cmd << "$('#sound-command_music').val('simulation.play_music(\"sound_name\")');"
    cmd << "$('#sound-command_sound').val('simulation.play_sound(\"sound_name\")');"
  end
  execute_js(cmd)
end

.update_stateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update state of all UI.

Since:

  • 1.0.0



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'RubyExtension/MSPhysics/dialog.rb', line 52

def update_state
  return if @dialog.nil? || !@init_called
  # Simulation dialog
  update_simulation_state
  # Joint dialog
  update_joint_state
  # Body dialog
  update_body_state
  # Sound dialog
  update_sound_state
  # Update size
  #execute_js("window.setTimeout(function() { update_placement(0, true); }, 10);")
  execute_js("update_placement(0, true);")
end