示例#1
0
void MSCheckPopupMenu::updateData(void)
{
  if (MSView::model()!=0)
   {
     freeze();
     const MSStringVector& aStringVector=stringVector();
     unsigned currentCount(itemCount());
     unsigned i;
     MSWidgetVector itemVector(children());
     MSCheckMenuItem *pMenuItem;
     for (i=0;i<aStringVector.length();i++)
      {
	if (i<itemVector.length())
	 {
           pMenuItem=(MSCheckMenuItem *)itemVector(i);
	   pMenuItem->label(aStringVector(i));
	   pMenuItem->state(MSFalse);
	 }
	else 
	  {
	    pMenuItem=new MSCheckMenuItem(this,aStringVector(i),0,i);
	    pMenuItem->selectColor(_selectColor);
	  }
	setItem(pMenuItem,i);
      }
     for (i=aStringVector.length();i<itemVector.length();i++)
      {
	pMenuItem=(MSCheckMenuItem *)itemVector(i);
	delete pMenuItem;
      }
     unfreeze();
     computeSize();
   }
  else removeAllItems();
}
示例#2
0
void MSStringPopupMenu::receiveEvent(MSEvent& aEvent_)
{
  if (aEvent_.type()==MSIndexedEvent::symbol())
   {
     MSIndexedEvent& aIndexedEvent=(MSIndexedEvent&)aEvent_;
     const MSIndexVector& aIndexVector=aIndexedEvent.index();
     if (aIndexVector.length()==0) updateData();
     else 
      {
	const MSStringVector& aStringVector=stringVector();
	unsigned currentCount(itemCount());
	if (aStringVector.length()!=currentCount) updateData();
	else
	 {
	   MSMenuItem *pMenuItem;
	   for (unsigned i=0;i<aIndexVector.length();i++)
	    {
	      pMenuItem=menuItem(aIndexVector(i));
	      if (pMenuItem!=0) pMenuItem->label(aStringVector(aIndexVector(i)));
	    }
	 }
      }
   }
  else updateData();
}
示例#3
0
// splits a string into a vector of strings delimited by white space
std::vector<std::string> tokenizeString(std::string input)
{
	std::stringstream stringStream(input);
	std::istream_iterator<std::string> begin(stringStream);
	std::istream_iterator<std::string> end;
	std::vector<std::string> stringVector(begin, end);
	return stringVector;
}
示例#4
0
	// This should be private
	// Split a string of numbers into a vector
	std::vector <int> parsedNum(std::string numString)
	{
		// Declare char vector and set each index to the equivelent index of numString
		std::vector<char> stringVector(numString.begin(), numString.end());
		
		// Declare int vector
		std::vector<int> largeNumber;
		
		// convert char from char-vector to int and assign to int-vector
		int x;
		for (int i = 0; i < numString.length(); i ++)
		{
			x = (int)stringVector.at(i) - 48;
			std::cout<<x<< std::endl;
			largeNumber.emplace_back(x);
		}
		
		// empty the string vector
		stringVector.clear();
		
		return largeNumber;
	}
bool
ProgrammableOpAttributes::SetupPipeline(const JSONNode& atts, stringVector& args, const std::string& parent)
{
    if(atts.GetType() != JSONNode::JSONARRAY)
        return false;

    const JSONNode::JSONArray& array = atts.GetArray();

    for(int i = 0; i < array.size(); ++i)
    {
        /// need key, value pair
        /// this can be in the form of a dictionary, "a = b", pair tuple (a,b), or a pair array [a,b]
        JSONNode node = array[i];
        JSONNode key,value;
        if(node.GetType() == JSONNode::JSONARRAY)
        {
            if(node.GetArray().size() != 2) continue;

            key = node.GetArray()[0];
            value = node.GetArray()[1];
        }
        else if(node.GetType() == JSONNode::JSONOBJECT)
        {
            /// parse through dictionary and compute arguments from names..
            const JSONNode::JSONObject& obj = node.GetJsonObject();
            if(obj.size() != 1) continue;

            const JSONNode::JSONObject::const_iterator itr = obj.begin();
            key = itr->first;
            value = itr->second;
        }
        else if(node.GetType() == JSONNode::JSONSTRING)
        {
            std::string pair = node.GetString();
            int index = pair.find("=");
            if(index == std::string::npos) continue;
            key = pair.substr(0,index);

            value = trim(pair.substr(index+1));
         }

        if(key.GetType() != JSONNode::JSONSTRING) continue;

        std::string keystr = trim(key.GetString());

        std::ostringstream str;
        str << "import json\n";
        if(value.GetType() == JSONNode::JSONSTRING)
        {
            std::string v = trim(value.GetString());

            ///character at 0 and has :
            if(v.find(":") != std::string::npos && v.find(":") == 0)
            {
                /// optionally handle whether it can be as_vtkarray, as_ndarray, or as_rarray

                size_t index = v.find(":as_ndarray");

                if(index == std::string::npos)
                    index = v.find(":as_rarray");

                if(index != std::string::npos)
                {
                    std::string newName = getNextName();
                    v = v.substr(0,index);
                    AddNode(newName, "as_ndarray");
                    AddConnection(v, newName, "in");
                    AddConnection(newName,parent,keystr);
                }
                else
                {
                    index = v.find(":as_vtkarray");
                    if(index != std::string::npos)
                        v = v.substr(0,index);
                    AddConnection(v,parent,keystr);
                }
            }
            else
            {
                std::string escapedCode = trim(value.GetString());
                replace(escapedCode,"\n","\\\n");
                replace(escapedCode,"'","\"");
                escapedCode = "'" + escapedCode + "'";

                str << "try:\n"
                    << " a = json.loads(" << escapedCode << ")\n"
                    << "except:\n"
                    << " a = " << escapedCode << "\n"
                    << "setout(a)\n";

                AddPythonScript(keystr,stringVector(),str.str());
                AddNode(keystr,keystr);
                AddConnection(keystr,parent,keystr);
            }
        }
        else
        {
            str << "setout(json.loads('" << trim(value.ToString()) << "'))\n";

            AddPythonScript(keystr,stringVector(),str.str());
            AddNode(keystr,keystr);
            AddConnection(keystr,parent,keystr);
        }
        args.push_back(keystr);
    }
    return true;
}
bool
AccessViewerSession::GetSourceMap(stringVector &keys, stringVector &values,
    std::map<std::string, stringVector> &uses)
{
    const char *mName = "AccessViewerSession::GetSourceMap: ";

    DataNode *vsNode = GetVSNode();
    bool ret = false;
    if(vsNode != 0)
    {
        DataNode *smNode = vsNode->GetNode("SourceMap");
        if(smNode != 0)
        {
            keys.clear();
            values.clear();

            DataNode **children = smNode->GetChildren();
            for(int i = 0; i < smNode->GetNumChildren(); ++i)
            {
                if(children[i]->GetNodeType() == STRING_NODE)
                {
                    keys.push_back(children[i]->GetKey());
                    values.push_back(children[i]->AsString());
                }
            }

            ret = keys.size() > 0;            
        }
        else
        {
            debug1 << mName << "Could not find SourceMap node." << endl;
        }

        // NOTE: This section knows a lot about viewer session files, which
        //       means that if the viewer session format changes then this
        //       code must also change.
        //
        // Look through the plots in the session file and determine
        // where each source is used so we can give a little more
        // information to the user.
        DataNode *wmNode = vsNode->GetNode("ViewerWindowManager");
        if(wmNode != 0)
        {
            DataNode *winNode = wmNode->GetNode("Windows");
            if(winNode != 0)
            {
                DataNode **wins = winNode->GetChildren();
                for(int i = 0; i < winNode->GetNumChildren(); ++i)
                {
                    if(wins[i]->GetNodeType() == INTERNAL_NODE &&
                       wins[i]->GetKey() == "ViewerWindow")
                    {
                        DataNode *vpl = wins[i]->GetNode("ViewerPlotList");
                        if(vpl != 0)
                        {
                            char tmp[1000];
                            int ploti = 0;
                            DataNode *plotNode = 0;
                            do
                            {
                                SNPRINTF(tmp, 1000, "plot%02d", ploti++);
                                plotNode = vpl->GetNode(tmp);
                                if(plotNode != 0)
                                {
                                    DataNode *pluginIDNode = 0,
                                             *varNameNode = 0,
                                             *sourceIDNode = 0;
                                    pluginIDNode = plotNode->GetNode("pluginID");
                                    sourceIDNode = plotNode->GetNode("sourceID");
                                    varNameNode = plotNode->GetNode("variableName");

                                    if(sourceIDNode != 0 && 
                                       sourceIDNode->GetNodeType() == STRING_NODE &&
                                       pluginIDNode != 0 && 
                                       pluginIDNode->GetNodeType() == STRING_NODE &&
                                       varNameNode != 0 && 
                                       varNameNode->GetNodeType() == STRING_NODE)
                                    {
                                        std::string source(sourceIDNode->AsString());
                                        std::string varName(varNameNode->AsString());
                                        std::string plotName(pluginIDNode->AsString());

                                        std::string::size_type pos = plotName.rfind("_");
                                        if(pos != std::string::npos)
                                            plotName = plotName.substr(0, pos);

                                        SNPRINTF(tmp, 1000, "Window %d, %s plot of %s",
                                            i+1, plotName.c_str(), varName.c_str());

                                        if(uses.find(source) == uses.end())
                                            uses[source] = stringVector();
                                        uses[source].push_back(std::string(tmp));
                                    }
                                    else
                                    {
                                        debug1 << mName << "pluginID, sourceID, or "
                                        "variableName nodes not located or they "
                                        "were the wrong types." << endl;
                                    }
                                }
                            } while(plotNode != 0);
                        }
                    }
                }
            }
        }

    }

    return ret;
}