cdrapp.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "cdrapp.h"
  2. #include <stdio.h>
  3. #define _USE_MATH_DEFINES
  4. #include <math.h> // C++ 在 math.h 中定义 M_PI 需要 _USE_MATH_DEFINES 宏
  5. bool Test_Intersect(corel* cdr){
  6. cdr->ActiveDocument->Unit = cdrInch;
  7. IVGShapePtr s[3];
  8. IVGShapePtr si[3];
  9. IVGShapePtr sm;
  10. double x, y, radius = 1.5 ;
  11. int r, g, b;
  12. // 通过将 i 乘以 2.09439507 (120度的弧度),可以将三个椭圆均匀地分布在一个圆上。
  13. // radius = 1.5 则是决定椭圆的大小。 这个数字控制椭圆的半径,也就是椭圆的大小。 // 创建3个椭圆, 填色 RGB:
  14. for (int i = 0; i != 3; i++) {
  15. x = cdr->ActivePage->SizeWidth / 2 + 1 * cos(i * M_PI * 2.0 / 3.0);
  16. y = cdr->ActivePage->SizeHeight / 2 + 1 * sin(i * M_PI * 2.0 / 3.0);
  17. s[i] = MakeEllipse(cdr, x, y, radius);
  18. r = 255 * (i == 0);
  19. g = 255 * (i == 1);
  20. b = 255 * (i == 2);
  21. s[i]->Fill->UniformColor->RGBAssign(r, g, b);
  22. }
  23. // 创建3个相交物件, IVGShape::Intersect 函数原型
  24. // IVGShapePtr IVGShape::Intersect ( struct IVGShape * TargetShape, VARIANT_BOOL LeaveSource, VARIANT_BOOL LeaveTarget );
  25. for (int i = 0; i != 3; i++) {
  26. int n = (i + 1) % 3;
  27. si[i] = s[i]->Intersect(s[n], true, true);
  28. auto c1 = s[i]->Fill->UniformColor;
  29. auto c2 = s[n]->Fill->UniformColor;
  30. r = c1->RGBRed + c2->RGBRed;
  31. g = c1->RGBGreen + c2->RGBGreen;
  32. b = c1->RGBBlue + c2->RGBBlue;
  33. si[i]->Fill->UniformColor->RGBAssign(r, g, b);
  34. }
  35. // 建立相交物件,填充白色
  36. sm = si[1]->Intersect(si[2], true, true);
  37. auto c3 = cdr->CreateRGBColor(255, 255, 255);
  38. sm->Fill->UniformColor = c3;
  39. return true;
  40. }
  41. bool polygon_gravity_dot(corel* cdr){
  42. cdr->ActiveDocument->Unit = cdrMillimeter;
  43. double x, y;
  44. // IVGShapePtr ActiveShape; // 获取当前选中的图形 函数原型
  45. auto s = cdr->ActiveShape;
  46. // IVGShapeRangePtr IVGApplication::CreateShapeRange ( );
  47. auto srs = cdr->CreateShapeRange();
  48. // 获取节点函数原型
  49. // IVGNodePtr IVGNodes::GetItem ( long Index );
  50. // IVGNodePtr IVGNodeRange::GetItem ( long Index );
  51. for(auto i = 0; i < s->DisplayCurve->Nodes->Count; i++){
  52. auto n = s->DisplayCurve->Nodes->Item[i+1];
  53. x = n->PositionX;
  54. y = n->PositionY;
  55. printf("%f, %f\n", x, y);
  56. // auto sy = MakeEllipse(cdr, x, y, 5);
  57. // sy->Outline->Color->RGBAssign(255, 0, 0);
  58. // auto sj = MakeRectangle(cdr, x, y, 10, 10);
  59. // sj->Outline->Color->RGBAssign(0, 255, 0);
  60. auto l = DrawLine(cdr, x, y, s->CenterX, s->CenterY);
  61. srs->Add(l);
  62. }
  63. // HRESULT IVGShapeRange::CreateSelection ( );
  64. srs->CreateSelection();
  65. return true;
  66. }
  67. // 建立矩形和圆形函数原型
  68. // IVGShapePtr IVGLayer::CreateRectangle2 ( double x, double y, double Width, double Height,
  69. // double RadiusUL, double RadiusUR, double RadiusLR, double RadiusLL );
  70. // IVGShapePtr IVGLayer::CreateEllipse2 ( double CenterX, double CenterY, double Radius1,
  71. // double Radius2, double StartAngle, double EndAngle, VARIANT_BOOL Pie );
  72. IVGShapePtr MakeEllipse(corel* cdr, double x, double y, double r){
  73. return cdr->ActiveLayer->CreateEllipse2(x, y, r, ZERO_4PC);
  74. }
  75. IVGShapePtr MakeEllipse(corel* cdr, IVGShapePtr s, double r){
  76. double x, y;
  77. x = s->CenterX;
  78. y = s->CenterY;
  79. return cdr->ActiveLayer->CreateEllipse2(x, y, r, ZERO_4PC);
  80. }
  81. IVGShapePtr MakeRectangle(corel* cdr, double x, double y, double w, double h){
  82. auto sj = cdr->ActiveLayer->CreateRectangle2(x, y, w, h, ZERO_4PC);
  83. sj->PutCenterX(x);
  84. sj->PutCenterY(y);
  85. return sj;
  86. }
  87. IVGShapePtr MakeRectangle(corel* cdr, IVGShapePtr s, double w, double h){
  88. double x, y;
  89. x = s->CenterX;
  90. y = s->CenterY;
  91. auto sj = cdr->ActiveLayer->CreateRectangle2(x, y, w, h, ZERO_4PC);
  92. sj->PutCenterX(x);
  93. sj->PutCenterY(y);
  94. return sj;
  95. }
  96. // IVGShapePtr IVGLayer::CreateLineSegment ( double StartX, double StartY, double EndX, double EndY );
  97. // 画一条线,设置轮廓色 M100
  98. IVGShapePtr DrawLine(corel* cdr, double x1, double y1, double x2, double y2){
  99. auto line = cdr->ActiveLayer->CreateLineSegment(x1, y1, x2, y2);
  100. line->Outline->Color->CMYKAssign(0, 100, 0, 0);
  101. return line;
  102. }
  103. // IVGShapePtr IVGLayer::FindShape ( _bstr_t Name, enum cdrShapeType Type, long StaticID, VARIANT_BOOL Recursive );
  104. // IVGShapePtr IVGLayer::CreateCurveSegment ( double StartX, double StartY, double EndX, double EndY, double StartingControlPointLength,
  105. // double StartingControlPointAngle, double EndingControlPointLength, double EndingControlPointAngle );
  106. // IVGShapePtr IVGLayer::CreateCurveSegment2 ( double x1, double y1, double StartingControlPointX, double StartingControlPointY,
  107. // double EndingControlPointX, double EndingControlPointY, double x2, double y2 );