frmSelectSame.frm 32 KB

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