1 // Created on: 2017-08-09
2 // Created by: Sergey NIKONOV
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <DDocStd.hxx>
17 #include <OSD_File.hxx>
18 #include <OSD_Protection.hxx>
19 #include <TDocStd_Document.hxx>
20 #include <TDF_Tool.hxx>
21 #include <XCAFDoc_AssemblyItemRef.hxx>
22 #include <XCAFDoc_DocumentTool.hxx>
23 #include <XCAFDoc_Note.hxx>
24 #include <XCAFDoc_NoteBalloon.hxx>
25 #include <XCAFDoc_NoteComment.hxx>
26 #include <XCAFDoc_NoteBinData.hxx>
27 #include <XCAFDoc_NotesTool.hxx>
28 #include <XDEDRAW_Notes.hxx>
33 Standard_Integer nargsreq;
37 Draw_Interpretor& operator << (Draw_Interpretor& di, const cmd& c)
39 di << "Use: " << c.use << "\n";
43 Draw_Interpretor& operator << (Draw_Interpretor& di, const TDF_Label& L)
45 TCollection_AsciiString anEntry;
46 TDF_Tool::Entry(L, anEntry);
51 Draw_Interpretor& operator << (Draw_Interpretor& di, const Handle(XCAFDoc_Note)& note)
53 TCollection_AsciiString anEntry;
54 TDF_Tool::Entry(note->Label(), anEntry);
59 Draw_Interpretor& operator << (Draw_Interpretor& di, const Handle(XCAFDoc_AssemblyItemRef)& ref)
61 TCollection_AsciiString anEntry;
62 TDF_Tool::Entry(ref->Label(), anEntry);
67 //=======================================================================
68 //function : noteCount
69 //purpose : returns number of annotated items, notes and orphan notes
70 //=======================================================================
71 static const cmd XNoteCount = {
72 "XNoteCount", 2, "XNoteCount Doc"
74 static Standard_Integer
75 noteCount(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
77 static const cmd& myCommand = XNoteCount;
79 if (argc < myCommand.nargsreq)
85 Handle(TDocStd_Document) aDoc;
86 DDocStd::GetDocument(argv[1], aDoc);
92 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
95 << aNotesTool->NbAnnotatedItems() << " "
96 << aNotesTool->NbNotes() << " "
97 << aNotesTool->NbOrphanNotes()
102 //=======================================================================
103 //function : noteNotes
104 //purpose : returns list of all notes
105 //=======================================================================
106 static const cmd XNoteNotes = {
107 "XNoteNotes", 2, "XNoteNotes Doc"
109 static Standard_Integer
110 noteNotes(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
112 static const cmd& myCommand = XNoteNotes;
114 if (argc < myCommand.nargsreq)
120 Handle(TDocStd_Document) aDoc;
121 DDocStd::GetDocument(argv[1], aDoc);
127 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
129 TDF_LabelSequence aNotes;
130 aNotesTool->GetNotes(aNotes);
131 for (TDF_LabelSequence::Iterator anIt(aNotes); anIt.More(); anIt.Next())
133 Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(anIt.Value());
140 //=======================================================================
141 //function : noteAnnotations
142 //purpose : returns list of all notes
143 //=======================================================================
144 static const cmd XNoteAnnotations = {
145 "XNoteAnnotations", 2, "XNoteAnnotations Doc"
147 static Standard_Integer
148 noteAnnotations(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
150 static const cmd& myCommand = XNoteAnnotations;
152 if (argc < myCommand.nargsreq)
158 Handle(TDocStd_Document) aDoc;
159 DDocStd::GetDocument(argv[1], aDoc);
165 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
167 TDF_LabelSequence aAnnotations;
168 aNotesTool->GetAnnotatedItems(aAnnotations);
169 for (TDF_LabelSequence::Iterator anIt(aAnnotations); anIt.More(); anIt.Next())
171 Handle(XCAFDoc_AssemblyItemRef) aRef = XCAFDoc_AssemblyItemRef::Get(anIt.Value());
178 //=======================================================================
179 //function : noteCreateBalloon
180 //purpose : creates a 'balloon' note and returns a new note entry
181 //=======================================================================
182 static const cmd XNoteCreateBalloon = {
183 "XNoteCreateBalloon", 3, "XNoteCreateBalloon Doc comment [--user name] [--time stamp]"
185 static Standard_Integer
186 noteCreateBalloon(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
188 static const cmd& myCommand = XNoteCreateBalloon;
190 if (argc < myCommand.nargsreq)
196 Standard_Integer iarg = 0;
198 Handle(TDocStd_Document) aDoc;
199 DDocStd::GetDocument(argv[++iarg], aDoc);
205 TCollection_ExtendedString aComment = argv[++iarg];
206 TCollection_ExtendedString aUsername, aTimestamp;
208 for (++iarg; iarg < argc; ++iarg)
210 TCollection_AsciiString opt = argv[iarg];
215 di << "Error: user name is expected.\n" << myCommand;
218 aUsername = argv[iarg];
220 else if (opt == "--time")
224 di << "Error: timestamp is expected.\n" << myCommand;
227 aTimestamp = argv[iarg];
231 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
232 Handle(XCAFDoc_Note) aNote = aNotesTool->CreateBalloon(aUsername, aTimestamp, aComment);
235 di << "Error: couldn't create a comment note.\n";
243 //=======================================================================
244 //function : noteCreateComment
245 //purpose : creates a comment note and returns a new note entry
246 //=======================================================================
247 static const cmd XNoteCreateComment = {
248 "XNoteCreateComment", 3, "XNoteCreateComment Doc comment [--user name] [--time stamp]"
250 static Standard_Integer
251 noteCreateComment(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
253 static const cmd& myCommand = XNoteCreateComment;
255 if (argc < myCommand.nargsreq)
261 Standard_Integer iarg = 0;
263 Handle(TDocStd_Document) aDoc;
264 DDocStd::GetDocument(argv[++iarg], aDoc);
270 TCollection_ExtendedString aComment = argv[++iarg];
271 TCollection_ExtendedString aUsername, aTimestamp;
273 for (++iarg; iarg < argc; ++iarg)
275 TCollection_AsciiString opt = argv[iarg];
280 di << "Error: user name is expected.\n" << myCommand;
283 aUsername = argv[iarg];
285 else if (opt == "--time")
289 di << "Error: timestamp is expected.\n" << myCommand;
292 aTimestamp = argv[iarg];
296 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
297 Handle(XCAFDoc_Note) aNote = aNotesTool->CreateComment(aUsername, aTimestamp, aComment);
300 di << "Error: couldn't create a comment note.\n";
308 //=======================================================================
309 //function : noteCreateBinData
310 //purpose : creates a binary data note and returns a new note entry
311 //=======================================================================
312 static const cmd XNoteCreateBinData = {
313 "XNoteCreateBinData", 5, "XNoteCreateBinData Doc title <--file path | --data data> [--mime type] [--user name] [--time stamp]"
315 static Standard_Integer
316 noteCreateBinData(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
318 static const cmd& myCommand = XNoteCreateBinData;
320 if (argc < myCommand.nargsreq)
326 Standard_Integer iarg = 0;
328 Handle(TDocStd_Document) aDoc;
329 DDocStd::GetDocument(argv[++iarg], aDoc);
335 Standard_Boolean aFromFile = Standard_False;
336 Standard_Boolean aFromData = Standard_False;
337 TCollection_ExtendedString aFilename;
338 Handle(TColStd_HArray1OfByte) aData;
339 TCollection_ExtendedString aTitle = argv[++iarg];
340 TCollection_AsciiString aMIMEtype;
341 TCollection_ExtendedString aUsername, aTimestamp;
343 for (++iarg; iarg < argc; ++iarg)
345 TCollection_AsciiString opt = argv[iarg];
350 di << "Error: data can be taken either from a file or a data array.\n" << myCommand;
355 di << "Error: file path is expected.\n" << myCommand;
358 aFilename = argv[iarg];
359 aFromFile = Standard_True;
361 else if (opt == "--data")
365 di << "Error: data can be taken either from a file or a data array.\n" << myCommand;
370 di << "Error: data array is expected.\n" << myCommand;
373 Standard_SStream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
375 Standard_Integer len = static_cast<Standard_Integer>(ss.tellp());
376 aData = new TColStd_HArray1OfByte(1, len);
377 for (Standard_Integer i = 1; i <= len && !ss.eof(); ++i)
379 ss >> aData->ChangeValue(i);
381 aFromData = Standard_True;
383 else if (opt == "--mime")
387 di << "Error: MIME type is expected.\n" << myCommand;
390 aMIMEtype = argv[iarg];
392 else if (opt == "--user")
396 di << "Error: user name is expected.\n" << myCommand;
399 aUsername = argv[iarg];
401 else if (opt == "--time")
405 di << "Error: timestamp is expected.\n" << myCommand;
408 aTimestamp = argv[iarg];
412 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
414 Handle(XCAFDoc_Note) aNote;
417 OSD_Path aPath(aFilename);
418 OSD_File aFile(aPath);
419 aFile.Open(OSD_ReadOnly, OSD_Protection());
420 aNote = aNotesTool->CreateBinData(aUsername, aTimestamp, aTitle, aMIMEtype, aFile);
424 aNote = aNotesTool->CreateBinData(aUsername, aTimestamp, aTitle, aMIMEtype, aData);
428 di << "Error: data can be taken either from a file or a data array.\n" << myCommand;
434 di << "Error: couldn't create a binary data note.\n";
442 //=======================================================================
443 //function : noteDelete
444 //purpose : deletes a note by the entry
445 //=======================================================================
446 static const cmd XNoteDelete = {
447 "XNoteDelete", 3, "XNoteDelete Doc note"
449 static Standard_Integer
450 noteDelete(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
452 static const cmd& myCommand = XNoteDelete;
454 if (argc < myCommand.nargsreq)
460 Handle(TDocStd_Document) aDoc;
461 DDocStd::GetDocument(argv[1], aDoc);
467 TCollection_ExtendedString anEntry = argv[2];
470 TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
473 di << anEntry << ": invalid note entry.\n";
477 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
478 if (!aNotesTool->DeleteNote(aLabel))
480 di << "Error: couldn't delete note.\n";
487 //=======================================================================
488 //function : noteDeleteAll
489 //purpose : deletes all notes
490 //=======================================================================
491 static const cmd XNoteDeleteAll = {
492 "XNoteDeleteAll", 2, "XNoteDeleteAll Doc"
494 static Standard_Integer
495 noteDeleteAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
497 static const cmd& myCommand = XNoteDeleteAll;
499 if (argc < myCommand.nargsreq)
505 Handle(TDocStd_Document) aDoc;
506 DDocStd::GetDocument(argv[1], aDoc);
512 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
513 Standard_Integer nbDeleted = aNotesTool->DeleteAllNotes();
519 //=======================================================================
520 //function : noteDeleteOrphan
521 //purpose : deletes all orphan notes
522 //=======================================================================
523 static const cmd XNoteDeleteOrphan = {
524 "XNoteDeleteOrphan", 2, "XNoteDeleteOrphan Doc"
526 static Standard_Integer
527 noteDeleteOrphan(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
529 static const cmd& myCommand = XNoteDeleteOrphan;
531 if (argc < myCommand.nargsreq)
537 Handle(TDocStd_Document) aDoc;
538 DDocStd::GetDocument(argv[1], aDoc);
544 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
545 Standard_Integer nbDeleted = aNotesTool->DeleteOrphanNotes();
551 //=======================================================================
553 //purpose : adds a note to a labeled item
554 //=======================================================================
555 static const cmd XNoteAdd = {
556 "XNoteAdd", 4, "XNoteAdd Doc note item [--attr guid | --subshape num]"
558 static Standard_Integer
559 noteAdd(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
561 static const cmd& myCommand = XNoteAdd;
563 if (argc < myCommand.nargsreq)
569 Standard_Integer iarg = 0;
571 Handle(TDocStd_Document) aDoc;
572 DDocStd::GetDocument(argv[++iarg], aDoc);
578 TCollection_AsciiString aNoteEntry = argv[++iarg];
579 TCollection_AsciiString anItemEntry = argv[++iarg];
581 TDF_Label aNoteLabel;
582 TDF_Tool::Label(aDoc->GetData(), aNoteEntry, aNoteLabel);
583 if (aNoteLabel.IsNull())
585 di << aNoteEntry << ": invalid note entry.\n";
588 XCAFDoc_AssemblyItemId anItemId(anItemEntry);
589 TDF_Label anItemLabel;
590 TDF_Tool::Label(aDoc->GetData(), anItemId.GetPath().Last(), anItemLabel);
591 if (anItemLabel.IsNull())
593 di << anItemId.ToString() << ": invalid item id.\n";
598 Standard_Integer aSubshape = 0;
599 Standard_Boolean aHasGUID = Standard_False;
600 Standard_Boolean aHasSubshape = Standard_False;
601 for (++iarg; iarg < argc; ++iarg)
603 TCollection_AsciiString opt = argv[iarg];
608 di << "Error: either attribute guid or subshape index must be specified.\n" << myCommand;
613 di << "Error: attribute guid is expected.\n" << myCommand;
616 TCollection_AsciiString arg = argv[iarg];
617 aGUID = arg.ToCString();
618 aHasGUID = Standard_True;
620 else if (opt == "--subshape")
624 di << "Error: subshape index is expected.\n" << myCommand;
627 TCollection_AsciiString arg = argv[iarg];
628 if (!arg.IsIntegerValue())
630 di << "Error: subshape index must be integer value.\n" << myCommand;
633 aSubshape = arg.IntegerValue();
634 aHasSubshape = Standard_True;
638 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
640 Handle(XCAFDoc_AssemblyItemRef) aRef;
643 aRef = aNotesTool->AddNoteToAttr(aNoteLabel, anItemId, aGUID);
645 else if (aHasSubshape)
647 aRef = aNotesTool->AddNoteToSubshape(aNoteLabel, anItemId, aSubshape);
651 aRef = aNotesTool->AddNote(aNoteLabel, anItemId);
656 di << "Error: couldn't add note.\n";
660 if (aRef->IsOrphan())
662 di << "Error: annotated item is invalid\n";
670 //=======================================================================
671 //function : noteRemove
672 //purpose : removes a note from a labeled item
673 //=======================================================================
674 static const cmd XNoteRemove = {
675 "XNoteRemove", 4, "XNoteRemove Doc item note [--attr guid | --subshape num] [--del-orphan]"
677 static Standard_Integer
678 noteRemove(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
680 static const cmd& myCommand = XNoteRemove;
682 if (argc < myCommand.nargsreq)
688 Standard_Integer iarg = 0;
690 Handle(TDocStd_Document) aDoc;
691 DDocStd::GetDocument(argv[++iarg], aDoc);
697 TCollection_AsciiString anItemEntry = argv[++iarg];
698 TCollection_AsciiString aNoteEntry = argv[++iarg];
700 TDF_Label aNoteLabel;
701 TDF_Tool::Label(aDoc->GetData(), aNoteEntry, aNoteLabel);
702 if (aNoteLabel.IsNull())
704 di << aNoteEntry << ": invalid note entry.\n";
707 XCAFDoc_AssemblyItemId anItemId(anItemEntry);
708 TDF_Label anItemLabel;
709 TDF_Tool::Label(aDoc->GetData(), anItemId.GetPath().Last(), anItemLabel);
710 if (anItemLabel.IsNull())
712 di << anItemId.ToString() << ": invalid item id.\n";
717 Standard_Integer aSubshape = 0;
718 Standard_Boolean aHasGUID = Standard_False;
719 Standard_Boolean aHasSubshape = Standard_False;
720 Standard_Boolean aDelOrphan = Standard_False;
721 for (++iarg; iarg < argc; ++iarg)
723 TCollection_AsciiString opt = argv[iarg];
728 di << "Error: either attribute guid or subshape index must be specified.\n" << myCommand;
733 di << "Error: attribute guid is expected.\n" << myCommand;
736 TCollection_AsciiString arg = argv[iarg];
737 aGUID = arg.ToCString();
738 aHasGUID = Standard_True;
740 else if (opt == "--subshape")
744 di << "Error: either attribute guid or subshape index must be specified.\n" << myCommand;
749 di << "Error: subshape index is expected.\n" << myCommand;
752 TCollection_AsciiString arg = argv[iarg];
753 if (!arg.IsIntegerValue())
755 di << "Error: subshape index must be integer value.\n" << myCommand;
758 aSubshape = arg.IntegerValue();
759 aHasSubshape = Standard_True;
761 else if (opt == "--del-orphan")
763 aDelOrphan = Standard_True;
767 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
771 di << aNotesTool->RemoveAttrNote(aNoteLabel, anItemId, aGUID, aDelOrphan);
773 else if (aHasSubshape)
775 di << aNotesTool->RemoveSubshapeNote(aNoteLabel, anItemId, aSubshape, aDelOrphan);
779 di << aNotesTool->RemoveNote(aNoteLabel, anItemId, aDelOrphan);
785 //=======================================================================
786 //function : noteRemoveAll
787 //purpose : removes all notes from a labeled item
788 //=======================================================================
789 static const cmd XNoteRemoveAll = {
790 "XNoteRemoveAll", 3, "XNoteRemoveAll Doc item [--attr guid] [--subshape num] [--del-orphan]"
792 static Standard_Integer
793 noteRemoveAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
795 static const cmd& myCommand = XNoteRemoveAll;
797 if (argc < myCommand.nargsreq)
803 Standard_Integer iarg = 0;
805 Handle(TDocStd_Document) aDoc;
806 DDocStd::GetDocument(argv[++iarg], aDoc);
812 TCollection_AsciiString anItemEntry = argv[++iarg];
814 XCAFDoc_AssemblyItemId anItemId(anItemEntry);
815 TDF_Label anItemLabel;
816 TDF_Tool::Label(aDoc->GetData(), anItemId.GetPath().Last(), anItemLabel);
817 if (anItemLabel.IsNull())
819 di << anItemId.ToString() << ": invalid item id.\n";
824 Standard_Integer aSubshape = 0;
825 Standard_Boolean aHasGUID = Standard_False;
826 Standard_Boolean aHasSubshape = Standard_False;
827 Standard_Boolean aDelOrphan = Standard_False;
828 for (++iarg; iarg < argc; ++iarg)
830 TCollection_AsciiString opt = argv[iarg];
835 di << "Error: either attribute guid or subshape index must be specified.\n" << myCommand;
840 di << "Error: attribute guid is expected.\n" << myCommand;
843 TCollection_AsciiString arg = argv[iarg];
844 aGUID = arg.ToCString();
845 aHasGUID = Standard_True;
847 else if (opt == "--subshape")
851 di << "Error: either attribute guid or subshape index must be specified.\n" << myCommand;
856 di << "Error: subshape index is expected.\n" << myCommand;
859 TCollection_AsciiString arg = argv[iarg];
860 if (!arg.IsIntegerValue())
862 di << "Error: subshape index must be integer value.\n" << myCommand;
865 aSubshape = arg.IntegerValue();
866 aHasSubshape = Standard_True;
868 else if (opt == "--del-orphan")
870 aDelOrphan = Standard_True;
874 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
878 di << aNotesTool->RemoveAllAttrNotes(anItemId, aGUID, aDelOrphan);
880 else if (aHasSubshape)
882 di << aNotesTool->RemoveAllSubshapeNotes(anItemId, aSubshape, aDelOrphan);
886 di << aNotesTool->RemoveAllNotes(anItemId, aDelOrphan);
892 //=======================================================================
893 //function : noteFindAnnotated
894 //purpose : find a label of the annotated item
895 //=======================================================================
896 static const cmd XNoteFindAnnotated = {
897 "XNoteFindAnnotated", 3, "XNoteFindAnnotated Doc item [--attr guid | --subshape num]"
899 static Standard_Integer
900 noteFindAnnotated(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
902 static const cmd& myCommand = XNoteFindAnnotated;
904 if (argc < myCommand.nargsreq)
910 Standard_Integer iarg = 0;
912 Handle(TDocStd_Document) aDoc;
913 DDocStd::GetDocument(argv[++iarg], aDoc);
919 TCollection_AsciiString anItemEntry = argv[++iarg];
921 XCAFDoc_AssemblyItemId anItemId(anItemEntry);
922 TDF_Label anItemLabel;
923 TDF_Tool::Label(aDoc->GetData(), anItemId.GetPath().Last(), anItemLabel);
924 if (anItemLabel.IsNull())
926 di << anItemId.ToString() << ": invalid item id.\n";
931 Standard_Integer aSubshape = 0;
932 Standard_Boolean aHasGUID = Standard_False;
933 Standard_Boolean aHasSubshape = Standard_False;
934 for (++iarg; iarg < argc; ++iarg)
936 TCollection_AsciiString opt = argv[iarg];
941 di << "Error: either attribute guid or subshape index must be specified.\n" << myCommand;
946 di << "Error: attribute guid is expected.\n" << myCommand;
949 TCollection_AsciiString arg = argv[iarg];
950 aGUID = arg.ToCString();
951 aHasGUID = Standard_True;
953 else if (opt == "--subshape")
957 di << "Error: subshape index is expected.\n" << myCommand;
960 TCollection_AsciiString arg = argv[iarg];
961 if (!arg.IsIntegerValue())
963 di << "Error: subshape index must be integer value.\n" << myCommand;
966 aSubshape = arg.IntegerValue();
967 aHasSubshape = Standard_True;
971 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
975 di << aNotesTool->FindAnnotatedItemAttr(anItemId, aGUID);
977 else if (aHasSubshape)
979 di << aNotesTool->FindAnnotatedItemSubshape(anItemId, aSubshape);
983 di << aNotesTool->FindAnnotatedItem(anItemId);
989 //=======================================================================
990 //function : noteGetNotes
991 //purpose : get notes of the labeled item
992 //=======================================================================
993 static const cmd XNoteGetNotes = {
994 "XNoteGetNotes", 3, "XNoteGetNotes Doc item [--attr guid | --subshape num]"
996 static Standard_Integer
997 noteGetNotes(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
999 static const cmd& myCommand = XNoteGetNotes;
1001 if (argc < myCommand.nargsreq)
1007 Standard_Integer iarg = 0;
1009 Handle(TDocStd_Document) aDoc;
1010 DDocStd::GetDocument(argv[++iarg], aDoc);
1016 TCollection_AsciiString anItemEntry = argv[++iarg];
1018 XCAFDoc_AssemblyItemId anItemId(anItemEntry);
1019 TDF_Label anItemLabel;
1020 TDF_Tool::Label(aDoc->GetData(), anItemId.GetPath().Last(), anItemLabel);
1021 if (anItemLabel.IsNull())
1023 di << anItemId.ToString() << ": invalid item id.\n";
1027 Standard_GUID aGUID;
1028 Standard_Integer aSubshape = 0;
1029 Standard_Boolean aHasGUID = Standard_False;
1030 Standard_Boolean aHasSubshape = Standard_False;
1031 for (++iarg; iarg < argc; ++iarg)
1033 TCollection_AsciiString opt = argv[iarg];
1034 if (opt == "--attr")
1038 di << "Error: either attribute guid or subshape index must be specified.\n" << myCommand;
1043 di << "Error: attribute guid is expected.\n" << myCommand;
1046 TCollection_AsciiString arg = argv[iarg];
1047 aGUID = arg.ToCString();
1048 aHasGUID = Standard_True;
1050 else if (opt == "--subshape")
1054 di << "Error: subshape index is expected.\n" << myCommand;
1057 TCollection_AsciiString arg = argv[iarg];
1058 if (!arg.IsIntegerValue())
1060 di << "Error: subshape index must be integer value.\n" << myCommand;
1063 aSubshape = arg.IntegerValue();
1064 aHasSubshape = Standard_True;
1068 Handle(XCAFDoc_NotesTool) aNotesTool = XCAFDoc_DocumentTool::NotesTool(aDoc->Main());
1070 TDF_LabelSequence aNotes;
1073 aNotesTool->GetAttrNotes(anItemId, aGUID, aNotes);
1075 else if (aHasSubshape)
1077 aNotesTool->GetSubshapeNotes(anItemId, aSubshape, aNotes);
1081 aNotesTool->GetNotes(anItemId, aNotes);
1084 for (TDF_LabelSequence::Iterator anIt(aNotes); anIt.More(); anIt.Next())
1086 di << anIt.Value() << " ";
1092 //=======================================================================
1093 //function : noteUsername
1094 //purpose : gets a note username
1095 //=======================================================================
1096 static const cmd XNoteUsername = {
1097 "XNoteUsername", 3, "XNoteUsername Doc note"
1099 static Standard_Integer
1100 noteUsername(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1102 static const cmd& myCommand = XNoteUsername;
1104 if (argc < myCommand.nargsreq)
1110 Standard_Integer iarg = 0;
1112 Handle(TDocStd_Document) aDoc;
1113 DDocStd::GetDocument(argv[++iarg], aDoc);
1119 TCollection_AsciiString aNoteEntry = argv[++iarg];
1121 TDF_Label aNoteLabel;
1122 TDF_Tool::Label(aDoc->GetData(), aNoteEntry, aNoteLabel);
1123 if (aNoteLabel.IsNull())
1125 di << aNoteEntry << ": invalid note entry.\n";
1129 Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(aNoteLabel);
1132 di << aNoteEntry << ": not a note entry.\n";
1136 di << aNote->UserName();
1141 //=======================================================================
1142 //function : noteTimestamp
1143 //purpose : gets a note timestamp
1144 //=======================================================================
1145 static const cmd XNoteTimestamp = {
1146 "XNoteTimestamp", 3, "XNoteTimestamp Doc note"
1148 static Standard_Integer
1149 noteTimestamp(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1151 static const cmd& myCommand = XNoteTimestamp;
1153 if (argc < myCommand.nargsreq)
1159 Standard_Integer iarg = 0;
1161 Handle(TDocStd_Document) aDoc;
1162 DDocStd::GetDocument(argv[++iarg], aDoc);
1168 TCollection_AsciiString aNoteEntry = argv[++iarg];
1170 TDF_Label aNoteLabel;
1171 TDF_Tool::Label(aDoc->GetData(), aNoteEntry, aNoteLabel);
1172 if (aNoteLabel.IsNull())
1174 di << aNoteEntry << ": invalid note entry.\n";
1178 Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(aNoteLabel);
1181 di << aNoteEntry << ": not a note entry.\n";
1185 di << aNote->TimeStamp();
1190 //=======================================================================
1191 //function : noteDump
1192 //purpose : dump a note contents
1193 //=======================================================================
1194 static const cmd XNoteDump = {
1195 "XNoteDump", 3, "XNoteDump Doc note"
1197 static Standard_Integer
1198 noteDump(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1200 static const cmd& myCommand = XNoteDump;
1202 if (argc < myCommand.nargsreq)
1208 Standard_Integer iarg = 0;
1210 Handle(TDocStd_Document) aDoc;
1211 DDocStd::GetDocument(argv[++iarg], aDoc);
1217 TCollection_AsciiString aNoteEntry = argv[++iarg];
1219 TDF_Label aNoteLabel;
1220 TDF_Tool::Label(aDoc->GetData(), aNoteEntry, aNoteLabel);
1221 if (aNoteLabel.IsNull())
1223 di << aNoteEntry << ": invalid note entry.\n";
1227 Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(aNoteLabel);
1230 di << aNoteEntry << ": not a note entry.\n";
1234 di << "Username : " << aNote->UserName() << "\n";
1235 di << "Timestamp : " << aNote->TimeStamp() << "\n";
1236 di << "Type : " << aNote->get_type_name() << "\n";
1237 if (Handle(XCAFDoc_NoteComment) aComment = Handle(XCAFDoc_NoteComment)::DownCast(aNote))
1239 di << "Comment : " << aComment->Comment() << "\n";
1241 else if (Handle(XCAFDoc_NoteBalloon) aBalloon = Handle(XCAFDoc_NoteBalloon)::DownCast(aNote))
1243 di << "Comment : " << aBalloon->Comment() << "\n";
1245 else if (Handle(XCAFDoc_NoteBinData) aBinData = Handle(XCAFDoc_NoteBinData)::DownCast(aNote))
1247 di << "Title : " << aBinData->Title() << "\n";
1248 di << "MIME type : " << aBinData->MIMEtype() << "\n";
1249 di << "Size : " << aBinData->Size() << "\n";
1250 static Standard_Integer theMaxLen = 64;
1251 const Handle(TColStd_HArray1OfByte)& aData = aBinData->Data();
1252 if (!aData.IsNull())
1255 Standard_Integer aLen = Min(aData->Length(), theMaxLen);
1256 for (Standard_Integer i = 1; i <= aLen; ++i)
1258 Standard_SStream ss; ss << aData->Value(i);
1259 di << ss.str().c_str();
1261 if (aData->Length() > theMaxLen)
1267 Handle(XCAFNoteObjects_NoteObject) aNoteObj = aNote->GetObject();
1268 if (!aNoteObj.IsNull())
1270 di << "text point : ";
1271 if (aNoteObj->HasPointText())
1273 const gp_Pnt& aP = aNoteObj->GetPointText();
1274 di << "[ " << aP.X() << " " << aP.Y() << " " << aP.Z() << " ]\n";
1277 di << " not specified\n";
1279 if (aNoteObj->HasPlane())
1281 const gp_Ax2& anAx = aNoteObj->GetPlane();
1282 const gp_Pnt& aP = anAx.Location();
1283 di << "P : [ " << aP.X() << " " << aP.Y() << " " << aP.Z() << " ]";
1284 const gp_Dir& aN = anAx.Direction();
1285 di << "N : [ " << aN.X() << " " << aN.Y() << " " << aN.Z() << " ]";
1287 di << "attachment point : ";
1288 if (aNoteObj->HasPoint())
1290 const gp_Pnt& aP = aNoteObj->GetPoint();
1291 di << "[ " << aP.X() << " " << aP.Y() << " " << aP.Z() << " ]\n";
1294 di << " not specified\n";
1295 di << "presentation : " << (aNoteObj->GetPresentation().IsNull() ? "no" : "specified");
1301 //=======================================================================
1302 //function : noteIsRefOrphan
1303 //purpose : checks if a ref is orphan
1304 //=======================================================================
1305 static const cmd XNoteRefDump = {
1306 "XNoteRefDump", 3, "XNoteRefDump Doc ref"
1308 static Standard_Integer
1309 noteRefDump(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1311 static const cmd& myCommand = XNoteRefDump;
1313 if (argc < myCommand.nargsreq)
1319 Standard_Integer iarg = 0;
1321 Handle(TDocStd_Document) aDoc;
1322 DDocStd::GetDocument(argv[++iarg], aDoc);
1328 TCollection_AsciiString aRefEntry = argv[++iarg];
1330 TDF_Label aRefLabel;
1331 TDF_Tool::Label(aDoc->GetData(), aRefEntry, aRefLabel);
1332 if (aRefLabel.IsNull())
1334 di << aRefEntry << ": invalid reference entry.\n";
1338 Handle(XCAFDoc_AssemblyItemRef) aRef = XCAFDoc_AssemblyItemRef::Get(aRefLabel);
1341 di << aRefEntry << ": not a reference entry.\n";
1345 di << "Item : " << aRef->GetItem().ToString() << "\n";
1346 if (aRef->HasExtraRef())
1350 Standard_SStream ss;
1351 aRef->GetGUID().ShallowDump(ss);
1352 di << "Attribute : " << ss.str().c_str() << "\n";
1354 else if (aRef->IsSubshapeIndex())
1355 di << "Subshape : " << aRef->GetSubshapeIndex() << "\n";
1357 di << "Orphan : " << (aRef->IsOrphan() ? "yes" : "no") << "\n";
1362 //=======================================================================
1363 //function : noteIsRefOrphan
1364 //purpose : checks if a ref is orphan
1365 //=======================================================================
1366 static const cmd XNoteIsRefOrphan = {
1367 "XNoteIsRefOrphan", 3, "XNoteIsRefOrphan Doc ref"
1369 static Standard_Integer
1370 noteIsRefOrphan(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1372 static const cmd& myCommand = XNoteIsRefOrphan;
1374 if (argc < myCommand.nargsreq)
1380 Standard_Integer iarg = 0;
1382 Handle(TDocStd_Document) aDoc;
1383 DDocStd::GetDocument(argv[++iarg], aDoc);
1389 TCollection_AsciiString aRefEntry = argv[++iarg];
1391 TDF_Label aRefLabel;
1392 TDF_Tool::Label(aDoc->GetData(), aRefEntry, aRefLabel);
1393 if (aRefLabel.IsNull())
1395 di << aRefEntry << ": invalid reference entry.\n";
1399 Handle(XCAFDoc_AssemblyItemRef) aRef = XCAFDoc_AssemblyItemRef::Get(aRefLabel);
1402 di << aRefEntry << ": not a reference entry.\n";
1406 di << aRef->IsOrphan();
1411 //=======================================================================
1412 //function : InitCommands
1414 //=======================================================================
1415 void XDEDRAW_Notes::InitCommands(Draw_Interpretor& di)
1417 static Standard_Boolean initialized = Standard_False;
1422 initialized = Standard_True;
1424 Standard_CString g = "XDE Notes commands";
1426 di.Add(XNoteCount.name, XNoteCount.use,
1427 __FILE__, noteCount, g);
1428 di.Add(XNoteNotes.name, XNoteNotes.use,
1429 __FILE__, noteNotes, g);
1430 di.Add(XNoteAnnotations.name, XNoteAnnotations.use,
1431 __FILE__, noteAnnotations, g);
1433 di.Add(XNoteCreateBalloon.name, XNoteCreateBalloon.use,
1434 __FILE__, noteCreateBalloon, g);
1435 di.Add(XNoteCreateComment.name, XNoteCreateComment.use,
1436 __FILE__, noteCreateComment, g);
1437 di.Add(XNoteCreateBinData.name, XNoteCreateBinData.use,
1438 __FILE__, noteCreateBinData, g);
1439 di.Add(XNoteDelete.name, XNoteDelete.use,
1440 __FILE__, noteDelete, g);
1441 di.Add(XNoteDeleteAll.name, XNoteDeleteAll.use,
1442 __FILE__, noteDeleteAll, g);
1443 di.Add(XNoteDeleteOrphan.name, XNoteDeleteOrphan.use,
1444 __FILE__, noteDeleteOrphan, g);
1446 di.Add(XNoteAdd.name, XNoteAdd.use,
1447 __FILE__, noteAdd, g);
1448 di.Add(XNoteRemove.name, XNoteRemove.use,
1449 __FILE__, noteRemove, g);
1450 di.Add(XNoteRemoveAll.name, XNoteRemoveAll.use,
1451 __FILE__, noteRemoveAll, g);
1453 di.Add(XNoteFindAnnotated.name, XNoteFindAnnotated.use,
1454 __FILE__, noteFindAnnotated, g);
1455 di.Add(XNoteGetNotes.name, XNoteGetNotes.use,
1456 __FILE__, noteGetNotes, g);
1458 di.Add(XNoteUsername.name, XNoteUsername.use,
1459 __FILE__, noteUsername, g);
1460 di.Add(XNoteTimestamp.name, XNoteTimestamp.use,
1461 __FILE__, noteTimestamp, g);
1462 di.Add(XNoteDump.name, XNoteDump.use,
1463 __FILE__, noteDump, g);
1465 di.Add(XNoteRefDump.name, XNoteRefDump.use,
1466 __FILE__, noteRefDump, g);
1467 di.Add(XNoteIsRefOrphan.name, XNoteIsRefOrphan.use,
1468 __FILE__, noteIsRefOrphan, g);