Skip to content

Commit

Permalink
Команда Duplicate; Fix #134
Browse files Browse the repository at this point in the history
  • Loading branch information
zamtmn committed Sep 12, 2024
1 parent 5ffc09b commit 49ba1aa
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 69 deletions.
1 change: 1 addition & 0 deletions cad_source/zcad.pas
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
uzcCommand_LPCSRun,
uzcCommand_Find,
uzcCommand_SpellCheck,
uzcCommand_Duplicate,

uzcenitiesvariablesextender,uzcExtdrLayerControl,uzcExtdrSmartTextEnt,
uzcExtdrIncludingVolume,uzcExtdrSCHConnection,uzcExtdrSCHConnector,
Expand Down
2 changes: 1 addition & 1 deletion cad_source/zcad/commands/uzccommand_copy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@author(Andrey Zubarev <[email protected]>)
}
{$MODE OBJFPC}{$H+}
unit uzccommand_copy;
unit uzcCommand_Copy;
{$INCLUDE zengineconfig.inc}

interface
Expand Down
28 changes: 3 additions & 25 deletions cad_source/zcad/commands/uzccommand_copyclip.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@author(Andrey Zubarev <[email protected]>)
}
{$mode delphi}
unit uzccommand_copyclip;
unit uzcCommand_CopyClip;

{$INCLUDE zengineconfig.inc}

Expand All @@ -32,7 +32,7 @@ interface
uzgldrawcontext,
uzcdrawings,
uzccommandsabstract,uzccommandsimpl,
uzegeometry,uzegeometrytypes;
uzegeometry,uzegeometrytypes,uzcCommand_Duplicate;

const
ZCAD_DXF_CLIPBOARD_NAME='[email protected]';
Expand All @@ -50,7 +50,6 @@ procedure CopyToClipboard;
var
s:ansistring;
suni:unicodestring;
I:integer;
zcformat:TClipboardFormat;
begin
if fileexists(utf8tosys(CopyClipFile)) then
Expand All @@ -61,10 +60,6 @@ procedure CopyToClipboard;
savedxf2000(s,ProgramPath + '/components/empty.dxf',ClipboardDWG^);
s:=s+#0;
suni:=s;
//setlength(suni,length(s)*2+2);
//fillchar(suni[1],length(suni),0);
//for I := 1 to length(s) do
// suni[i*2-1]:=s[i];
Clipboard.Open;
Clipboard.Clear;
zcformat:=RegisterClipboardFormat(ZCAD_DXF_CLIPBOARD_NAME);
Expand Down Expand Up @@ -93,30 +88,13 @@ function CopyClip_com(const Context:TZCADCommandContext;operands:TCommandOperand
pobj,pobjcopy:pGDBObjEntity;
ir:itrec;
DC:TDrawContext;
NeedReCreateClipboardDWG:boolean;
FoundEnts:boolean;
SelectedAABB:TBoundingBox;
m:DMatrix4D;
begin
ClipboardDWG.pObjRoot.ObjArray.free;
dc:=drawings.GetCurrentDwg^.CreateDrawingRC(false,[DCODrawable]);
NeedReCreateClipboardDWG:=true;
FoundEnts:=false;
SelectedAABB:=default(TBoundingBox);

pobj:=drawings.GetCurrentROOT.ObjArray.beginiterate(ir);
if pobj<>nil then repeat
if pobj.selected then begin
if FoundEnts then
ConcatBB(SelectedAABB,pobj.vp.BoundingBox)
else
SelectedAABB:=pobj.vp.BoundingBox;
FoundEnts:=true;
end;
pobj:=drawings.GetCurrentROOT.ObjArray.iterate(ir);
until pobj=nil;

if FoundEnts then begin
if GetSelectedEntsAABB(drawings.GetCurrentROOT.ObjArray,SelectedAABB) then begin
ReCreateClipboardDWG;
m:=CreateTranslationMatrix(-SelectedAABB.LBN{-(SelectedAABB.RTF+SelectedAABB.LBN)/2});
pobj:=drawings.GetCurrentROOT.ObjArray.beginiterate(ir);
Expand Down
2 changes: 1 addition & 1 deletion cad_source/zcad/commands/uzccommand_cutclip.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@author(Andrey Zubarev <[email protected]>)
}
{$mode delphi}
unit uzccommand_cutclip;
unit uzcCommand_CutClip;

{$INCLUDE zengineconfig.inc}

Expand Down
100 changes: 100 additions & 0 deletions cad_source/zcad/commands/uzccommand_duplicate.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
*****************************************************************************
* *
* This file is part of the ZCAD *
* *
* See the file COPYING.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
{
@author(Andrey Zubarev <[email protected]>)
}
{$mode delphi}
unit uzcCommand_Duplicate;

{$INCLUDE zengineconfig.inc}

interface
uses
uzcLog,
SysUtils,
LCLType,LazUTF8,Clipbrd,
uzbpaths,
uzeentity,
uzeffdxf,
gzctnrVectorTypes,
uzgldrawcontext,
uzcdrawings,
uzcstrconsts,
uzccommandsabstract,uzccommandsimpl,UGDBVisibleOpenArray,
uzegeometry,uzegeometrytypes,uzcinterface,uzccommandsmanager,
uzcCommand_Copy,uzglviewareadata;

type
duplicade_com= object(copy_com)
procedure CommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands);virtual;
//function CalcTransformMatrix(p1,p2: GDBvertex):DMatrix4D; virtual;
function AfterClick(const Context:TZCADCommandContext;wc: GDBvertex; mc: GDBvertex2DI; var button: Byte;osp:pos_record): Integer; virtual;
end;
var
duplicade:duplicade_com;

function GetSelectedEntsAABB(constref ObjArray:GDBObjEntityOpenArray;out SelectedAABB:TBoundingBox):boolean;

implementation

function GetSelectedEntsAABB(constref ObjArray:GDBObjEntityOpenArray;out SelectedAABB:TBoundingBox):boolean;
var
pobj:pGDBObjEntity;
ir:itrec;
begin
Result:=False;
SelectedAABB:=default(TBoundingBox);

pobj:=ObjArray.beginiterate(ir);
if pobj<>nil then repeat
if pobj.selected then begin
if Result then
ConcatBB(SelectedAABB,pobj.vp.BoundingBox)
else
SelectedAABB:=pobj.vp.BoundingBox;
Result:=true;
end;
pobj:=ObjArray.iterate(ir);
until pobj=nil;
end;

procedure duplicade_com.CommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands);
var
SelectedAABB:TBoundingBox;
begin
Inherited;
if drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.GetRealCount>0 then begin
GetSelectedEntsAABB(drawings.GetCurrentROOT.ObjArray,SelectedAABB);
t3dp:=SelectedAABB.LBN;
inc(mouseclic);
end else begin
ZCMsgCallBackInterface.TextMessage(rscmSelEntBeforeComm,TMWOHistoryOut);
Commandmanager.executecommandend;
end;
end;

function duplicade_com.AfterClick(const Context:TZCADCommandContext;wc: GDBvertex; mc: GDBvertex2DI; var button: Byte;osp:pos_record): Integer;
begin
inherited;
if (button and MZW_LBUTTON)<>0 then
Commandmanager.executecommandend;
end;

initialization
programlog.LogOutFormatStr('Unit "%s" initialization',[{$INCLUDE %FILE%}],LM_Info,UnitsInitializeLMId);
duplicade.init('Duplicate',0,0);
finalization
ProgramLog.LogOutFormatStr('Unit "%s" finalization',[{$INCLUDE %FILE%}],LM_Info,UnitsFinalizeLMId);
end.
85 changes: 44 additions & 41 deletions cad_source/zcad/commands/uzccommand_move.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@author(Andrey Zubarev <[email protected]>)
}
{$MODE OBJFPC}{$H+}
unit uzccommand_move;
unit uzcCommand_Move;
{$INCLUDE zengineconfig.inc}

interface
Expand Down Expand Up @@ -55,8 +55,10 @@ TCopyObjectDesc=record
move_com = object(CommandRTEdObject)
t3dp: gdbvertex;
pcoa:ptpcoavector;
//constructor init;
procedure CommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands); virtual;
protected
function InternalCommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands):Boolean;virtual;
public
procedure CommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands);virtual;
procedure CommandCancel(const Context:TZCADCommandContext); virtual;
function BeforeClick(const Context:TZCADCommandContext;wc: GDBvertex; mc: GDBvertex2DI; var button: Byte;osp:pos_record): Integer; virtual;
function AfterClick(const Context:TZCADCommandContext;wc: GDBvertex; mc: GDBvertex2DI; var button: Byte;osp:pos_record): Integer; virtual;
Expand All @@ -82,16 +84,14 @@ procedure Move_com.showprompt(mklick:integer);
end;
end;

procedure Move_com.CommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands);
var //i: Integer;
function Move_com.InternalCommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands):Boolean;
var
tv,pobj: pGDBObjEntity;
ir:itrec;
counter:integer;
tcd:TCopyObjectDesc;
dc:TDrawContext;
ir:itrec;
counter:integer;
tcd:TCopyObjectDesc;
dc:TDrawContext;
begin
//self.savemousemode:=drawings.GetCurrentDWG^.wa.param.md.mode;
Inherited;
counter:=0;

pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
Expand All @@ -103,39 +103,42 @@ procedure Move_com.CommandStart(const Context:TZCADCommandContext;Operands:TComm
until pobj=nil;


if counter>0 then
begin
if counter>0 then begin
inherited CommandStart(context,'');
drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
showprompt(0);
dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
Getmem(Pointer(pcoa),sizeof(tpcoavector));
pcoa^.init(counter);
pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
if pobj<>nil then
repeat
begin
if pobj^.selected then
begin
tv := pobj^.Clone({drawings.GetCurrentROOT}@drawings.GetCurrentDWG^.ConstructObjRoot);
if tv<>nil then
begin
tv^.State:=tv^.State+[ESConstructProxy];
drawings.GetCurrentDWG^.ConstructObjRoot.AddMi(@tv);
//ObjArray.AddPEntity(tv^);
tcd.sourceEnt:=pobj;
tcd.tmpProxy:=tv;
tcd.copyEnt:=nil;
pcoa^.PushBackData(tcd);
tv^.formatentity(drawings.GetCurrentDWG^,dc);
end;
end;
end;
pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
until pobj=nil
end
else
begin
dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
Getmem(Pointer(pcoa),sizeof(tpcoavector));
pcoa^.init(counter);
pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
if pobj<>nil then
repeat
if pobj^.selected then begin
tv := pobj^.Clone(@drawings.GetCurrentDWG^.ConstructObjRoot);
if tv<>nil then
begin
tv^.State:=tv^.State+[ESConstructProxy];
drawings.GetCurrentDWG^.ConstructObjRoot.AddMi(@tv);
tcd.sourceEnt:=pobj;
tcd.tmpProxy:=tv;
tcd.copyEnt:=nil;
pcoa^.PushBackData(tcd);
tv^.formatentity(drawings.GetCurrentDWG^,dc);
end;
end;
pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
until pobj=nil;
result:=True;
end else begin
result:=False;
end;

end;

procedure Move_com.CommandStart(const Context:TZCADCommandContext;Operands:TCommandOperands);
begin
Inherited;
if not InternalCommandStart(Context,Operands) then begin
ZCMsgCallBackInterface.TextMessage(rscmSelEntBeforeComm,TMWOHistoryOut);
Commandmanager.executecommandend;
end;
Expand Down
2 changes: 1 addition & 1 deletion cad_source/zcad/commands/uzccommand_pasteclip.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@author(Andrey Zubarev <[email protected]>)
}
{$MODE OBJFPC}{$H+}
unit uzccommand_PasteClip;
unit uzcCommand_PasteClip;
{$INCLUDE zengineconfig.inc}

interface
Expand Down
1 change: 1 addition & 0 deletions environment/runtimefiles/common/menu/actionscontent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ZAction Name="ACN_COPYCLIPBASE" Command="CopyBase" Img="copyclipbase" Caption="Copy to clipboard with base point" ShortCut="CTRL+SHIFT+C" SecondaryShortCuts="CTRL+INS"/>
<ZAction Name="ACN_PASTE" Command="PasteClip" Img="pasteclip" Caption="Paste" Hint="Paste from clipboard" ShortCut="CTRL+V" SecondaryShortCuts="SHIFT+INS"/>
<ZAction Name="ACN_ERASE" Command="Erase" Img="erase" Caption="Erase" ShortCut="DEL"/>
<ZAction Name="ACN_DUPLICATE" Command="Duplicate" Img="#dbl" Caption="Duplicate" ShortCut="CTRL+D"/>
<ZAction Name="ACN_SELECTALL" Command="SelectAll" Img="#SA" Caption="Select all" ShortCut="CTRL+A"/>
<ZAction Name="ACN_INVERSESELECTED" Command="InverseSelected" Img="#SI" Caption="Inverse selected"/>
<ZAction Name="ACN_DESELECTALL" Command="DeSelectAll" Img="#DSA" Caption="DeSelect all" ShortCut="CTRL+SHIFT+A"/>
Expand Down
1 change: 1 addition & 0 deletions environment/runtimefiles/common/menu/menuscontent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<Action Name="ACN_COPYCLIP"/>
<Action Name="ACN_COPYCLIPBASE"/>
<Action Name="ACN_PASTE"/>
<Action Name="ACN_DUPLICATE"/>
<Action Name="ACN_ERASE"/>
<Separator/>
<Action Name="ACN_SELECTALL"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<Action Name="ACN_COPYCLIP"/>
<Action Name="ACN_COPYCLIPBASE"/>
<Action Name="ACN_PASTE"/>
<Action Name="ACN_DUPLICATE"/>
<Action Name="ACN_ERASE"/>
<Separator/>
<Action Name="ACN_SELECTALL"/>
Expand Down

0 comments on commit 49ba1aa

Please sign in to comment.