Skip to content

Commit aa34a91

Browse files
author
Nicole Aucoin
committed
ENH: add the pointfile flag
Add the pointfile flag to support reading and writing fiducial files to and from CLIs. Issue #2979
1 parent 18cdc5a commit aa34a91

File tree

1 file changed

+101
-1
lines changed

1 file changed

+101
-1
lines changed

ModuleDescriptionParser/ModuleDescriptionParser.cxx

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ startElement(void *userData, const char *element, const char **attrs)
7878
ps->LastData[ps->Depth].clear();
7979

8080
// Check for a valid module description file
81-
//
81+
//
8282
if (ps->Depth == 0 && (name != "executable") )
8383
{
8484
std::string error("ModuleDescriptionParser Error: <executable> must be the outer most tag. <" + name + std::string("> was found instead."));
@@ -513,6 +513,97 @@ startElement(void *userData, const char *element, const char **attrs)
513513
}
514514
parameter->SetTag(name);
515515
}
516+
else if (name == "pointfile")
517+
{
518+
if (!group || (ps->OpenTags.top() != "parameters"))
519+
{
520+
std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
521+
if (ps->ErrorDescription.size() == 0)
522+
{
523+
ps->ErrorDescription = error;
524+
ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
525+
ps->Error = true;
526+
}
527+
ps->OpenTags.push(name);
528+
delete parameter;
529+
return;
530+
}
531+
parameter = new ModuleParameter;
532+
int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
533+
534+
// Parse attribute pairs
535+
parameter->SetCPPType("std::string");
536+
parameter->SetType("scalar");
537+
for (int attr=0; attr < (attrCount / 2); attr++)
538+
{
539+
if ((strcmp(attrs[2*attr], "multiple") == 0))
540+
{
541+
if ((strcmp(attrs[2*attr+1], "true") == 0) ||
542+
(strcmp(attrs[2*attr+1], "false") == 0))
543+
{
544+
parameter->SetMultiple(attrs[2*attr+1]);
545+
if (strcmp(attrs[2*attr+1], "true") == 0)
546+
{
547+
parameter->SetCPPType("std::vector<std::string>");
548+
parameter->SetArgType("std::string");
549+
}
550+
}
551+
else
552+
{
553+
std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
554+
if (ps->ErrorDescription.size() == 0)
555+
{
556+
ps->ErrorDescription = error;
557+
ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
558+
ps->Error = true;
559+
}
560+
ps->OpenTags.push(name);
561+
delete parameter;
562+
return;
563+
}
564+
}
565+
else if ((strcmp(attrs[2*attr], "fileExtensions") == 0))
566+
{
567+
parameter->SetFileExtensionsAsString(attrs[2*attr+1]);
568+
}
569+
else if ((strcmp(attrs[2*attr], "coordinateSystem") == 0))
570+
{
571+
if ((strcmp(attrs[2*attr+1], "ijk") == 0) ||
572+
(strcmp(attrs[2*attr+1], "lps") == 0) ||
573+
(strcmp(attrs[2*attr+1], "ras") == 0))
574+
{
575+
parameter->SetCoordinateSystem(attrs[2*attr+1]);
576+
}
577+
else
578+
{
579+
std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid coordinate system. Only \"ijk\", \"lps\" and \"ras\" are accepted.");
580+
if (ps->ErrorDescription.size() == 0)
581+
{
582+
ps->ErrorDescription = error;
583+
ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
584+
ps->Error = true;
585+
}
586+
ps->OpenTags.push(name);
587+
delete parameter;
588+
return;
589+
}
590+
}
591+
else
592+
{
593+
std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr]) + "\" is not a valid attribute for \"" + name + "\". Only \"multiple\" and \"fileExtensions\" are accepted.");
594+
if (ps->ErrorDescription.size() == 0)
595+
{
596+
ps->ErrorDescription = error;
597+
ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
598+
ps->Error = true;
599+
}
600+
ps->OpenTags.push(name);
601+
delete parameter;
602+
return;
603+
}
604+
}
605+
parameter->SetTag(name);
606+
}
516607
else if (name == "region")
517608
{
518609
if (!group || (ps->OpenTags.top() != "parameters"))
@@ -1623,6 +1714,15 @@ endElement(void *userData, const char *element)
16231714
}
16241715
ps->CurrentParameter = 0;
16251716
}
1717+
else if (group && parameter && (name == "pointfile"))
1718+
{
1719+
ps->CurrentGroup->AddParameter(*parameter);
1720+
if (ps->CurrentParameter)
1721+
{
1722+
delete ps->CurrentParameter;
1723+
}
1724+
ps->CurrentParameter = 0;
1725+
}
16261726
else if (group && parameter && (name == "region"))
16271727
{
16281728
ps->CurrentGroup->AddParameter(*parameter);

0 commit comments

Comments
 (0)