1
1

frmSelectSame.bas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmSelectSame
  3. Caption = "相似选择"
  4. ClientHeight = 4770
  5. ClientLeft = 495
  6. ClientTop = 5895
  7. ClientWidth = 2625
  8. OleObjectBlob = "frmSelectSame.frx":0000
  9. ShowModal = 0 'False
  10. End
  11. Attribute VB_Name = "frmSelectSame"
  12. Attribute VB_GlobalNameSpace = False
  13. Attribute VB_Creatable = False
  14. Attribute VB_PredeclaredId = True
  15. Attribute VB_Exposed = False
  16. Option Explicit 'Requires explicit declaration of all
  17. 'variables. This protects against
  18. 'inadvertent use of the slow 'Variant' type
  19. 'variables which are used when the specific
  20. 'type is unknown.
  21. Private Const TOOLNAME As String = "VBA_SelectSame"
  22. Private Const SECTION As String = "Options"
  23. Private Sub btnSelect_Click()
  24. On Error Resume Next
  25. Dim fLeft As Double, fTop As Double
  26. fLeft = frmSelectSame.Left
  27. fTop = frmSelectSame.Top
  28. SaveSetting "SelectSame", "Preferences", "form_left", fLeft
  29. SaveSetting "SelectSame", "Preferences", "form_top", fTop
  30. beg
  31. If (chkFill = False And _
  32. chkOutline = False And _
  33. chkOutlineColor = False And _
  34. chkOutlineLength = False And _
  35. chkSize = False And _
  36. chkWHratio = False And _
  37. chkType = False And _
  38. chkNodes = False And _
  39. chkSegments = False And _
  40. chkPaths = False) Then
  41. MsgBox "请至少选择一个选项", vbCritical, "JH Select Same 2"
  42. Exit Sub
  43. End If
  44. With Me '"Me" is a VBA reserved word, returning a
  45. 'reference to the form (or class module)
  46. 'in which the current code is located.
  47. 'The chk... functions return the current
  48. 'Value of the check buttons of the same
  49. 'name.
  50. .SelectAllSimilar .chkFill, .chkOutline, .chkOutlineColor, .chkOutlineLength, _
  51. .chkSize, .chkWHratio, .chkType, .chkNodes, .chkSegments, .chkPaths, _
  52. .OptDoc, .Optpage, .Optlayer, .chkInGroups, .chkColorMark, .chkIndiv
  53. End With
  54. EndOpt
  55. 'Added to fix refresh issues
  56. ActiveWindow.Refresh
  57. Application.Refresh
  58. 'On Error Resume Next
  59. ' If VersionMajor = 13 Then
  60. ' AppActivate "CorelDRAW X3"
  61. ' AppActivate ActiveDocument
  62. ' End If
  63. ' If VersionMajor = 14 Then
  64. ' AppActivate "CorelDRAW X4"
  65. ' AppActivate ActiveDocument
  66. ' End If
  67. ' If VersionMajor = 15 Then
  68. ' AppActivate "CorelDRAW X5"
  69. ' AppActivate ActiveDocument
  70. ' End If
  71. ' If VersionMajor = 16 Then
  72. ' AppActivate "CorelDRAW X6"
  73. ' AppActivate ActiveDocument
  74. ' End If
  75. ' If VersionMajor = 17 Then
  76. ' AppActivate "CorelDRAW X7"
  77. ' AppActivate ActiveDocument
  78. ' End If
  79. ' If VersionMajor = 18 Then
  80. ' AppActivate "CorelDRAW X8"
  81. ' AppActivate ActiveDocument
  82. ' End If
  83. ' If VersionMajor = 19 Then
  84. ' AppActivate "CorelDRAW 2017"
  85. ' AppActivate ActiveDocument
  86. ' End If
  87. ' If VersionMajor = 20 Then
  88. ' AppActivate "CorelDRAW 2018"
  89. ' AppActivate ActiveDocument
  90. ' End If
  91. ' If VersionMajor = 21 Then
  92. ' AppActivate "CorelDRAW 2019"
  93. ' AppActivate ActiveDocument
  94. ' End If
  95. End Sub
  96. Sub SelectAllSimilar(Optional CheckFill As Boolean = True, _
  97. Optional CheckOutline As Boolean = True, _
  98. Optional CheckOutlineColor As Boolean = True, _
  99. Optional CheckOutlineLength As Boolean = True, _
  100. Optional CheckSize As Boolean = False, _
  101. Optional CheckWHratio As Boolean = False, _
  102. Optional CheckType As Boolean = True, _
  103. Optional CountNodes As Boolean = False, _
  104. Optional CountSegments As Boolean = False, _
  105. Optional CountPaths As Boolean = False, _
  106. Optional WithinDoc As Boolean = False, _
  107. Optional WithinPage As Boolean = True, _
  108. Optional WithinLayer As Boolean = False, _
  109. Optional WithinGroups As Boolean = True, _
  110. Optional CheckColorMark As Boolean = False, _
  111. Optional CheckIndiv As Boolean = True)
  112. 'Object variables. Reference to:
  113. Dim shpsSelected As Shapes 'selected shapes,
  114. Dim shpsToTest As Shapes 'full set of shapes to be tested,
  115. Dim pagesr As ShapeRange 'pages shapes collection,
  116. Dim docsr As New ShapeRange
  117. Dim shpModel As Shape 'a pre-selected shape,
  118. Dim shpToMatch As Shape 'a shape to be matched,
  119. 'Dim oScript As Object 'CorelScript object,
  120. Dim clnModelShapes As Collection 'our list of pre-selected shapes,定义源对象集合
  121. Dim clnSubShapes As Collection 'our list of shapes inside a group. 定义群组内的目标对象
  122. Dim P As Page, p1 As Page '文档中查找使用
  123. Dim shr As ShapeRange, sr As New ShapeRange
  124. Dim i As Integer ' '文档中循环查找计数使用
  125. On Error GoTo NothingSelected 'Get a reference to any
  126. Set shr = ActiveSelectionRange
  127. Set shpsSelected = ActiveDocument.Selection.Shapes
  128. On Error GoTo 0 'pre-selected shapes. 将文档中当前选中的范围作为源对象
  129. If shpsSelected.Count > 0 Then 'Gather the pre-selected shapes
  130. Set clnModelShapes = New Collection 'into a new collection for
  131. For Each shpModel In shpsSelected 'simple processing. 建立源对象集合
  132. clnModelShapes.Add shpModel
  133. Next
  134. '===================================
  135. ' TurnOptimizations cdrOptimizationOn
  136. '===================================
  137. If WithinPage Then
  138. Set shpsToTest = ActivePage.Shapes
  139. 'Ensure that "Edit across layers"
  140. 'is ON. Otherwise, selecting
  141. ' Set oScript = CorelScript 'across layers, followed by
  142. ' oScript.SetMultiLayer True 'grouping, can flatten all
  143. ' Set oScript = Nothing 'layers into one. 选中表示将对当前页面的所有对象与源对象进行匹配,否则只匹配当前图层的对象
  144. 'Replace the above with this line, CoreScript is not longer support X7+
  145. ActiveDocument.EditAcrossLayers = True
  146. End If
  147. If WithinLayer Then
  148. Set shpsToTest = ActivePage.ActiveLayer.Shapes
  149. End If
  150. If WithinDoc Then '在当前文档查找,将当前页面相应的对象加入到待比较范围
  151. 'Set p1 = ActivePage
  152. For i = 1 To ActiveDocument.Pages.Count
  153. ActiveDocument.Pages(i).Activate
  154. Set pagesr = ActivePage.SelectShapesFromRectangle(0, 2480, 1820, 0, False).Shapes.All
  155. docsr.AddRange pagesr '各页面依次查找,相应的对象加入到待比较范围
  156. Next i
  157. Set shpsToTest = docsr.Shapes
  158. ' MsgBox "共有待比较对象 " & shpsToTest.Count & " 个"
  159. Label13.Caption = "共有待比较对象 " & shpsToTest.Count & " 个"
  160. 'p1.Activate
  161. End If
  162. If WithinGroups Then 'Check through flattened list.
  163. Set clnSubShapes = FlatShapeList(shpsToTest)
  164. '=======
  165. For Each shpToMatch In clnSubShapes
  166. If Not shpToMatch.Selected Then 'If the shape is not yet selected,
  167. '==================== 'check the models for a match.
  168. For Each shpModel In clnModelShapes
  169. If ShapesMatch(shpToMatch, shpModel, CheckFill, _
  170. CheckOutline, CheckOutlineColor, CheckOutlineLength, CheckSize, CheckWHratio, _
  171. CheckType, CountNodes, CountSegments, CountPaths, CheckIndiv) Then
  172. 'shpToMatch.AddToSelection
  173. sr.Add shpToMatch
  174. Exit For 'If a match has now been found,
  175. End If 'we can skip any remaining models.
  176. Next
  177. '=====================
  178. End If
  179. Next
  180. '=======
  181. Else 'Check through top-level list.
  182. For Each shpToMatch In shpsToTest
  183. If Not shpToMatch.Selected Then 'If the shape is not yet selected,
  184. 'check the models for a match.
  185. For Each shpModel In clnModelShapes
  186. If ShapesMatch(shpToMatch, shpModel, CheckFill, _
  187. CheckOutline, CheckOutlineColor, CheckOutlineLength, CheckSize, CheckWHratio, _
  188. CheckType, CountNodes, CountSegments, CountPaths, CheckIndiv) Then
  189. 'shpToMatch.AddToSelection
  190. sr.Add shpToMatch
  191. Exit For 'If a match has now been found,
  192. End If 'we can skip any remaining models.
  193. Next
  194. End If
  195. Next
  196. End If
  197. '===================================
  198. ' TurnOptimizations cdrOptimizationOff
  199. 'CorelScript.RedrawScreen
  200. '===================================
  201. 'sr.Add ActiveDocument.Selection
  202. If CheckColorMark And sr.Count > 0 Then sr.SetOutlineProperties , , CreateCMYKColor(0, 100, 0, 0) '轮廓线上色
  203. sr.AddRange shr
  204. sr.CreateSelection
  205. ' MsgBox "共找到 " & sr.Count & " 个对象"
  206. Label13.Caption = "共找到 " & sr.Count & " 个对象"
  207. End If
  208. Set clnModelShapes = Nothing 'Release the memory allocated
  209. Set shpsToTest = Nothing
  210. Exit Sub
  211. NothingSelected:
  212. End Sub
  213. Private Function ShapesMatch(shpShape As Shape, shpModel As Shape, _
  214. Optional CheckFill As Boolean = True, _
  215. Optional CheckOutline As Boolean = True, _
  216. Optional CheckOutlineColor As Boolean = True, _
  217. Optional CheckOutlineLength As Boolean = True, _
  218. Optional CheckSize As Boolean = False, _
  219. Optional CheckWHratio As Boolean = False, _
  220. Optional CheckType As Boolean = True, _
  221. Optional CountNodes As Boolean = False, _
  222. Optional CountSegments As Boolean = False, _
  223. Optional CountPaths As Boolean = False, _
  224. Optional CheckIndiv As Boolean = False) As Boolean
  225. 'Sizes "match" if they differ by less than one per cent
  226. Dim ToleranceSize As Double '面积大小允许波动
  227. ToleranceSize = Me.TextBox1 / 100 '面积大小允许波动,以百分比为单位
  228. Dim ToleranceLength As Double '线长允许波动
  229. ToleranceLength = Me.TextBox2 / 100 '长度允许波动,以百分比为单位
  230. Dim ToleranceNodesCount As Long '节点数量允许波动,以 点 单位
  231. ToleranceNodesCount = Me.TextBox3 '节点数量允许波动,以 点 单位
  232. Dim ToleranceSubPathsCount As Long '子路径 子线段 允许波动,以 条 为单位
  233. ToleranceSubPathsCount = Me.TextBox4 '子路径 子线段 允许波动,以 条 为单位
  234. Dim ToleranceWHratio As Double '长宽比 允许波动,以 百分比 为单位
  235. ToleranceWHratio = Me.TextBox5 '长宽比 允许波动,以 百分比 为单位
  236. Dim ToleranceSegmentsCount As Long '线段数 允许波动,以 个 为单位
  237. ToleranceSegmentsCount = Me.TextBox6 '线段数 允许波动,以 个 为单位
  238. 'Object Variables. 'Reference to:
  239. Dim clrModel As Color 'color features of model shape,
  240. Dim clrShape As Color 'color features of shape to be tested
  241. Dim fillModel As Fill 'fill style of model shape,
  242. Dim outlnModel As Outline 'outline style of model shape,
  243. Dim crvModel As Curve 'Bezier curve of model shape,
  244. Dim crvShape As Curve 'Bezier curve of shape to be tested,
  245. Dim fntModel As StructFontProperties 'font properties of model text shape,
  246. Dim trgModel As Text 'general text properties of model shape.
  247. Dim spath As SubPath, opath As SubPath
  248. Dim j As Integer
  249. 'Simple Variables. Storage of:
  250. Dim dblWidth As Double 'width of a shape,
  251. Dim dblHeight As Double 'height of a shape,
  252. Dim lngShapeType As cdrShapeType 'code for type of shape to be tested,
  253. Dim lngModelType As cdrShapeType 'code for the type of a model shape,
  254. Dim lngType As Long 'code for the type of a fill, color,
  255. 'or outline.
  256. 'Does the SHAPE match the MODEL ?
  257. 'Exit immediately on any mismatch.
  258. With shpShape
  259. lngShapeType = .Type 'Same basic TYPE of shape ?
  260. lngModelType = shpModel.Type
  261. If CheckType Then If lngShapeType <> lngModelType Then GoTo NoMatch
  262. 'A GROUP ? delegate to GroupsMatch()
  263. ' If lngShapeType = cdrGroupShape Then
  264. ' ShapesMatch = GroupsMatch(shpShape, shpModel, CheckSize, _
  265. ' CountNodes, CountPaths)
  266. ' Exit Function
  267. ' End If
  268. 'Does SIZE count ? Is so, are the
  269. If CheckSize Then 'size differences significant ?
  270. dblWidth = shpModel.SizeWidth
  271. If Abs(.SizeWidth - dblWidth) > (dblWidth * _
  272. ToleranceSize) Then GoTo NoMatch
  273. dblHeight = shpModel.SizeHeight
  274. If Abs(.SizeHeight - dblHeight) > (dblHeight * _
  275. ToleranceSize) Then GoTo NoMatch
  276. End If
  277. If CheckWHratio Then 'size width and height ratio differences significant ?
  278. dblWidth = shpModel.SizeWidth
  279. dblHeight = shpModel.SizeHeight
  280. If Abs(.SizeHeight / .SizeWidth - dblHeight / dblWidth) > (dblHeight / dblWidth * ToleranceWHratio) Then GoTo NoMatch
  281. End If
  282. If CountNodes Or CountPaths Or CheckOutlineLength Or CountSegments Then
  283. 'Only Curves can match ...
  284. If lngShapeType <> cdrCurveShape Then GoTo NoMatch
  285. Set crvShape = .Curve
  286. Set crvModel = shpModel.Curve
  287. 'If CheckIndiv Then '逐条子路径比较
  288. 'If Abs(crvShape.SubPaths.Count - crvModel.SubPaths.Count) <> 0 Then GoTo NoMatch
  289. 'For j = 1 To crvShape.SubPaths.Count
  290. 'If Abs(crvShape.SubPath(j).Nodes.Count - crvModel.SubPath(j).Nodes.Count) > ToleranceNodesCount Then GoTo NoMatch
  291. 'Next j
  292. If CountPaths Then 'Do the PATH counts match ?
  293. If VersionMajor > 12 Then 'GDG ##########################################
  294. If Abs(crvShape.SubPaths.Count - crvModel.SubPaths.Count) > ToleranceSubPathsCount Then GoTo NoMatch
  295. 'MsgBox "subpaths1: " & crvShape.SubPaths.Count & "subpaths2: " & crvModel.SubPaths.Count
  296. Else
  297. If Abs(crvShape.SubPathCount - crvModel.SubPathCount) > ToleranceSubPathsCount Then GoTo NoMatch
  298. End If 'GDG #############################################################
  299. End If
  300. If CountNodes Then 'Do the NODE counts match ?
  301. If VersionMajor > 12 Then 'GDG ##########################################
  302. If Abs(crvShape.Nodes.Count - crvModel.Nodes.Count) > ToleranceNodesCount Then GoTo NoMatch
  303. Else
  304. If Abs(crvShape.NodeCount - crvModel.NodeCount) > ToleranceNodesCount Then GoTo NoMatch
  305. End If 'GDG #############################################################
  306. End If
  307. If CountSegments Then 'Do the Segments counts match ?
  308. If VersionMajor > 12 Then 'GDG ##########################################
  309. If Abs(crvShape.Segments.Count - crvModel.Segments.Count) > ToleranceSegmentsCount Then GoTo NoMatch
  310. Else
  311. If Abs(crvShape.SegmentCount - crvModel.SegmentCount) > ToleranceSegmentsCount Then GoTo NoMatch
  312. End If 'GDG #############################################################
  313. End If
  314. If CheckOutlineLength Then 'Do the curve length match ?
  315. If VersionMajor > 12 Then 'GDG ##########################################
  316. If Abs(crvShape.Length - crvModel.Length) > crvModel.Length * ToleranceLength Then GoTo NoMatch
  317. 'MsgBox "subpaths1: " & crvShape.SubPaths.Count & "subpaths2: " & crvModel.SubPaths.Count
  318. Else
  319. If Abs(crvShape.Length - crvModel.Length) > crvModel.Length * ToleranceLength Then GoTo NoMatch
  320. End If 'GDG #############################################################
  321. End If
  322. End If
  323. If CheckFill Then
  324. Set fillModel = shpModel.Fill
  325. With .Fill 'Is the FILL type the same ?
  326. lngType = .Type
  327. If lngType <> shpModel.Fill.Type Then GoTo NoMatch
  328. If lngType = cdrUniformFill Then
  329. 'Does the uniform fill match ?
  330. If VersionMajor > 12 Then 'GDG ##########################################
  331. 'GDG ##########################################
  332. Dim col1 As New Color
  333. col1.CopyAssign .UniformColor
  334. Dim col2 As New Color
  335. col2.CopyAssign shpModel.Fill.UniformColor
  336. 'GDG ##########################################
  337. If col1.IsSame(col2) = False Then GoTo NoMatch
  338. Else
  339. Set clrModel = fillModel.UniformColor
  340. lngType = .UniformColor.Type
  341. If lngType <> clrModel.Type Then GoTo NoMatch
  342. If .UniformColor.Name(True) <> clrModel.Name(True) Then GoTo NoMatch
  343. End If 'GDG #############################################################
  344. End If
  345. End With
  346. End If
  347. If CheckOutline Then '(Groups have no outline)
  348. If lngShapeType <> cdrGroupShape Then
  349. Set outlnModel = shpModel.Outline
  350. If Not outlnModel Is Nothing Then
  351. With .Outline
  352. lngType = .Type
  353. If lngType <> outlnModel.Type Then GoTo NoMatch
  354. If lngType > 0 Then 'Does the shape have an OUTLINE ?
  355. 'Same LINE WIDTH ?
  356. If .Width <> outlnModel.Width Then GoTo NoMatch
  357. 'Matching LINE COLOR ?
  358. ' Set clrShape = .Color
  359. ' lngType = clrShape.Type
  360. ' Set clrModel = outlnModel.Color
  361. ' If lngType <> clrModel.Type Then GoTo NoMatch
  362. ' If clrShape.Name(True) <> clrModel.Name(True) Then GoTo NoMatch
  363. End If
  364. End With
  365. End If
  366. End If
  367. End If
  368. If CheckOutlineColor Then '(Groups have no outline)
  369. If lngShapeType <> cdrGroupShape Then
  370. Set outlnModel = shpModel.Outline
  371. If Not outlnModel Is Nothing Then
  372. With .Outline
  373. lngType = .Type
  374. If lngType <> outlnModel.Type Then GoTo NoMatch
  375. If lngType > 0 Then 'Does the shape have an OUTLINE ?
  376. 'Matching LINE COLOR ?
  377. If VersionMajor > 12 Then 'GDG ##########################################
  378. 'GDG ##########################################
  379. Dim col3 As New Color
  380. col3.CopyAssign .Color
  381. Dim col4 As New Color
  382. col4.CopyAssign shpModel.Outline.Color
  383. 'GDG ##########################################
  384. If col3.IsSame(col4) = False Then GoTo NoMatch
  385. Else
  386. Set clrShape = .Color
  387. lngType = clrShape.Type
  388. Set clrModel = outlnModel.Color
  389. If lngType <> clrModel.Type Then GoTo NoMatch
  390. If clrShape.Name(True) <> clrModel.Name(True) _
  391. Then GoTo NoMatch
  392. End If
  393. End If
  394. End With
  395. End If
  396. End If
  397. End If
  398. End With
  399. ShapesMatch = True
  400. Exit Function
  401. NoMatch:
  402. ShapesMatch = False
  403. NoMatchExit:
  404. ShapesMatch = False
  405. Exit Function
  406. End Function
  407. Private Function GroupsMatch(Group As Shape, GroupModel As Shape, _
  408. Optional CheckFill As Boolean = True, _
  409. Optional CheckOutline As Boolean = True, _
  410. Optional CheckOutlineColor As Boolean = True, _
  411. Optional CheckOutlineLength As Boolean = True, _
  412. Optional CheckSize As Boolean = False, _
  413. Optional CheckType As Boolean = True, _
  414. Optional CountNodes As Boolean = False, _
  415. Optional CountPaths As Boolean = False) As Boolean
  416. 'Object Variables. Reference to:
  417. Dim shpsModels As Shapes 'shapes in the pre-selected group,
  418. Dim shpsInGroup As Shapes 'shapes in the group to be tested,
  419. Dim shpModel As Shape 'a shape in the pre-selected group,
  420. Dim shpInGroup As Shape 'a shape in the group to be tested.
  421. 'Simple Variables Storage of:
  422. Dim lngInGroup As Long 'number of shapes in a group,
  423. Dim i As Long 'a numeric index to a
  424. 'particular sub-group.
  425. 'On Error GoTo NoMatch 'Shape & model must be groups.
  426. Set shpsModels = GroupModel.Shapes
  427. Set shpsInGroup = Group.Shapes
  428. 'On Error GoTo 0
  429. 'Same number of shapes
  430. lngInGroup = shpsModels.Count 'in each group ?
  431. If shpsInGroup.Count <> lngInGroup Then GoTo NoMatch
  432. For i = 1 To lngInGroup 'Try to Match all sub-shapes,
  433. Set shpInGroup = shpsInGroup(i) 'and GroupsMatch all sub-groups.
  434. Set shpModel = shpsModels(i)
  435. If shpModel.Type <> cdrGroupShape Then
  436. If Not ShapesMatch(shpInGroup, shpModel, _
  437. CheckSize, CountNodes) Then GoTo NoMatch
  438. Else
  439. If Not GroupsMatch(shpInGroup, shpModel, _
  440. CheckSize, CountNodes) Then GoTo NoMatch
  441. End If
  442. Next i
  443. GroupsMatch = True
  444. Exit Function
  445. NoMatch:
  446. GroupsMatch = False
  447. End Function
  448. Private Function FlatShapeList(TopLevelShapes As Shapes) As Collection
  449. 'Object Variables. Reference to:
  450. Dim shpTopLevel As Shape 'a top-level shape,
  451. Dim shpInGroup As Shape 'a shape inside a group,
  452. Dim clnAllShapes As Collection 'our list of all members and
  453. 'descendants of TopLevelShapes.
  454. If TopLevelShapes.Count Then
  455. Set clnAllShapes = New Collection
  456. For Each shpTopLevel In TopLevelShapes
  457. 'Add shape to list, keyed under
  458. 'a string version of its unique ID
  459. clnAllShapes.Add shpTopLevel
  460. 'If the shape is a group, then
  461. 'also gather all its descendants
  462. 'and add them to the list.
  463. If shpTopLevel.Type = cdrGroupShape Then
  464. For Each shpInGroup In ShapesInGroup(shpTopLevel)
  465. clnAllShapes.Add shpInGroup
  466. Next
  467. End If
  468. Next
  469. Set FlatShapeList = clnAllShapes 'Return the assembled collection.
  470. Else
  471. Set FlatShapeList = Nothing
  472. End If
  473. End Function
  474. Private Function ShapesInGroup(GroupShape As Shape) As Collection
  475. 'Object Variables. Reference to:
  476. Dim shpsInGroup As Shapes 'the set of shapes inside a group,
  477. Dim shpInGroup As Shape 'a particular shape in a group,
  478. Dim shpNested As Shape 'a shape inside a sub-group,
  479. Dim clnShapeList As Collection 'our list of all nested shapes.
  480. If GroupShape.Type = cdrGroupShape Then
  481. Set shpsInGroup = GroupShape.Shapes 'Get a reference to the
  482. 'shapes in this group.
  483. Set clnShapeList = New Collection
  484. For Each shpInGroup In shpsInGroup
  485. clnShapeList.Add shpInGroup 'Add all shapes in the group to
  486. 'our main collection.
  487. If shpInGroup.Type = cdrGroupShape Then
  488. 'Recurse to get nested shapes.
  489. For Each shpNested In ShapesInGroup(shpInGroup)
  490. clnShapeList.Add shpNested
  491. Next
  492. End If
  493. Next
  494. Set ShapesInGroup = clnShapeList 'Return the assembled collection.
  495. Else
  496. Set ShapesInGroup = Nothing 'Release the memory if the
  497. End If 'collection is not needed
  498. End Function
  499. Private Sub Image2_Click()
  500. frminfo.Show vbModeless
  501. End Sub
  502. Private Sub UserForm_Activate()
  503. Const YES As String = "True"
  504. Const NO As String = "False"
  505. Optpage = GetSetting(TOOLNAME, SECTION, "InPage", YES)
  506. OptDoc = GetSetting(TOOLNAME, SECTION, "InDoc", NO)
  507. Optlayer = GetSetting(TOOLNAME, SECTION, "InLayer", NO)
  508. chkColorMark = GetSetting(TOOLNAME, SECTION, "ColorMark", YES)
  509. chkFill = GetSetting(TOOLNAME, SECTION, "Fill", YES)
  510. chkInGroups = GetSetting(TOOLNAME, SECTION, "InGroups", YES)
  511. chkNodes = GetSetting(TOOLNAME, SECTION, "Nodes", NO)
  512. chkSegments = GetSetting(TOOLNAME, SECTION, "Segments", NO)
  513. chkOutline = GetSetting(TOOLNAME, SECTION, "Outline", YES)
  514. chkOutlineColor = GetSetting(TOOLNAME, SECTION, "OutlineColor", NO)
  515. chkOutlineLength = GetSetting(TOOLNAME, SECTION, "OutlineLength", YES)
  516. chkPaths = GetSetting(TOOLNAME, SECTION, "Paths", NO)
  517. chkSize = GetSetting(TOOLNAME, SECTION, "Size", NO)
  518. chkWHratio = GetSetting(TOOLNAME, SECTION, "WHratio", NO)
  519. chkType = GetSetting(TOOLNAME, SECTION, "Type", YES)
  520. chkIndiv = GetSetting(TOOLNAME, SECTION, "Indiv", NO)
  521. chkColorMark = GetSetting(TOOLNAME, SECTION, "ColorMark", NO)
  522. saveFormPos False
  523. End Sub
  524. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  525. saveFormPos True
  526. End Sub
  527. Sub saveFormPos(bDoSave As Boolean)
  528. Dim dL, dT
  529. If bDoSave Then 'save position
  530. SaveSetting TOOLNAME, SECTION, "form_left", Me.Left
  531. SaveSetting TOOLNAME, SECTION, "form_top", Me.Top
  532. Else 'place instead.
  533. dL = GetSetting(TOOLNAME, SECTION, "form_left", 900)
  534. dT = GetSetting(TOOLNAME, SECTION, "form_top", 200)
  535. Me.Left = dL: Me.Top = dT
  536. End If
  537. End Sub
  538. Private Sub OptDoc_Click()
  539. SaveSetting TOOLNAME, SECTION, "InDoc", CStr(OptDoc)
  540. End Sub
  541. Private Sub Optlayer_Click()
  542. SaveSetting TOOLNAME, SECTION, "InLayer", CStr(Optlayer)
  543. End Sub
  544. Private Sub Optpage_Click()
  545. SaveSetting TOOLNAME, SECTION, "InPage", CStr(Optpage)
  546. End Sub
  547. Private Sub chkColorMark_Click()
  548. SaveSetting TOOLNAME, SECTION, "ColorMark", CStr(chkColorMark)
  549. End Sub
  550. Private Sub chkIndiv_Click()
  551. SaveSetting TOOLNAME, SECTION, "Indiv", CStr(chkIndiv)
  552. End Sub
  553. Private Sub chkFill_Click()
  554. SaveSetting TOOLNAME, SECTION, "Fill", CStr(chkFill)
  555. End Sub
  556. Private Sub chkInGroups_Click()
  557. SaveSetting TOOLNAME, SECTION, "InGroups", CStr(chkInGroups)
  558. End Sub
  559. Private Sub chkNodes_Click()
  560. SaveSetting TOOLNAME, SECTION, "Nodes", CStr(chkNodes)
  561. End Sub
  562. Private Sub chkSegments_Click()
  563. SaveSetting TOOLNAME, SECTION, "Segments", CStr(chkSegments)
  564. End Sub
  565. Private Sub chkOutline_Click()
  566. SaveSetting TOOLNAME, SECTION, "Outline", CStr(chkOutline)
  567. End Sub
  568. Private Sub chkOutlineColor_Click()
  569. SaveSetting TOOLNAME, SECTION, "OutlineColor", CStr(chkOutlineColor)
  570. End Sub
  571. Private Sub chkPaths_Click()
  572. SaveSetting TOOLNAME, SECTION, "Paths", CStr(chkPaths)
  573. End Sub
  574. Private Sub chkSize_Click()
  575. SaveSetting TOOLNAME, SECTION, "Size", CStr(chkSize)
  576. End Sub
  577. Private Sub chkWHratio_Click()
  578. SaveSetting TOOLNAME, SECTION, "WHratio", CStr(chkWHratio)
  579. End Sub
  580. Private Sub chkType_Click()
  581. SaveSetting TOOLNAME, SECTION, "Type", CStr(chkType)
  582. End Sub
  583. Private Sub chkOutLineLength_Click()
  584. SaveSetting TOOLNAME, SECTION, "OutlineLength", CStr(chkOutlineLength)
  585. End Sub
  586. Sub beg()
  587. ActiveDocument.Unit = cdrMillimeter
  588. ActiveDocument.BeginCommandGroup "aa"
  589. Optimization = True
  590. End Sub
  591. Sub EndOpt()
  592. Optimization = False
  593. ActiveDocument.EndCommandGroup
  594. ActiveWindow.Refresh
  595. Application.Refresh
  596. End Sub