New entities can not be selected

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
aby
Posts: 81
Joined: 21 May 2007, 13:02
Location: Turkey

New entities can not be selected

Post by aby » 01 Mar 2008, 13:01

Hi,

The problem of to select assigned entities is now shifted to select entites from a newly created drawing. In the following you'll find a very simple code which is based on your transparent code example. When you press the button the program creates two elipses. I'm trying to select one of the ellipse with no success. What am I missing.

Thanks

Aby

Code: Select all

<b>Header file</b>
//---------------------------------------------------------------------------

#ifndef TestSelectionH
#define TestSelectionH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>

#include <sgConsts.hpp>	// Pascal unit
#include <DXFConv.hpp>	// Pascal unit
#include <DXFImage.hpp>	// Pascal unit
#include <sgDrawingNavigator.hpp>
#include <DXFExport.hpp>
#include <CADtoDXF.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TPanel *pnlmage;
        TButton *btnOpen;
        TOpenDialog *OpenDialog1;
        void __fastcall btnOpenClick(TObject *Sender);

private:	// User declarations
                TsgDXFImage *vImg;
        TSGDrawingNavigator *FDwgNavigator;
              Types::TPoint FDownPoint;
              Types::TPoint FCurPoint;
              Types::TPoint FStartPoint;
                       bool FDrawing;

public:		// User declarations
              __fastcall TForm1(TComponent* Owner);
              __fastcall ~TForm1() { delete vImg; };
         void __fastcall ImageMouseDown(System::TObject* Sender, Controls::TMouseButton Button, Classes::TShiftState Shift, int X, int Y);
         void __fastcall ImageMouseMove(System::TObject* Sender, Classes::TShiftState Shift, int X, int Y);
         void __fastcall ImageMouseUp(System::TObject* Sender, Controls::TMouseButton Button, Classes::TShiftState Shift, int X, int Y);
         void __fastcall CreateSelectedEntities(Types::TRect ARect);
         void __fastcall ChangeRectBounds(TRect& ARect);
         bool __fastcall IsEntityInRect(Dxfconv::TsgDXFEntity *Entity, const TRect& Rect);


    __property TSGDrawingNavigator *DwgNavigator = { read = FDwgNavigator };
};
//---------------------------------------------------------------------------

void __fastcall DrawFrame(HDC AHDC, const Types::TRect &ARect);

extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
<b>.cpp file</b>
//---------------------------------------------------------------------------

#include <vcl.h>
#include "math.h"
#pragma hdrstop

#include "TestSelection.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
        FDwgNavigator = new TSGDrawingNavigator(pnlmage);
        FDwgNavigator->Parent = pnlmage;
        FDwgNavigator->Align = alClient;
        DwgNavigator->AutoFocus = true;
        DwgNavigator->Anchors = FDwgNavigator->Anchors << akLeft << akTop << akRight << akBottom;
        FDwgNavigator->OnMouseDown = ImageMouseDown;
        FDwgNavigator->OnMouseMove = ImageMouseMove;
        FDwgNavigator->OnMouseUp = ImageMouseUp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ImageMouseDown(System::TObject* Sender, Controls::TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
        if (Button == mbLeft) {
                FDownPoint = Point(X, Y);
                FCurPoint = FDownPoint;
                FStartPoint.x = X;
                FStartPoint.y = Y;
                FDrawing = true;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ImageMouseMove(System::TObject* Sender, Classes::TShiftState Shift, int X, int Y)
{
        if (FDrawing) {
                TRect  vRect;
                vRect.Top = FDownPoint.y;
                vRect.Left = FDownPoint.x;
                vRect.Bottom = FCurPoint.y;
                vRect.Right = FCurPoint.x;
                DrawFrame(FDwgNavigator->Canvas->Handle, vRect);
                FCurPoint = Point(X, Y);
                vRect.Bottom = FCurPoint.y;
                vRect.Right = FCurPoint.x;
                DrawFrame(FDwgNavigator->Canvas->Handle, vRect);
        }
}
//---------------------------------------------------------------------------
void __fastcall DrawFrame(HDC AHDC, const Types::TRect &ARect)
{

        int Width = ARect.Right - ARect.Left;
        int Height = ARect.Bottom - ARect.Top;
        PatBlt(AHDC, ARect.Left, ARect.Top, Width, 1, PATINVERT);
        PatBlt(AHDC, ARect.Left + Width - 1, ARect.Top + 1, 1, Height - 2, PATINVERT);
        PatBlt(AHDC, ARect.Left, ARect.Top + Height - 1, Width, 1, PATINVERT);
        PatBlt(AHDC, ARect.Left, ARect.Top + 1, 1, Height - 2, PATINVERT);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ImageMouseUp(System::TObject* Sender,
                       Controls::TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
        TRect vRect;
        if (FDrawing && fabs(FDownPoint.y - FCurPoint.y) >  0)  {
                vRect.Top = FDownPoint.y;
                vRect.Left = FDownPoint.x;
                vRect.Bottom = FCurPoint.y;
                vRect.Right = FCurPoint.x;
                DrawFrame(FDwgNavigator->Canvas->Handle, vRect);
                CreateSelectedEntities(vRect);
        } else  {
                TsgDXFEntity *FEntity = reinterpret_cast<TsgDXFEntity *> (SelectionMatrix->Matrix[X][Y]);
                if (FEntity) {
                        FEntity->Color = clYellow;
                        FDwgNavigator->Refresh();
                }
        }
        FDrawing = false;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::btnOpenClick(TObject *Sender)
{
        AnsiString cnstLayerName = "new_Layer";
        AnsiString cnstLTypeName = "new_LType";

        vImg = new TsgDXFImage;
        vImg->Converter->InitializeSections();
  //    { Adding the new linetype to image-converter }
        TsgDXFLineType *vLType = new TsgDXFLineType;
        vLType->Name = cnstLTypeName;
        vLType->Lines->AddTick(25);       // length of the "solid" part of a line
        vLType->Lines->AddTick(-12.5);    // length of the "empty" part of a line
        vImg->Converter->Sections[csLTypes]->AddEntity(vLType);

        TsgCADCurvePolygon *vHatch1 =  new TsgCADCurvePolygon;
        vImg->Layouts[0]->AddEntity(vHatch1);
        Tsg2DBoundaryList *vBoundary = new Tsg2DBoundaryList;
        vHatch1->BoundaryData->Add(vBoundary);
        Tsg2DEllipse *vEllipse = new Tsg2DEllipse;
        vBoundary->Add(vEllipse);
        vEllipse->CenterPoint = MakeF2DPoint(0,0);
        vEllipse->MajorPoint = MakeF2DPoint(0,100);
        vEllipse->Radius = 2;

        vHatch1->Color = clRed;
        vImg->Converter->Loads(vHatch1);

        TsgCADCurvePolygon *vHatch2 = new TsgCADCurvePolygon;
        vImg->Layouts[0]->AddEntity(vHatch2);
        vBoundary = new Tsg2DBoundaryList;
        vHatch2->BoundaryData->Add(vBoundary);
        vEllipse = new Tsg2DEllipse;
        vBoundary->Add(vEllipse);
        vEllipse->CenterPoint = MakeF2DPoint(80,80);
        vEllipse->MajorPoint = MakeF2DPoint(0,80);
        vEllipse->Radius = 2;
        vHatch2->Color = 0x9900FF00;   // 99 specifies a transparency
        vImg->Converter->Loads(vHatch2);

        vImg->GetExtents();
        FDwgNavigator->Picture->Graphic = vImg;
        FDwgNavigator->Width = (int) (vImg->AbsWidth());
        FDwgNavigator->Height = (int) (vImg->AbsHeight());
        FDwgNavigator->Update();
        FDwgNavigator->FitToSize();
        vImg->SetMatrixMode(smEnabled);
        FDwgNavigator->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CreateSelectedEntities(Types::TRect ARect)
{
        ChangeRectBounds(ARect);
        for (int I = vImg->Converter->Counts[csEntities]-1; I > 0; --I) {
                TsgDXFEntity *Entity = dynamic_cast<TsgDXFEntity *> (vImg->Converter->Entities[I]);
                if (IsEntityInRect(Entity, ARect))
                        Entity->Color = clRed;
        }
        FDwgNavigator->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChangeRectBounds(TRect& ARect)
{
        if (ARect.Right < ARect.Left){
                long  t = ARect.Left;
                ARect.Right = ARect.Left;
                ARect.Left = t;
        }
        if (ARect.Bottom < ARect.Top) {
                long t = ARect.Top;
                ARect.Top = ARect.Bottom;
                ARect.Bottom = t;
        }
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::IsEntityInRect(Dxfconv::TsgDXFEntity *Entity, const TRect& Rect)
{
        if (IsBadRect(Entity->Box))
                return false;
        TPoint vTL = vImg->GetPoint(Entity->Box.TopLeft);
        TPoint vBR = vImg->GetPoint(Entity->Box.BottomRight);
        return PtInRect(Rect, vTL) && PtInRect(Rect, vBR);
}



aby
Posts: 81
Joined: 21 May 2007, 13:02
Location: Turkey

Post by aby » 09 Mar 2008, 16:34

I am waiting your response.

You can replicate this example in Delphi, if it is difficult for you to replicate in C++. For me it doesn't matter, it is sufficient to get an answer.[?]

Thanks

Aby

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 12 Mar 2008, 08:57

Hi Aby,

We will answer you soon.

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Post Reply